Example #1
0
        public void TestVacationSpotSelection()
        {
            double[][] criteria = new double[][]
            {
                new double[] { 1, 5, 0.33333333, 1 },
                new double[] { 0, 1, 0.2, 0.5 },
                new double[] { 0, 0, 1, 3 },
                new double[] { 0, 0, 0, 1 }
            };
            //double[][] xxx = new double[2][];

            double[][] activitiesChoices = new double[][]
            {
                new double[] { 1, 4, 3 },
                new double[] { 0, 1, 2 },
                new double[] { 0, 0, 1 }
            };

            double[][] nightlifeChoices = new double[][]
            {
                new double[] { 1, 0.5, 0.3333333 },
                new double[] { 0, 1, 0.5 },
                new double[] { 0, 0, 1 }
            };

            double[][] siteseeingChoices = new double[][]
            {
                new double[] { 1, 0.142857, 0.2 },
                new double[] { 0, 1, 2 },
                new double[] { 0, 0, 1 }
            };

            double[][] costChoices = new double[][]
            {
                new double[] { 1, 3, 5 },
                new double[] { 0, 1, 2 },
                new double[] { 0, 0, 1 }
            };

            //4 criteria, 3 choices
            AHPModel model = new AHPModel(4, 3);

            model.AddCriteria(criteria);
            model.AddCriterionRatedChoices(0, activitiesChoices);
            model.AddCriterionRatedChoices(1, nightlifeChoices);
            model.AddCriterionRatedChoices(2, siteseeingChoices);
            model.AddCriterionRatedChoices(3, costChoices);

            model.CalculateModel();

            //GeneralMatrix calcCriteria = model.CalculatedCriteria;
            //GeneralMatrix results = model.ModelResult;
            GeneralMatrix choices = model.CalculatedChoices;

            //choices: SF 42%, Orlando31%, NY 27%
            Assert.AreEqual(31, System.Math.Round(choices.GetElement(0, 0) * 100, 0));
            Assert.AreEqual(42, System.Math.Round(choices.GetElement(1, 0) * 100, 0));
            Assert.AreEqual(27, System.Math.Round(choices.GetElement(2, 0) * 100, 0));
        }
Example #2
0
        private void tESTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            double[][] criteria = new double[][]
            {
                new double[] { 1, 2, 3 },
                new double[] { 0, 1, 1.5 },
                new double[] { 0, 0, 1 }
            };
            //double[][] xxx = new double[2][];

            double[][] kecantikanChoices = new double[][]
            {
                new double[] { 1, 4, 3 },
                new double[] { 0, 1, 0.5 },
                new double[] { 0, 0, 1 }
            };

            double[][] pendidikanChoices = new double[][]
            {
                new double[] { 1, 0.33, 0.25 },
                new double[] { 0, 1, 0.5 },
                new double[] { 0, 0, 1 }
            };

            double[][] kekayaanChoices = new double[][]
            {
                new double[] { 1, 0.01, 0.10 },
                new double[] { 0, 1, 10 },
                new double[] { 0, 0, 1 }
            };

            //4 criteria, 3 choices
            AHPModel model = new AHPModel(3, 3);

            model.AddCriteria(criteria);
            model.AddCriterionRatedChoices(0, kecantikanChoices);
            model.AddCriterionRatedChoices(1, pendidikanChoices);
            model.AddCriterionRatedChoices(2, kekayaanChoices);


            model.CalculateModel();



            GeneralMatrix calcCriteria = model.CalculatedCriteria;
            GeneralMatrix results      = model.ModelResult;
            GeneralMatrix choices      = model.CalculatedChoices;

            //results.ge

            //choices: SF 42%, Orlando31%, NY 27%
            //Assert.AreEqual(31, System.Math.Round(choices.GetElement(0, 0) * 100, 0));
            //Assert.AreEqual(42, System.Math.Round(choices.GetElement(1, 0) * 100, 0));
            //Assert.AreEqual(27, System.Math.Round(choices.GetElement(2, 0) * 100, 0));
        }
