Beispiel #1
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);
        }
Beispiel #2
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[][] 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));
        }
Beispiel #3
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));
        }