Exemple #1
0
        // -----------------------------------------------------------------------------------
        public Dictionary <Case, double[, ]> AHP(List <Case> Cases)
        {
            double[,] Non_Results;
            Dictionary <Case, double[, ]> Results = new Dictionary <Case, double[, ]>();

            for (int u = 0; u < exp_random_cases.Count; u++)
            {
                Case _problem = exp_random_cases[u];
                // Criteria Comparsions------------------------
                MyAHPModel model = new MyAHPModel();

                double[,] cri_arr = model.Create_Criteria_Comparison_Array(count_citeria);
                MyAHPModel model1 = new MyAHPModel(count_citeria, Cases.Count);
                model1.AddCriteria(cri_arr);
                model1.CalculatedCriteria();
                // Choices Comparsions------------------------
                bool     consistency = false;
                double[] choices     = new double[Cases.Count];
                double[] tempresult  = new double[Cases.Count];
                for (int uu = 0; uu < count_citeria; uu++)
                {
                    double[,] comp_choice = model1.CreateOne_CeiteriaChoiceComp(uu, Cases);
                    while (!consistency)
                    {
                        tempresult = model1.Calculated_One__Choic(out consistency, model1.CriteriaWeights[uu], comp_choice);
                    }
                    for (int h = 0; h < tempresult.GetLength(0); h++)
                    {
                        choices[h] += tempresult[h];
                    }
                }
                int ii = 0;
                Non_Results = new double[Cases.Count, 2];
                foreach (Case c in Cases)
                {
                    Non_Results[ii, 0] = Convert.ToDouble(c.GetFeature("id").GetFeatureValue());
                    Non_Results[ii, 1] = choices[ii] * 100;
                    ii++;
                }
                // sort Clustered
                for (int i = 0; i < Non_Results.GetLength(0) - 1; i++)
                {
                    for (int j = 0; j < Non_Results.GetLength(0) - i - 1; j++)
                    {
                        if (Non_Results[j, 1] < Non_Results[j + 1, 1])
                        {
                            double temp = Non_Results[j, 1];
                            Non_Results[j, 1]     = Non_Results[j + 1, 1];
                            Non_Results[j + 1, 1] = temp;
                            temp = Non_Results[j, 0];
                            Non_Results[j, 0]     = Non_Results[j + 1, 0];
                            Non_Results[j + 1, 0] = temp;
                        }
                    }
                }
                Results.Add(exp_random_cases[u], Non_Results);
            }
            return(Results);
        }