Example #3
0
        public static Colaborador[] calcularAhpTeam(double psaPls, double tsPls, double citPls, double rcPls, double dkPls, double bdkPls, double tsPsa, double citPsa, double rcPsa, double dkPsa, double bdkPsa, double citTs, double rcTs, double dkTs, double bdkTs, double rcCit, double dkCit, double bdkCit, double dkRc, double bdkRc, double bdkDk)
        {
            //Pesquisa na Base de dados o utilizador
            ListaColab = db.pontuacaoColab();

            if ((ListaColab.Count) > 3)
            {
                var size = ListaColab.Count;
                //double[] communicationSkillArray = { 12, 15, 12, 20, 1 };
                double[] programmingArray          = new double[size];
                double[] problemSolvingArray       = new double[size];
                double[] testingSkillsArray        = new double[size];
                double[] continuosIntegrationArray = new double[size];
                double[] refactoringArray          = new double[size];
                double[] databaseKnowledgeArray    = new double[size];
                double[] bigDataArray = new double[size];



                for (var i = 0; i < ListaColab.Count; i++)
                {
                    programmingArray[i]          = ListaColab[i].prog_lang_skill;
                    problemSolvingArray[i]       = ListaColab[i].problem_solving;
                    testingSkillsArray[i]        = ListaColab[i].integration_tool;
                    continuosIntegrationArray[i] = ListaColab[i].integration_tool;
                    refactoringArray[i]          = ListaColab[i].refact_concept;
                    databaseKnowledgeArray[i]    = ListaColab[i].db_knowledge;
                    bigDataArray[i] = ListaColab[i].big_data_knowledge;
                }


                //var size = ListaColab.Count;

                // cada elemento da matrix corresponde a cada criterio de comparação

                /* array == criterios
                 * cada elemento do array == nota de cada pessoa */
                double[][] criteria = new double[][]
                {
                    new double[] { 1, psaPls, tsPls, citPls, rcPls, dkPls, bdkPls },
                    new double[] { 0, 1, tsPsa, citPsa, rcPsa, dkPsa, bdkPsa },
                    new double[] { 0, 0, 1, citTs, rcTs, dkTs, bdkTs },
                    new double[] { 0, 0, 0, 1, rcCit, dkCit, bdkCit },
                    new double[] { 0, 0, 0, 0, 1, dkRc, bdkRc },
                    new double[] { 0, 0, 0, 0, 0, 1, bdkDk },
                    new double[] { 0, 0, 0, 0, 0, 0, 1 }
                };

                // array
                double[][] programmingMatrix = new double[size][];

                for (int i = 0; i < size; i++)
                {
                    programmingMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        programmingMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            programmingMatrix[k][w] = 1;
                        }
                        else
                        {
                            programmingMatrix[k][w] = programmingArray[k] / programmingArray[w];
                        }
                    }
                }

                double[][] problemSolvingMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    problemSolvingMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        problemSolvingMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            problemSolvingMatrix[k][w] = 1;
                        }
                        else
                        {
                            problemSolvingMatrix[k][w] = problemSolvingArray[k] / problemSolvingArray[w];
                        }
                    }
                }
                double[][] testingSkillsMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    testingSkillsMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        testingSkillsMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            testingSkillsMatrix[k][w] = 1;
                        }
                        else
                        {
                            testingSkillsMatrix[k][w] = testingSkillsArray[k] / testingSkillsArray[w];
                        }
                    }
                }

                double[][] continuosIntegrationMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    continuosIntegrationMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        continuosIntegrationMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            continuosIntegrationMatrix[k][w] = 1;
                        }
                        else
                        {
                            continuosIntegrationMatrix[k][w] = continuosIntegrationArray[k] / continuosIntegrationArray[w];
                        }
                    }
                }

                double[][] refactoringMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    refactoringMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        refactoringMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            refactoringMatrix[k][w] = 1;
                        }
                        else
                        {
                            refactoringMatrix[k][w] = refactoringArray[k] / refactoringArray[w];
                        }
                    }
                }

                double[][] databaseKnowledgeMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    databaseKnowledgeMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        databaseKnowledgeMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            databaseKnowledgeMatrix[k][w] = 1;
                        }
                        else
                        {
                            databaseKnowledgeMatrix[k][w] = databaseKnowledgeArray[k] / databaseKnowledgeArray[w];
                        }
                    }
                }

                double[][] bigDataMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    bigDataMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        bigDataMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            bigDataMatrix[k][w] = 1;
                        }
                        else
                        {
                            bigDataMatrix[k][w] = bigDataArray[k] / bigDataArray[w];
                        }
                    }
                }


                AHPModel model = new AHPModel(7, size);

                // options  == matrix alternativa

                model.AddCriteria(criteria);
                model.AddCriterionRatedChoices(0, programmingMatrix);
                model.AddCriterionRatedChoices(1, problemSolvingMatrix);
                model.AddCriterionRatedChoices(2, testingSkillsMatrix);
                model.AddCriterionRatedChoices(3, continuosIntegrationMatrix);
                model.AddCriterionRatedChoices(4, refactoringMatrix);
                model.AddCriterionRatedChoices(5, databaseKnowledgeMatrix);
                model.AddCriterionRatedChoices(6, bigDataMatrix);
                model.CalculateModel();

                GeneralMatrix CalcCriteria = model.CalculatedCriteria;
                GeneralMatrix results      = model.ModelResult;
                GeneralMatrix calcOptions  = model.CalculatedChoices;


                //Coloca o resutado ahp no objeto colaborador
                for (var i = 1; i < ListaColab.Count; i++)
                {
                    ListaColab[i].resultadoAhp = calcOptions.GetElement(i, 0);
                }

                Colaborador temp;

                Colaborador[] listaColabToArray = ListaColab.ToArray();
                //ordenar o array perante o resultado do ahp
                for (int write = 0; write < listaColabToArray.Length; write++)
                {
                    for (int sort = 0; sort < listaColabToArray.Length - 1; sort++)
                    {
                        if (listaColabToArray[sort].resultadoAhp < listaColabToArray[sort + 1].resultadoAhp)
                        {
                            temp = listaColabToArray[sort + 1];
                            listaColabToArray[sort + 1] = listaColabToArray[sort];
                            listaColabToArray[sort]     = temp;
                        }
                    }
                }

                return(listaColabToArray);
            }
            return(null);
        }
