Exemple #1
0
        //---------------------------------------------------------------------------------------
        public void FindSolutions_FuzzyAHP()
        {
            bool consistency;

            double[] choices;
            double[] tempresult;
            AllAhpCriteria     = new Dictionary <Case, double[]>();
            AllFAhpCriteria    = new Dictionary <Case, double[]>();
            AllAhpResults      = new Dictionary <Case, double[, ]>();
            AllFuzzyAhpResults = new Dictionary <Case, double[, ]>();
            List <double[, ]> tempahp;
            List <double[, ]> tempfahp;
            List <Case>       AhpArrCases;

            double[,] Ahp_Results;
            double[,] Fahp_Results;

            //---------------------------------------------------------------------------------
            for (int u = 0; u < exp_random_cases.Count; u++)
            {
                Case _problem = exp_random_cases[u];
                // Criteria Comparsions------------------------
                MyAHPModel model = new MyAHPModel(count_citeria);
                tempahp           = new List <double[, ]>();
                tempfahp          = new List <double[, ]>();
                double[,] cri_arr = model.Create_Criteria_Comparison_Array(count_citeria);

                //-------Criteria Weights----------------------------------------------------------------
                model.AddCriteria(cri_arr);
                double[] cri_wgh = new double[count_citeria];
                bool     res     = false;
                while (!res)
                {
                    if (model.CalculatedCriteria())
                    {
                        res = true;
                    }
                }
                cri_wgh = model.CriteriaWeights;
                //-------------------------------AHP--------------------------------------------------
                AhpArrCases = FindAlternative_WithClustering(_problem);
                if (AhpArrCases.Count != 0)
                {
                    // non clustering
                    MyAHPModel model1 = new MyAHPModel(count_citeria, AhpArrCases.Count);
                    model1.AddCriteria(cri_arr);
                    model1.CalculatedCriteria();
                    AllAhpCriteria.Add(exp_random_cases[u], model1.CriteriaWeights);
                    // Choices Comparsions------------------------
                    consistency = false;
                    choices     = new double[AhpArrCases.Count];
                    tempresult  = new double[AhpArrCases.Count];
                    for (int uu = 0; uu < count_citeria; uu++)
                    {
                        double[,] comp_choice = model1.CreateOne_CeiteriaChoiceComp(uu, AhpArrCases);
                        while (!consistency)
                        {
                            tempresult = model1.Calculated_One__Choic(out consistency, model1.CriteriaWeights[uu], comp_choice);
                        }
                        consistency = false;
                        for (int h = 0; h < tempresult.GetLength(0); h++)
                        {
                            choices[h] += tempresult[h];
                        }
                    }
                    int ii = 0;
                    Ahp_Results = new double[AhpArrCases.Count, 2];
                    foreach (Case cc in AhpArrCases)
                    {
                        Ahp_Results[ii, 0] = Convert.ToDouble(cc.GetFeature("id").GetFeatureValue());
                        Ahp_Results[ii, 1] = choices[ii] * 100;
                        ii++;
                    }
                    // sort Clustered
                    for (int i = 0; i < Ahp_Results.GetLength(0) - 1; i++)
                    {
                        for (int j = 0; j < Ahp_Results.GetLength(0) - i - 1; j++)
                        {
                            if (Ahp_Results[j, 1] < Ahp_Results[j + 1, 1])
                            {
                                double temp = Ahp_Results[j, 1];
                                Ahp_Results[j, 1]     = Ahp_Results[j + 1, 1];
                                Ahp_Results[j + 1, 1] = temp;
                                temp = Ahp_Results[j, 0];
                                Ahp_Results[j, 0]     = Ahp_Results[j + 1, 0];
                                Ahp_Results[j + 1, 0] = temp;
                            }
                            else if (Ahp_Results[j, 1] == Ahp_Results[j + 1, 1])
                            {
                                EuclideanSimilarity s = new EuclideanSimilarity();
                                int    num1           = Convert.ToInt32(Ahp_Results[j, 0]);
                                int    num2           = Convert.ToInt32(Ahp_Results[j + 1, 0]);
                                double sim1           = s.Similarity(AhpArrCases[num1], _problem);
                                double sim2           = s.Similarity(AhpArrCases[num2], _problem);
                                if (sim2 > sim1)
                                {
                                    double temp = Ahp_Results[j, 1];
                                    Ahp_Results[j, 1]     = Ahp_Results[j + 1, 1];
                                    Ahp_Results[j + 1, 1] = temp;
                                    temp = Ahp_Results[j, 0];
                                    Ahp_Results[j, 0]     = Ahp_Results[j + 1, 0];
                                    Ahp_Results[j + 1, 0] = temp;
                                }
                            }
                        }
                    }


                    // Fuzzy
                    MyFuzzyAHP model2 = new MyFuzzyAHP(count_citeria, AhpArrCases.Count);
                    model2.AddCriteria(cri_arr);
                    model2.CalculatedCriteria();
                    AllFAhpCriteria.Add(exp_random_cases[u], model2.CriteriaWeights);
                    // Choices Comparsions------------------------
                    consistency = false;
                    choices     = new double[AhpArrCases.Count];
                    tempresult  = new double[AhpArrCases.Count];
                    for (int uu = 0; uu < count_citeria; uu++)
                    {
                        double[,] comp_choice = model2.CreateOne_CeiteriaChoiceComp(uu, AhpArrCases);

                        while (!consistency)
                        {
                            tempresult = model2.Calculated_One__Choice(out consistency, model2.CriteriaWeights[uu], comp_choice);
                        }
                        consistency = false;
                        for (int h = 0; h < tempresult.GetLength(0); h++)
                        {
                            choices[h] += tempresult[h];
                        }
                    }
                    ii           = 0;
                    Fahp_Results = new double[AhpArrCases.Count, 2];
                    foreach (Case cc in AhpArrCases)
                    {
                        Fahp_Results[ii, 0] = Convert.ToDouble(cc.GetFeature("id").GetFeatureValue());
                        Fahp_Results[ii, 1] = choices[ii] * 100;
                        ii++;
                    }

                    // sort Clustered
                    for (int i = 0; i < Fahp_Results.GetLength(0) - 1; i++)
                    {
                        for (int j = 0; j < Fahp_Results.GetLength(0) - i - 1; j++)
                        {
                            if (Fahp_Results[j, 1] < Fahp_Results[j + 1, 1])
                            {
                                double temp = Fahp_Results[j, 1];
                                Fahp_Results[j, 1]     = Fahp_Results[j + 1, 1];
                                Fahp_Results[j + 1, 1] = temp;
                                temp = Fahp_Results[j, 0];
                                Fahp_Results[j, 0]     = Fahp_Results[j + 1, 0];
                                Fahp_Results[j + 1, 0] = temp;
                            }
                        }
                    }
                    AllAhpResults.Add(exp_random_cases[u], Ahp_Results);
                    AllFuzzyAhpResults.Add(exp_random_cases[u], Fahp_Results);
                }
            } //end if
        }     // end for
        private void button21_Click(object sender, EventArgs e)
        {
            // display


            int dG_WithR = 0;

            dG_With.Columns.Clear();



            //dG_Non.Columns.Add("Porblem No ", "Porblem No  ");
            dG_With.Columns.Add("SolNum", "Sol Num  ");
            dG_With.Columns.Add("Weight  ", "Weight  ");
            dG_With.Columns.Add("Sim  ", "Sim  ");



            List <Case> solutions = statistics.FindAlternative_WithClustering(statistics.exp_random_cases[problem_num]);

            // call method
            listBox1.Items.Add("Finding Alternatices by specifying best cluster");

            double[] ranks;
            Dictionary <int, double[, ]> choices;

            double[,] criteriaarr;

            MyFuzzyAHP myfahp = new MyFuzzyAHP(statistics.count_citeria, solutions.Count);

            criteriaarr = GenerateComparison.CriteriaComparisonMatrix;

            myfahp.AddCriteria(criteriaarr);
            myfahp.CalculatedCriteria();
            choices = GenerateComparison.Create_All_Criteria_Choice_Comparison_Array(solutions);
            myfahp.AddCriterionRatedChoices(choices);
            ranks = myfahp.CalculatedChoices();
            for (int i = 0; i < ranks.Length; i++)
            {
                dG_With.Rows.Add();
                dG_With.Rows[dG_WithR].Cells[0].Value = solutions[i].GetFeature("id").GetFeatureValue().ToString();
                dG_With.Rows[dG_WithR].Cells[1].Value = Math.Round(ranks[i] * 100, 2);
                EuclideanSimilarity s = new EuclideanSimilarity();
                dG_With.Rows[dG_WithR].Cells[2].Value = Math.Round(s.Similarity(solutions[i], statistics.exp_random_cases[problem_num]) * 100, 2);
                dG_WithR++;
            }


            dG_With.Sort(dG_With.Columns[1], ListSortDirection.Descending);

            if (dG_Prob.Columns.Count == 0)
            {
                dG_Prob.Columns.Add("Criteria", " Criteria ");
                dG_Prob.Columns.Add("AHP", "AHP");
                dG_Prob.Columns.Add("FuzzyAHP", "Fuzzy AHP");
                for (int i = 1; i < solutions[0].GetFeatures().Count - 1; i++)
                {
                    dG_Prob.Rows.Add();
                    Feature f = (Feature)solutions[0].GetFeatures()[i];
                    dG_Prob.Rows[i - 1].Cells[0].Value = f.GetFeatureName().ToString();
                    dG_Prob.Rows[i - 1].Cells[2].Value = Math.Round(myfahp.CriteriaWeights[i - 1] * 100, 2);
                }
            }
            else
            {
                for (int i = 1; i < solutions[0].GetFeatures().Count - 1; i++)
                {
                    Feature f = (Feature)solutions[0].GetFeatures()[i];
                    dG_Prob.Rows[i - 1].Cells[2].Value = Math.Round(myfahp.CriteriaWeights[i - 1] * 100, 2);
                }
            }

            dG_Prob.AutoResizeColumns();
            dG_Prob.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            dG_With.AutoResizeColumns();
            dG_With.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            // display
        }