Exemple #2
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
Exemple #3
0
        //=======================================================================================================================
        public void FindSolutions_AHP()
        {
            bool consistency;

            double[] choices;
            double[] tempresult;
            AllNonClusterdResults = new Dictionary <Case, Dictionary <double, double[, ]> >();
            AllClusterdResults    = new Dictionary <Case, Dictionary <double, double[, ]> >();
            criteria_weights      = new Dictionary <Case, double[]>();
            Dictionary <string, double>     cri_dic;
            Dictionary <double, double[, ]> tempNon;
            Dictionary <double, double[, ]> tempWith;
            List <Case> ClusterdArrCases;
            List <Case> NonClusterdArrCases;

            double[,] Non_Results;
            double[,] With_Results;
            ArrayList current_cases_partial = new ArrayList();
            //List<Case> centroids = new List<Case>();
            Kmeans kmeans = new Kmeans();
            Dictionary <int, List <Case> > cases_by_centroids = new Dictionary <int, List <Case> >();


            // get centroids for case
            for (int i = 0; i < centroids.Count; i++)
            {
                int k = Convert.ToInt32(centroids[i].GetFeature("id").GetFeatureValue());
                cases_by_centroids.Add(k, Db.get_cases_condition_cluster(tablename, casename, "cluster", k.ToString()));
            }


            //---------------------------------------------------------------------------------
            for (int u = 0; u < exp_random_cases.Count; u++)
            {
                cri_dic = new Dictionary <string, double>();
                double sim      = Math.Round(0.10, 2);
                Case   _problem = exp_random_cases[u];
                // Criteria Comparsions------------------------
                MyAHPModel model = new MyAHPModel(count_citeria);
                tempNon           = new  Dictionary <double, double[, ]> ();
                tempWith          = new Dictionary <double, double[, ]>();
                double[,] cri_arr = model.Create_Criteria_Comparison_Array(count_citeria);

                //-------Criteria Weights----------------------------------------------------------------
                model.AddCriteria(cri_arr);
                double[]      cri_wgh        = new double[count_citeria];
                List <string> criteria_names = Db.get_criteria(casename);

                bool res = false;
                while (!res)
                {
                    if (model.CalculatedCriteria())
                    {
                        res = true;
                    }
                }
                cri_wgh = model.CriteriaWeights;


                criteria_weights.Add(_problem, model.CriteriaWeights);


                //-------------------------------AHP--------------------------------------------------
                while (sim < 1)
                {
                    NonClusterdArrCases = FindAlternative_NonClustering(_problem, sim.ToString());
                    ClusterdArrCases    = FindAlternative_WithClustering(_problem, sim.ToString());

                    if (NonClusterdArrCases.Count != 0)
                    {
                        // non clustering
                        MyAHPModel model1 = new MyAHPModel(count_citeria, NonClusterdArrCases.Count);
                        model1.AddCriteria(cri_arr);
                        model1.CalculatedCriteria();
                        // Choices Comparsions------------------------
                        consistency = false;
                        choices     = new double[NonClusterdArrCases.Count];
                        tempresult  = new double[NonClusterdArrCases.Count];
                        for (int uu = 0; uu < count_citeria; uu++)
                        {
                            double[,] comp_choice = model1.CreateOne_CeiteriaChoiceComp(uu, NonClusterdArrCases);
                            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;
                        Non_Results = new double[NonClusterdArrCases.Count, 2];
                        foreach (Case cc in NonClusterdArrCases)
                        {
                            Non_Results[ii, 0] = Convert.ToDouble(cc.GetFeature("id").GetFeatureValue());
                            Non_Results[ii, 1] = choices[ii] * 100;
                            ii++;
                        }
                        // sort Clustered
                        for (int i = 0; i < Non_Results.GetLength(0) - 1; i++)
                        {
                            for (int j = 0; j < Non_Results.GetLength(0) - i - 1; j++)
                            {
                                if (Non_Results[j, 1] < Non_Results[j + 1, 1])
                                {
                                    double temp = Non_Results[j, 1];
                                    Non_Results[j, 1]     = Non_Results[j + 1, 1];
                                    Non_Results[j + 1, 1] = temp;
                                    temp = Non_Results[j, 0];
                                    Non_Results[j, 0]     = Non_Results[j + 1, 0];
                                    Non_Results[j + 1, 0] = temp;
                                }
                            }
                        }
                        tempNon.Add(sim, Non_Results);
                    }
                    if (ClusterdArrCases.Count != 0)
                    {
                        // Clustering
                        MyAHPModel model2 = new MyAHPModel(count_citeria, ClusterdArrCases.Count);
                        model2.AddCriteria(cri_arr);
                        model2.CalculatedCriteria();
                        // Choices Comparsions------------------------
                        consistency = false;
                        choices     = new double[ClusterdArrCases.Count];
                        tempresult  = new double[ClusterdArrCases.Count];
                        for (int uu = 0; uu < count_citeria; uu++)
                        {
                            double[,] comp_choice = model2.CreateOne_CeiteriaChoiceComp(uu, ClusterdArrCases);

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

                        // sort Clustered
                        for (int i = 0; i < With_Results.GetLength(0) - 1; i++)
                        {
                            for (int j = 0; j < With_Results.GetLength(0) - i - 1; j++)
                            {
                                if (With_Results[j, 1] < With_Results[j + 1, 1])
                                {
                                    double temp = With_Results[j, 1];
                                    With_Results[j, 1]     = With_Results[j + 1, 1];
                                    With_Results[j + 1, 1] = temp;
                                    temp = With_Results[j, 0];
                                    With_Results[j, 0]     = With_Results[j + 1, 0];
                                    With_Results[j + 1, 0] = temp;
                                }
                            }
                        }
                        tempWith.Add(sim, With_Results);
                    } // end if

                    sim += Math.Round(0.05, 2);
                    sim  = Math.Round(sim, 2);
                } // end sim
                AllNonClusterdResults.Add(exp_random_cases[u], tempNon);
                AllClusterdResults.Add(exp_random_cases[u], tempWith);
            } // end for
        }