Example #4
0
        public static Colaborador[] calcularAhpTeamMaster(double pmtCs, double citCs, double desCs, double maCs, double csCs, double citPmt, double desPmt, double maPmt, double csPmt, double desCit, double maCit, double csCit, double maDes, double csDes, double csMa)
        {
            //Pesquisa na Base de dados o utilizador
            ListaColab = db.pontuacaoColab();

            if ((ListaColab.Count) > 3)
            {
                var size = ListaColab.Count;
                //double[] communicationSkillArray = { 12, 15, 12, 20, 1 };
                double[] communicationSkillArray    = new double[size];
                double[] projectManagmentArray      = new double[size];
                double[] continuosIntegrationArray  = new double[size];
                double[] developmentEnviromentArray = new double[size];
                double[] motivationArray            = new double[size];
                double[] CoordenationArray          = new double[size];


                for (var i = 0; i < ListaColab.Count; i++)
                {
                    communicationSkillArray[i]    = ListaColab[i].communication;
                    projectManagmentArray[i]      = ListaColab[i].proj_management_tool;
                    continuosIntegrationArray[i]  = ListaColab[i].integration_tool;
                    developmentEnviromentArray[i] = ListaColab[i].dev_environment_setup;
                    motivationArray[i]            = ListaColab[i].motivation_ability;
                    CoordenationArray[i]          = ListaColab[i].coordination_skill;
                }


                //var size = ListaColab.Count;

                // cada elemento da matrix corresponde a cada criterio de comparação

                /* array == criterios
                 * cada elemento do array == nota de cada pessoa */
                double[][] criteria = new double[][]
                {
                    new double[] { 1, pmtCs, citCs, desCs, maCs, csCs },
                    new double[] { 0, 1, citPmt, desPmt, maPmt, csPmt },
                    new double[] { 0, 0, 1, desCit, maCit, csCit },
                    new double[] { 0, 0, 0, 1, maDes, csDes },
                    new double[] { 0, 0, 0, 0, 1, csMa },
                    new double[] { 0, 0, 0, 0, 0, 1 }
                };

                // array
                double[][] communicationSkillMatrix = new double[size][];

                for (int i = 0; i < size; i++)
                {
                    communicationSkillMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        communicationSkillMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            communicationSkillMatrix[k][w] = 1;
                        }
                        else
                        {
                            communicationSkillMatrix[k][w] = communicationSkillArray[k] / communicationSkillArray[w];
                        }
                    }
                }

                double[][] projectManagmentMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    projectManagmentMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        projectManagmentMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            projectManagmentMatrix[k][w] = 1;
                        }
                        else
                        {
                            projectManagmentMatrix[k][w] = projectManagmentArray[k] / projectManagmentArray[w];
                        }
                    }
                }

                double[][] continuosIntegrationMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    continuosIntegrationMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        continuosIntegrationMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            continuosIntegrationMatrix[k][w] = 1;
                        }
                        else
                        {
                            continuosIntegrationMatrix[k][w] = continuosIntegrationArray[k] / continuosIntegrationArray[w];
                        }
                    }
                }

                double[][] developmentEnviromentMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    developmentEnviromentMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        developmentEnviromentMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            developmentEnviromentMatrix[k][w] = 1;
                        }
                        else
                        {
                            developmentEnviromentMatrix[k][w] = developmentEnviromentArray[k] / developmentEnviromentArray[w];
                        }
                    }
                }

                double[][] motivationMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    motivationMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        motivationMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            motivationMatrix[k][w] = 1;
                        }
                        else
                        {
                            motivationMatrix[k][w] = motivationArray[k] / motivationArray[w];
                        }
                    }
                }

                double[][] CoordenationMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    CoordenationMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        CoordenationMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            CoordenationMatrix[k][w] = 1;
                        }
                        else
                        {
                            CoordenationMatrix[k][w] = CoordenationArray[k] / CoordenationArray[w];
                        }
                    }
                }


                AHPModel model = new AHPModel(6, size);

                // options  == matrix alternativa

                model.AddCriteria(criteria);
                model.AddCriterionRatedChoices(0, communicationSkillMatrix);
                model.AddCriterionRatedChoices(1, projectManagmentMatrix);
                model.AddCriterionRatedChoices(2, continuosIntegrationMatrix);
                model.AddCriterionRatedChoices(3, developmentEnviromentMatrix);
                model.AddCriterionRatedChoices(4, motivationMatrix);
                model.AddCriterionRatedChoices(5, CoordenationMatrix);
                model.CalculateModel();

                GeneralMatrix CalcCriteria = model.CalculatedCriteria;
                GeneralMatrix results      = model.ModelResult;
                GeneralMatrix calcOptions  = model.CalculatedChoices;

                //var posMaior = 0;

                //for (var i = 1; i < ListaColab.Count; i++)
                //{


                //    if (calcOptions.GetElement(i, 0) > calcOptions.GetElement(i - 1, 0))
                //    {
                //        posMaior = i;
                //    }
                //}
                //DialogResult dialogCamposIns = MessageBox.Show(ListaColab[posMaior].colab_nome.ToString(),
                //                    "Erro - seleção", MessageBoxButtons.OK, MessageBoxIcon.Error);

                //return ListaColab[posMaior];


                //Coloca o resutado ahp no objeto colaborador
                for (var i = 1; i < ListaColab.Count; i++)
                {
                    ListaColab[i].resultadoAhp = calcOptions.GetElement(i, 0);
                }

                Colaborador temp;

                Colaborador[] listaColabToArray = ListaColab.ToArray();
                //ordenar o array perante o resultado do ahp
                for (int write = 0; write < listaColabToArray.Length; write++)
                {
                    for (int sort = 0; sort < listaColabToArray.Length - 1; sort++)
                    {
                        if (listaColabToArray[sort].resultadoAhp < listaColabToArray[sort + 1].resultadoAhp)
                        {
                            temp = listaColabToArray[sort + 1];
                            listaColabToArray[sort + 1] = listaColabToArray[sort];
                            listaColabToArray[sort]     = temp;
                        }
                    }
                }

                return(listaColabToArray);


                //    Console.WriteLine("Option 1");

                //Console.WriteLine(calcOptions.GetElement(0, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(1, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(2, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(3, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(4, 0) * 100.00);

                //Console.ReadLine();
            }
            return(null);
        }
Example #5
0
        public static Colaborador[] calcularAhpProductOwner(double kbnCm, double kifCm, double eaCm, double fkCm, double kifKbm, double eaKbm, double fkKbm, double eaKif, double fkKif, double fkea)
        {
            //Pesquisa na Base de dados o utilizador
            ListaColab = db.pontuacaoColab();

            if ((ListaColab.Count) > 4)
            {
                var size = ListaColab.Count;
                //double[] communicationSkillArray = { 12, 15, 12, 20, 1 };
                double[] communicationSkillArray = new double[size];
                double[] knowledgeBusinessArray  = new double[size];
                double[] knowledgeIndstryArray   = new double[size];
                double[] entrepeneurArray        = new double[size];
                double[] financialKnowlegdeArray = new double[size];


                for (var i = 0; i < ListaColab.Count; i++)
                {
                    communicationSkillArray[i] = ListaColab[i].communication;
                    knowledgeBusinessArray[i]  = ListaColab[i].know_business_model;
                    knowledgeIndstryArray[i]   = ListaColab[i].know_industry_field;
                    entrepeneurArray[i]        = ListaColab[i].enterpreneur_ability;
                    financialKnowlegdeArray[i] = ListaColab[i].financial_know;
                }


                //var size = ListaColab.Count;

                // cada elemento da matrix corresponde a cada criterio de comparação

                /* array == criterios
                 * cada elemento do array == nota de cada pessoa */
                double[][] criteria = new double[][]
                {
                    new double[] { 1, kbnCm, kifCm, eaCm, fkCm },
                    new double[] { 0, 1, kifKbm, eaKbm, fkKbm },
                    new double[] { 0, 0, 1, eaKif, fkKif },
                    new double[] { 0, 0, 0, 1, fkea },
                    new double[] { 0, 0, 0, 0, 1 }
                };

                // array
                double[][] communicationSkillMatrix = new double[size][];

                for (int i = 0; i < size; i++)
                {
                    communicationSkillMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        communicationSkillMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            communicationSkillMatrix[k][w] = 1;
                        }
                        else
                        {
                            communicationSkillMatrix[k][w] = communicationSkillArray[k] / communicationSkillArray[w];
                        }
                    }
                }

                double[][] knowledgeBusinessMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    knowledgeBusinessMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        knowledgeBusinessMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            knowledgeBusinessMatrix[k][w] = 1;
                        }
                        else
                        {
                            knowledgeBusinessMatrix[k][w] = knowledgeBusinessArray[k] / knowledgeBusinessArray[w];
                        }
                    }
                }

                double[][] knowledgeIndstryMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    knowledgeIndstryMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        knowledgeIndstryMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            knowledgeIndstryMatrix[k][w] = 1;
                        }
                        else
                        {
                            knowledgeIndstryMatrix[k][w] = knowledgeIndstryArray[k] / knowledgeIndstryArray[w];
                        }
                    }
                }

                double[][] entrepeneurMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    entrepeneurMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        entrepeneurMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            entrepeneurMatrix[k][w] = 1;
                        }
                        else
                        {
                            entrepeneurMatrix[k][w] = entrepeneurArray[k] / entrepeneurArray[w];
                        }
                    }
                }

                double[][] financialKnowlegdeMatrix = new double[size][];
                for (int i = 0; i < size; i++)
                {
                    financialKnowlegdeMatrix[i] = new double[size];
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        financialKnowlegdeMatrix[i][j] = 0;
                    }
                }
                for (int k = 0; k < size; k++)
                {
                    for (int w = k; w < size; w++)
                    {
                        if (w.Equals(k))
                        {
                            financialKnowlegdeMatrix[k][w] = 1;
                        }
                        else
                        {
                            financialKnowlegdeMatrix[k][w] = financialKnowlegdeArray[k] / financialKnowlegdeArray[w];
                        }
                    }
                }


                AHPModel model = new AHPModel(5, size);

                // options  == matrix alternativa

                model.AddCriteria(criteria);
                model.AddCriterionRatedChoices(0, communicationSkillMatrix);
                model.AddCriterionRatedChoices(1, knowledgeBusinessMatrix);
                model.AddCriterionRatedChoices(2, knowledgeIndstryMatrix);
                model.AddCriterionRatedChoices(3, entrepeneurMatrix);
                model.AddCriterionRatedChoices(4, financialKnowlegdeMatrix);
                model.CalculateModel();

                GeneralMatrix CalcCriteria = model.CalculatedCriteria;
                GeneralMatrix results      = model.ModelResult;
                GeneralMatrix calcOptions  = model.CalculatedChoices;

                //var posMaior = 0;

                //for (var i = 1; i < ListaColab.Count; i++)
                //{


                //    if (calcOptions.GetElement(i, 0)> calcOptions.GetElement(i-1, 0))
                //    {
                //         posMaior = i;
                //    }
                //}
                //DialogResult dialogCamposIns = MessageBox.Show(ListaColab[posMaior].colab_nome.ToString(),
                //                    "Erro - seleção", MessageBoxButtons.OK, MessageBoxIcon.Error);

                //return ListaColab[posMaior];

                //Coloca o resutado ahp no objeto colaborador
                for (var i = 1; i < ListaColab.Count; i++)
                {
                    ListaColab[i].resultadoAhp = calcOptions.GetElement(i, 0);
                }

                Colaborador temp;

                Colaborador[] listaColabToArray = ListaColab.ToArray();
                //ordenar o array perante o resultado do ahp
                for (int write = 0; write < listaColabToArray.Length; write++)
                {
                    for (int sort = 0; sort < listaColabToArray.Length - 1; sort++)
                    {
                        if (listaColabToArray[sort].resultadoAhp < listaColabToArray[sort + 1].resultadoAhp)
                        {
                            temp = listaColabToArray[sort + 1];
                            listaColabToArray[sort + 1] = listaColabToArray[sort];
                            listaColabToArray[sort]     = temp;
                        }
                    }
                }

                return(listaColabToArray);


                //Console.WriteLine(calcOptions.GetElement(0, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(1, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(2, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(3, 0) * 100.00);
                //Console.WriteLine(calcOptions.GetElement(4, 0) * 100.00);
            }
            return(null);
        }
Example #6
0
        private void FrmProcessLoad(object sender, EventArgs e)
        {
            //insertLog("\nENTER FUNC()=> private void FrmProcess_Load(...)");
            //_____START CALCULATING AHP
            log.Clear();
            log.Text += "[START] Kalkulasi Kriteria...";

            if (CalculatePcmCriteria())
            {
                InsertLog("[OK] Nilai Consistency Ratio dapat diterima\n");
            }
            else
            {
                InsertLog("[ERROR] Nilai Consistency Ratio tidak dapat diterima\n" +
                          "Proses tidak dapat dilanjutkan");
                // ReSharper disable RedundantJumpStatement
                return;
                // ReSharper restore RedundantJumpStatement
            }

            InsertLog("\n[START] Kalkulasi kandidat...");

            var dt = _dbConnect.GetRecord(string.Format("SELECT kode,nama " +
                                                        "FROM tbl_kriteria " +
                                                        "WHERE aktif='{0}' " +
                                                        "ORDER BY kode", "True"));

            int countCandidate = _dbConnect.intExecuteScalar("SELECT COUNT(*) " +
                                                             "FROM tbl_anggota");

            //inisialisasi AHP model
            AHPModel model = new AHPModel(dt.Rows.Count, countCandidate);

            //add kriteria
            model.AddCriteria(_criteria);


            //untuk masing-masing kriteria..
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int kodeKriteria = int.Parse(dt.Rows[i][0].ToString());

                var dtA = _dbConnect.GetRecord(string.Format("SELECT kode_kriteria_item " +
                                                             "FROM tbl_anggota_kriteria_items " +
                                                             "WHERE kode_kriteria={0} " +
                                                             "ORDER BY kode_anggota", kodeKriteria));

                double[][] arrayKandidatBobot = new double[dtA.Rows.Count][];
                //kalkulasikan nilai dari matrix kriteria anggota
                for (int k = 0; k < dtA.Rows.Count; k++)
                {
                    arrayKandidatBobot[k] = new double[dtA.Rows.Count];
                    int kodeA = int.Parse(dtA.Rows[k][0].ToString());

                    for (int l = 0; l < dtA.Rows.Count; l++)
                    {
                        if (k == l)
                        {
                            //nilai = 1
                            arrayKandidatBobot[k][l] = 1;
                        }
                        else if (k > l)
                        {
                            //nilai 0
                            arrayKandidatBobot[k][l] = 0;
                        }
                        else
                        {
                            int kodeB = int.Parse(dtA.Rows[l][0].ToString());
                            arrayKandidatBobot[k][l] = GetNilaiKriteriaItem(kodeA, kodeB);
                        }
                    }
                }


                if (dtA.Rows.Count <= 2)
                {
                    InsertLog("Kandidat <= dari 2, maka tidak perlu dilakukan pengecekan Consistency Index(CI)");
                }
                else
                {
                    //periksa apakah Pair Comparation matrix untuk kriteria ini punya CI <= CI_acceptableValue ?
                    if (CalculatePcm(arrayKandidatBobot))
                    {
                        InsertLog(string.Format("[OK] Nilai Consistency Ratio untuk {0} dapat diterima\n", dt.Rows[i][1]));
                    }
                    else
                    {
                        InsertLog("[ERROR] Nilai Consistency Ratio tidak dapat diterima\n" +
                                  "Proses tidak dapat dilanjutkan");
                        // ReSharper disable RedundantJumpStatement
                        return;
                        // ReSharper restore RedundantJumpStatement
                    }
                }

                model.AddCriterionRatedChoices(i, arrayKandidatBobot);
            }

            model.CalculateModel();
            GeneralMatrix calcCriteria = model.CalculatedCriteria;
            GeneralMatrix results      = model.ModelResult;
            GeneralMatrix choices      = model.CalculatedChoices;

            //choices: SF 42%, Orlando31%, NY 27%
            //Assert.AreEqual(31, System.Math.Round(choices.GetElement(0, 0) * 100, 0));
            //Assert.AreEqual(42, System.Math.Round(choices.GetElement(1, 0) * 100, 0));
            //Assert.AreEqual(27, System.Math.Round(choices.GetElement(2, 0) * 100, 0));

            //clear all rows on gridview
            dtGridView.Columns.Clear();
            var dgvColumnKriteria = new DataGridViewTextBoxColumn
            {
                HeaderText = "Kriteria",
                Name       = "kriteria",
                SortMode   = DataGridViewColumnSortMode.NotSortable
            };
            int colKriteria = dtGridView.Columns.Add(dgvColumnKriteria);

            dtGridView.Columns[colKriteria].Frozen = true;

            var dgvColumnWeight = new DataGridViewTextBoxColumn
            {
                HeaderText = "Berat",
                Name       = "Weight",
                SortMode   = DataGridViewColumnSortMode.NotSortable
            };

            dtGridView.Columns.Add(dgvColumnWeight);

            //            calcCriteria : weight cantik -> kaya
            //            result : choise yayu (cantik -> kaya)
            //                     grace (cantik -> kaya)
            //                     fitri (cantik -> kaya)
            //            choices :Composite Weight (Yayu ->Fitri)

            //insert candidate name


            var dtKandidat = _dbConnect.GetRecord("SELECT nama " +
                                                  "FROM tbl_anggota " +
                                                  "ORDER BY kode");

            for (int a = 0; a < dtKandidat.Rows.Count; a++)
            {
                var dgvColumn = new DataGridViewTextBoxColumn
                {
                    HeaderText = dtKandidat.Rows[a][0].ToString(),
                    Name       = string.Format("kandidat-{0}", a),
                    SortMode   = DataGridViewColumnSortMode.NotSortable
                };
                dtGridView.Columns.Add(dgvColumn);
            }

            var dtKriteria = _dbConnect.GetRecord("SELECT nama " +
                                                  "FROM tbl_kriteria " +
                                                  "ORDER BY kode");

            //string[] chartSeriesArray = new string[dtKriteria.Rows.Count];


            chart1.Series.Clear();
            chart1.ChartAreas[0].BackColor          = Color.LightBlue;
            chart1.ChartAreas[0].BackSecondaryColor = Color.White;
            chart1.ChartAreas[0].BackGradientStyle  = GradientStyle.TopBottom;
            chart1.ChartAreas[0].BorderColor        = Color.Black;
            chart1.ChartAreas[0].BorderDashStyle    = ChartDashStyle.Solid;
            chart1.ChartAreas[0].BorderWidth        = 1;
            chart1.ChartAreas[0].ShadowOffset       = 4;
            //chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
            //chart1.ChartAreas[0].Area3DStyle.Inclination = 90;
            //chart1.ChartAreas[0].Area3DStyle.Rotation = 45;
            chart1.ChartAreas[0].Area3DStyle.LightStyle = LightStyle.Simplistic;

            chart1.Legends[0].BackColor          = Color.LightBlue;
            chart1.Legends[0].BackSecondaryColor = Color.White;
            chart1.Legends[0].BackGradientStyle  = GradientStyle.DiagonalLeft;
            chart1.Legends[0].BorderColor        = Color.Black;
            chart1.Legends[0].BorderWidth        = 1;
            chart1.Legends[0].BorderDashStyle    = ChartDashStyle.Solid;

            chart1.Legends[0].ShadowOffset = 2;

            for (int i = 0; i < dtKriteria.Rows.Count; i++)
            {
                //add new ros
                dtGridView.Rows.Add(1);
                dtGridView[0, i].Value = dtKriteria.Rows[i][0].ToString();

                string seriesName = dtKriteria.Rows[i][0].ToString();
                this.chart1.Series.Add(seriesName);
                //gunakan ini untuk swith axis -> chart1.Series[seriesName].ChartType = SeriesChartType.Bar;
                chart1.Series[seriesName].ChartType    = SeriesChartType.Column;
                chart1.Series[seriesName].BorderWidth  = 0;
                chart1.Series[seriesName].ShadowOffset = 3;

                dtGridView[1, i].Value = System.Math.Round(calcCriteria.GetElement(i, 0), 4);

                for (int j = 0; j < dtKandidat.Rows.Count; j++)
                {
                    double val = results.GetElement(j, i);
                    dtGridView[j + 2, i].Value = System.Math.Round(val, 4);

                    string kandidateName = dtKandidat.Rows[j][0].ToString();
                    chart1.Series[seriesName].Points.AddXY(kandidateName, val);
                }
            }

            //composite weight
            dtGridView.Rows.Add(1);
            dtGridView[0, dtGridView.Rows.Count - 1].Value = "Composite Weight";
            for (int b = 0; b < dtKandidat.Rows.Count; b++)
            {
                dtGridView[b + 2, dtGridView.Rows.Count - 1].Value = string.Format("{0}", System.Math.Round(choices.GetElement(b, 0), 3), System.Math.Round(choices.GetElement(b, 0) * 100, 0));
            }
        }
Example #7
0
        public void TestChoiceMatrix()
        {
            double[][] mat1 = new double[][]
            {
                new double[] { 1, 2, 3, 4 },
                new double[] { 0, 1, 2, 5 },
                new double[] { 0, 0, 1, 5 },
                new double[] { 0, 0, 0, 1 }
            };

            GeneralMatrix gmat1 = new GeneralMatrix(mat1);

            gmat1 = AHPModel.ExpandUtility(gmat1);

            double[][] mat2 = new double[][]
            {
                new double[] { 1, 2, 3, 1 },
                new double[] { 0, 1, 2, 3 },
                new double[] { 0, 0, 1, 9 },
                new double[] { 0, 0, 0, 1 }
            };
            GeneralMatrix gmat2 = new GeneralMatrix(mat2);

            gmat2 = AHPModel.ExpandUtility(gmat2);

            double[][] mat3 = new double[][]
            {
                new double[] { 1, 4, 2, 2 },
                new double[] { 0, 1, 2, 4 },
                new double[] { 0, 0, 1, 4 },
                new double[] { 0, 0, 0, 1 }
            };

            GeneralMatrix gmat3 = new GeneralMatrix(mat3);

            gmat3 = AHPModel.ExpandUtility(gmat3);


            //3 criteria 4 choices
            AHPModel model = new AHPModel(3, 4);

            model.AddCriterionRatedChoices(0, mat1);
            model.AddCriterionRatedChoices(1, mat2);
            model.AddCriterionRatedChoices(2, mat3);

            GeneralMatrix matrix = model.ChoiceMatrix;

            GeneralMatrix nmat1 = matrix.GetMatrix(0, 3, 0, 3);
            GeneralMatrix nmat2 = matrix.GetMatrix(0, 3, 4, 7);
            GeneralMatrix nmat3 = matrix.GetMatrix(0, 3, 8, 11);

            bool alarm = false;

            int i, j;

            for (i = 0; i < nmat1.ColumnDimension; i++)
            {
                for (j = 0; j < nmat1.RowDimension; j++)
                {
                    if (nmat1.GetElement(i, j) != gmat1.GetElement(i, j))
                    {
                        alarm = true;
                    }
                }
            }

            for (i = 0; i < nmat2.ColumnDimension; i++)
            {
                for (j = 0; j < nmat2.RowDimension; j++)
                {
                    if (nmat2.GetElement(i, j) != gmat2.GetElement(i, j))
                    {
                        alarm = true;
                    }
                }
            }

            for (i = 0; i < nmat3.ColumnDimension; i++)
            {
                for (j = 0; j < nmat3.RowDimension; j++)
                {
                    if (nmat3.GetElement(i, j) != gmat3.GetElement(i, j))
                    {
                        alarm = true;
                    }
                }
            }


            Assert.IsFalse(alarm);
        }
Example #8
0
        public void TestFeatureSelection()
        {
            double[][] criteria = new double[][]
            {
                new double[] { 1, 0.33333333, 0.166666667 },
                new double[] { 0, 1, 0.2 },
                new double[] { 0, 0, 1 }
            };

            double[][] costChoices = new double[][]
            {
                new double[] { 1.00000, 0.50000, 0.11111, 0.25000, 0.20000, 3.00000, 2.00000, 0.33333, 7.00000, 2.00000, 5.00000, 1.00000, 3.00000, 4.00000, 0.25000, 0.33333, 0.20000, 1.00000, 0.14286 },
                new double[] { 0.00000, 1.00000, 0.11111, 0.20000, 0.14286, 4.00000, 3.00000, 0.20000, 4.00000, 3.00000, 5.00000, 1.00000, 3.00000, 3.00000, 0.20000, 0.25000, 0.20000, 3.00000, 0.14286 },
                new double[] { 0.00000, 0.00000, 1.00000, 9.00000, 5.00000, 9.00000, 9.00001, 5.00000, 9.00000, 9.00000, 9.00000, 8.00000, 9.00000, 6.00000, 4.00000, 6.00000, 5.00000, 7.00000, 1.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 1.00000, 0.16667, 6.00000, 5.00000, 0.33333, 4.00000, 3.00000, 5.00000, 3.00000, 4.00000, 0.50000, 0.25000, 0.50000, 0.25000, 2.00000, 0.14286 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 9.00000, 8.00000, 5.00000, 9.00000, 6.00000, 8.00000, 6.00000, 9.00000, 7.00000, 3.00000, 6.00000, 5.00000, 7.00001, 2.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.33333, 0.14286, 1.00000, 0.25000, 0.33333, 0.20000, 1.00000, 0.20000, 0.12500, 0.20000, 0.14286, 0.25000, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.16667, 2.00000, 0.33333, 2.00000, 0.25000, 3.00000, 0.20000, 0.14286, 0.20000, 0.14286, 0.25000, 0.12500 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 8.00000, 5.00000, 6.00000, 4.00000, 8.00000, 3.00000, 0.33333, 4.00000, 1.00000, 4.00000, 0.16667 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.20000, 0.33333, 0.16667, 1.00000, 0.16667, 0.12500, 0.20000, 0.12500, 0.25000, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 4.00000, 0.50000, 6.00000, 0.25000, 0.14286, 0.25000, 0.16667, 0.33333, 0.12500 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.20000, 4.00000, 0.20000, 0.14286, 0.20000, 0.14286, 0.33333, 0.12500 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 5.00000, 1.00000, 0.33333, 1.00000, 0.33333, 3.00000, 0.14286 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.16667, 0.12500, 0.16667, 0.12500, 0.20000, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.33333, 1.00000, 0.33333, 3.00000, 0.16667 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 5.00000, 4.00000, 5.99999, 0.33333 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.33333, 3.00000, 0.16667 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 3.00000, 0.20000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.16670 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000 }
            };

            double[][] efficiencyChoices = new double[][]
            {
                new double[] { 1.00000, 0.11110, 0.33333, 0.20000, 0.16667, 0.20000, 0.14286, 1.00000, 0.11111, 0.50000, 0.20000, 0.16667, 0.11111, 0.25000, 0.50000, 0.25000, 5.00000, 1.00000, 0.14286 },
                new double[] { 0.00000, 1.00000, 8.00000, 6.00000, 5.00000, 4.00000, 0.25000, 9.00000, 0.33333, 7.00000, 7.00000, 5.00000, 0.20000, 4.00000, 8.00000, 4.00000, 9.00000, 7.00000, 0.33333 },
                new double[] { 0.00000, 0.00000, 1.00000, 0.20000, 0.14286, 0.12500, 0.11111, 1.00000, 0.11111, 0.33333, 0.25000, 0.16667, 0.11111, 0.20000, 1.00000, 0.25000, 3.00000, 0.33333, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 1.00000, 0.25000, 0.50000, 0.20000, 9.00001, 0.25000, 4.00000, 6.00000, 4.00000, 0.14286, 0.33333, 6.00000, 2.00000, 8.00000, 4.00000, 0.16670 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.33333, 0.20000, 9.00001, 0.12500, 3.00000, 3.00000, 1.00000, 0.14286, 0.25000, 5.00000, 4.00000, 9.00000, 5.99999, 0.20000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.25000, 7.00001, 0.20000, 5.00000, 6.00000, 4.00000, 0.20000, 4.00000, 7.00000, 5.00000, 9.00000, 7.00001, 0.50000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 9.00000, 0.50000, 7.00000, 7.00000, 5.00000, 0.33333, 4.00000, 9.00000, 7.00000, 9.00000, 7.00000, 2.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.11111, 0.14286, 0.33333, 0.14286, 0.11111, 0.16667, 0.33333, 0.20000, 2.00000, 0.50000, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 9.00000, 9.00000, 6.00000, 0.50000, 7.00000, 9.00000, 7.00000, 9.00000, 8.00000, 3.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 2.00000, 0.33333, 0.12500, 0.25000, 2.00000, 0.33333, 5.00000, 3.00000, 0.12500 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.20000, 0.12500, 0.20000, 1.00000, 0.25000, 3.00000, 1.00000, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.14286, 0.50000, 6.00000, 4.00000, 8.00000, 5.99999, 0.25000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 7.00000, 9.00000, 7.00001, 9.00000, 9.00001, 3.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 8.00000, 5.99999, 9.00000, 5.00000, 0.16667 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.33333, 5.00000, 1.00000, 0.12500 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 5.00000, 4.00000, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.25000, 0.11111 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.11110 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000 }
            };

            double[][] revenueChoices = new double[][]
            {
                new double[] { 1.00000, 7.00000, 0.50000, 4.00000, 2.00000, 4.00000, 7.00001, 2.00000, 8.00000, 6.00000, 2.00000, 0.50000, 0.25000, 7.00000, 6.00000, 0.16667, 0.50000, 0.25000, 9.00000 },
                new double[] { 0.00000, 1.00000, 0.16667, 2.00000, 0.33333, 0.20000, 0.25000, 0.16667, 2.00000, 0.33333, 0.12500, 0.14286, 0.14286, 6.00000, 0.25000, 0.16667, 0.33333, 0.11110, 2.00000 },
                new double[] { 0.00000, 0.00000, 1.00000, 0.33333, 0.33333, 0.50000, 3.00000, 0.25000, 5.00000, 4.00000, 0.50000, 0.33333, 0.16667, 5.00000, 0.33333, 0.20000, 0.33333, 0.12500, 9.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 1.00000, 0.20000, 0.50000, 4.00000, 3.00000, 8.00000, 6.00000, 4.00000, 3.00000, 0.14286, 6.00000, 3.00000, 0.20000, 4.00000, 0.33333, 9.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 3.00000, 2.00000, 4.00000, 8.00000, 6.00000, 3.00000, 2.00000, 0.12500, 8.00000, 2.00000, 0.25000, 6.00000, 0.33333, 9.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 3.00000, 2.00000, 7.00000, 4.00000, 3.00000, 2.00000, 0.12500, 4.00000, 1.00000, 0.20000, 3.00000, 0.16667, 9.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 3.00000, 5.00000, 0.50000, 0.33333, 0.25000, 0.11111, 2.00000, 1.00000, 0.14286, 0.33333, 0.14286, 3.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 4.00000, 5.00000, 2.00000, 0.50000, 0.14286, 5.00000, 2.00000, 0.14286, 1.00000, 0.16667, 5.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.50000, 0.33333, 0.25000, 0.11111, 2.00000, 0.33333, 0.14286, 0.33333, 0.16667, 3.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.20000, 0.16667, 0.11111, 4.00000, 0.33333, 0.12500, 0.16667, 0.14286, 6.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.33333, 0.11111, 4.00000, 0.50000, 0.14286, 2.00000, 0.16667, 7.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.11111, 5.00000, 4.00000, 0.14286, 2.00000, 0.16667, 6.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 9.00000, 9.00000, 7.00001, 9.00000, 4.00000, 9.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.25000, 0.14286, 0.33333, 0.16667, 3.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.20000, 3.00000, 0.20000, 6.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 7.00000, 2.00000, 9.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.25000, 9.00001 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 9.00000 },
                new double[] { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000 }
            };

            //3 criteria, 19 features = choices
            AHPModel model = new AHPModel(3, 19);

            model.AddCriteria(criteria);

            model.AddCriterionRatedChoices(0, costChoices);
            model.AddCriterionRatedChoices(1, efficiencyChoices);
            model.AddCriterionRatedChoices(2, revenueChoices);

            model.CalculateModel();

            GeneralMatrix choices = model.CalculatedChoices;

            Assert.AreEqual(19, System.Math.Round(choices.GetElement(12, 0) * 100, 0));
        }
Example #9
0
        /// <summary>
        /// This method will calculate the contest results.
        /// </summary>
        private void CalculateContestResults()
        {
            GetContestVotes();

            double[][] criteriaValues;
            double[][] projectValues;

            List <double[][]>    judgeProjectValues = new List <double[][]>();
            List <GeneralMatrix> projectResults     = new List <GeneralMatrix>();

            // Cycle through all judge evaluations.
            foreach (JudgeEvaluation judgeEvaluation in contestEvaluation.JudgeEvaluations)
            {
                criteriaValues = new double[criteriaCount][];

                // Cycle through all criteria evaluations.
                int k = 0;
                for (int i = 0; i < criteriaCount; i++)
                {
                    criteriaValues[i] = new double[criteriaCount];
                    for (int j = i; j < criteriaCount; j++)
                    {
                        if (i != j)
                        {
                            double evaluation = judgeEvaluation.CriteriaEvaluations[k].Value;

                            if (evaluation > 0)
                            {
                                criteriaValues[i][j] = evaluation;
                            }
                            else
                            {
                                criteriaValues[i][j] = (1 / Math.Abs(evaluation));
                            }

                            k++;
                        }
                        else
                        {
                            criteriaValues[i][j] = 1;
                        }
                    }
                }

                int l = 0;

                judgeProjectValues = new List <double[][]>();

                // Cycle through all project evaluations.
                for (int i = 0; i < criteriaCount; i++)
                {
                    projectValues = new double[projectCount][];

                    for (int j = 0; j < projectCount; j++)
                    {
                        projectValues[j] = new double[projectCount];
                        for (k = j; k < projectCount; k++)
                        {
                            if (j != k)
                            {
                                double evaluation = judgeEvaluation.ProjectEvaluations[l].Value;

                                if (evaluation > 0)
                                {
                                    projectValues[j][k] = evaluation;
                                }
                                else
                                {
                                    projectValues[j][k] = (1 / Math.Abs(evaluation));
                                }

                                l++;
                            }
                            else
                            {
                                projectValues[j][k] = 1;
                            }
                        }
                    }

                    judgeProjectValues.Add(projectValues);
                }

                AHPModel model;

                model = new AHPModel(criteriaCount, projectCount);

                model.AddCriteria(criteriaValues);

                for (int i = 0; i < judgeProjectValues.Count; i++)
                {
                    model.AddCriterionRatedChoices(i, judgeProjectValues[i]);
                }

                model.CalculateModel();

                GeneralMatrix results = model.CalculatedChoices;

                projectResults.Add(results);
            }

            foreach (Project project in contest.Projects)
            {
                contestResults.Add(new ProjectResult
                {
                    Project = project,
                    Result  = 0
                });
            }

            contestResults = new ObservableCollection <ProjectResult>(contestResults.OrderBy(contestResult => contestResult.Project.Id).ToList());

            for (int i = 0; i < projectResults.Count; i++)
            {
                for (int j = 0; j < contestResults.Count; j++)
                {
                    contestResults[j].Result += projectResults[i].Array[j][0];
                }
            }

            // Normalize the scores so they all sum together to 1.
            foreach (ProjectResult projectResult in contestResults)
            {
                projectResult.Result /= (double)projectResults.Count;
            }

            // Order the projects by their results.
            contestResults = new ObservableCollection <ProjectResult>(contestResults.OrderByDescending(contestResult => contestResult.Result).ToList());

            // Check if any projects have the same results.
            for (int i = 0; i < contestResults.Count - 1; i++)
            {
                if (contestResults[i].Result == contestResults[i + 1].Result)
                {
                    // Get the youngest promoter.
                    Promoter youngestPromoterProject1 = new Promoter();
                    foreach (Promoter promoter in contestResults[i].Project.Promoters)
                    {
                        if (promoter.DateOfBirth < youngestPromoterProject1.DateOfBirth)
                        {
                            youngestPromoterProject1 = promoter;
                        }
                    }

                    Promoter youngestPromoterProject2 = new Promoter();
                    foreach (Promoter promoter in contestResults[i + 1].Project.Promoters)
                    {
                        if (promoter.DateOfBirth < youngestPromoterProject2.DateOfBirth)
                        {
                            youngestPromoterProject2 = promoter;
                        }
                    }

                    // Check which has the youngest promoter.
                    // If the second one isn't younger than the first one, nothing changes.
                    if (youngestPromoterProject1.DateOfBirth > youngestPromoterProject2.DateOfBirth)
                    {
                        Project tempProject = contestResults[i].Project;

                        contestResults[i].Project     = contestResults[i + 1].Project;
                        contestResults[i + 1].Project = tempProject;
                    }
                }
            }
        }