Пример #1
0
 public static void WriteMatrix(GeneralMatrix m)
 {
     if (m==null)
         return;
     for(int i = 0;i<m.RowDimension;++i)
     {
         for(int j = 0;j<m.ColumnDimension;++j)
         {
             Console.Write("{0} ",m.GetElement(i,j));
         }
         Console.WriteLine();
     }
 }
Пример #2
0
        /// <summary>
        /// Gets a list of coordinates from a general matrix.
        ///
        /// Any point in the general matrix that has a value greater than
        /// zero will correspond to an entry in the list of coords.
        /// </summary>
        /// <param name="mesh">The GeneralMatrix to create the list from.</param>
        /// <returns>The list of Coords representing the matrix.</returns>
        private List <Coord> IndexList(GeneralMatrix mesh)
        {
            List <Coord> indices = new List <Coord>();

            // make a list of the coordinates of the black pixels
            for (int row = 0; row < GRID_Y_SIZE; row++)
            {
                for (int col = 0; col < GRID_X_SIZE; col++)
                {
                    if (mesh.GetElement(row, col) > 0.0)
                    {
                        indices.Add(new Coord(col, row));
                    }
                }
            }

            return(indices);
        }
Пример #3
0
        public void TestPriorities()
        {
            PrioritiesSelector ps = new PrioritiesSelector();

            double[][] mat = new double[][]
            {
                new double[] { 1, 0.333333333, 2, 4 },
                new double[] { 3, 1, 5, 3 },
                new double[] { 0.5, 0.2, 1, 0.3333333333333 },
                new double[] { 0.25, 0.3333333333333, 3, 1 }
            };
            GeneralMatrix matrix = new GeneralMatrix(mat);

            ps.ComputePriorities(matrix);
            GeneralMatrix pr = ps.CalculatedMatrix;

            Assert.IsTrue(System.Math.Round(pr.GetElement(0, 0), 2) == 0.26);
        }
        public string Recognize(Sketch.Substroke stroke)
        {
            List <double> features  = getFeatureValues(stroke.PointsL);
            string        best      = "NA";
            double        bestScore = double.MinValue;
            List <double> allScores = new List <double>();

            // Compute scores for each class
            for (int c = 0; c < _classNames.Count; c++)
            {
                double sum = 0.0;
                for (int i = 0; i < _weights_0.Count; i++)
                {
                    sum += _weights.GetElement(c, i) * features[i];
                }

                double score = this._weights_0[c] + sum;
                allScores.Add(score);
                if (score > bestScore)
                {
                    bestScore = score;
                    best      = _classNames[c];
                }
            }
            allScores.Remove(bestScore);

            // Get Probability - for rejection
            double sumP = 0.0;

            foreach (double s in allScores)
            {
                sumP += Math.Exp(s - bestScore);
            }
            double probability = 1 / sumP;

            if (probability < SCORE_THRESHOLD)
            {
                return("Unknown");
            }

            return(best);
        }
Пример #5
0
        public void Hessian()
        {
            double eps = 1e-5;

            double[]      vector = { 0, 0, 0 };
            double[][]    result = { new double[] { 10.0, 2.0, -2.0 },
                                     new double[]    {  2.0, 4.0,  2.0 },
                                     new double[]    { -2.0, 2.0,  4.0 } };
            GeneralMatrix expectedMatrix = new GeneralMatrix(result);
            TestFunction  f       = new TestFunction();
            GeneralMatrix hessian = f.CalculateHessian(vector);

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Assert.IsTrue(System.Math.Abs(hessian.GetElement(i, j) - expectedMatrix.GetElement(i, j)) < eps);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Average values of the priority matrix over sum of columns.
        /// set values of sum of averaged rows into a new matrix
        /// </summary>
        /// <param name="argMatrix"></param>
        /// <param name="selection"></param>
        public void PCalc(GeneralMatrix argMatrix, GeneralMatrix selection)
        {
            int           n       = argMatrix.ColumnDimension;
            GeneralMatrix sMatrix = new GeneralMatrix(argMatrix.ArrayCopy);

            double c = 0.0;
            int    i, j;

            for (i = 0; i < sMatrix.ColumnDimension; i++)
            {
                c = 0.0;
                for (j = 0; j < sMatrix.RowDimension; j++)
                {
                    c += sMatrix.GetElement(j, i);
                }
                selection.SetElement(i, 0, c);
            }

            for (i = 0; i < sMatrix.ColumnDimension; i++)
            {
                for (j = 0; j < sMatrix.RowDimension; j++)
                {
                    sMatrix.SetElement(j, i, sMatrix.GetElement(j, i) / selection.GetElement(i, 0));
                }
            }

            for (i = 0; i < sMatrix.RowDimension; i++)
            {
                c = 0.0;
                for (j = 0; j < sMatrix.ColumnDimension; j++)
                {
                    c += sMatrix.GetElement(i, j);
                }
                selection.SetElement(i, 0, c / n);
            }
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
0
 public static PointD ToPointD(GeneralMatrix _3x1Matrix)
 {
     return(new PointD(_3x1Matrix.GetElement(0, 0), _3x1Matrix.GetElement(1, 0)));
 }
Пример #10
0
 public static PointF ToPointF(GeneralMatrix _3x1Matrix)
 {
     return(new PointF((float)_3x1Matrix.GetElement(0, 0), (float)_3x1Matrix.GetElement(1, 0)));
 }
Пример #11
0
        private void computeaccCalButton_Click(object sender, EventArgs e)
        {
            int i, j;

            calStatusText.Text = "Computing Calibration...";

            // Construct D matrix
            // D = [x.^2, y.^2, z.^2, x.*y, x.*z, y.*z, x, y, z, ones(N,1)];
            for (i = 0; i < SAMPLES; i++)
            {
                // x^2 term
                D.SetElement(i, 0, loggedData[i, 0] * loggedData[i, 0]);

                // y^2 term
                D.SetElement(i, 1, loggedData[i, 1] * loggedData[i, 1]);

                // z^2 term
                D.SetElement(i, 2, loggedData[i, 2] * loggedData[i, 2]);

                // x*y term
                D.SetElement(i, 3, loggedData[i, 0] * loggedData[i, 1]);

                // x*z term
                D.SetElement(i, 4, loggedData[i, 0] * loggedData[i, 2]);

                // y*z term
                D.SetElement(i, 5, loggedData[i, 1] * loggedData[i, 2]);

                // x term
                D.SetElement(i, 6, loggedData[i, 0]);

                // y term
                D.SetElement(i, 7, loggedData[i, 1]);

                // z term
                D.SetElement(i, 8, loggedData[i, 2]);

                // Constant term
                D.SetElement(i, 9, 1);
            }

            // QR=triu(qr(D))
            QRDecomposition QR = new QRDecomposition(D);
            // [U,S,V] = svd(D)
            SingularValueDecomposition SVD = new SingularValueDecomposition(QR.R);
            GeneralMatrix V = SVD.GetV();

            GeneralMatrix A = new GeneralMatrix(3, 3);

            double[] p = new double[V.RowDimension];

            for (i = 0; i < V.RowDimension; i++)
            {
                p[i] = V.GetElement(i, V.ColumnDimension - 1);
            }

            /*
             * A = [p(1) p(4)/2 p(5)/2;
             * p(4)/2 p(2) p(6)/2;
             * p(5)/2 p(6)/2 p(3)];
             */

            if (p[0] < 0)
            {
                for (i = 0; i < V.RowDimension; i++)
                {
                    p[i] = -p[i];
                }
            }

            A.SetElement(0, 0, p[0]);
            A.SetElement(0, 1, p[3] / 2);
            A.SetElement(1, 2, p[4] / 2);

            A.SetElement(1, 0, p[3] / 2);
            A.SetElement(1, 1, p[1]);
            A.SetElement(1, 2, p[5] / 2);

            A.SetElement(2, 0, p[4] / 2);
            A.SetElement(2, 1, p[5] / 2);
            A.SetElement(2, 2, p[2]);

            CholeskyDecomposition Chol = new CholeskyDecomposition(A);
            GeneralMatrix         Ut   = Chol.GetL();
            GeneralMatrix         U    = Ut.Transpose();

            double[]      bvect = { p[6] / 2, p[7] / 2, p[8] / 2 };
            double        d     = p[9];
            GeneralMatrix b     = new GeneralMatrix(bvect, 3);

            GeneralMatrix v = Ut.Solve(b);

            double vnorm_sqrd = v.GetElement(0, 0) * v.GetElement(0, 0) + v.GetElement(1, 0) * v.GetElement(1, 0) + v.GetElement(2, 0) * v.GetElement(2, 0);
            double s          = 1 / Math.Sqrt(vnorm_sqrd - d);

            GeneralMatrix c = U.Solve(v);

            for (i = 0; i < 3; i++)
            {
                c.SetElement(i, 0, -c.GetElement(i, 0));
            }

            U = U.Multiply(s);

            for (i = 0; i < 3; i++)
            {
                for (j = 0; j < 3; j++)
                {
                    calMat[i, j] = U.GetElement(i, j);
                }
            }

            for (i = 0; i < 3; i++)
            {
                bias[i] = c.GetElement(i, 0);
            }

            accAlignment00.Text = calMat[0, 0].ToString();
            accAlignment01.Text = calMat[0, 1].ToString();
            accAlignment02.Text = calMat[0, 2].ToString();

            accAlignment10.Text = calMat[1, 0].ToString();
            accAlignment11.Text = calMat[1, 1].ToString();
            accAlignment12.Text = calMat[1, 2].ToString();

            accAlignment20.Text = calMat[2, 0].ToString();
            accAlignment21.Text = calMat[2, 1].ToString();
            accAlignment22.Text = calMat[2, 2].ToString();

            biasX.Text = bias[0].ToString();
            biasY.Text = bias[1].ToString();
            biasZ.Text = bias[2].ToString();

            calStatusText.Text               = "Done";
            flashCommitButton.Enabled        = true;
            accAlignmentCommitButton.Enabled = true;
        }
Пример #12
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));
            }
        }
Пример #13
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);
        }
Пример #14
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));
        }
Пример #15
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);
        }
Пример #16
0
        /// <summary>
        /// Using linear least squares algorithm described at http://en.wikipedia.org/wiki/Linear_least_squares
        /// </summary>
        /// <returns></returns>
        public Transformation CalculateAverageTransformation()
        {
            var averageProjectionOrigin = new LongLat();

            foreach (var session in this)
            {
                averageProjectionOrigin += session.ProjectionOrigin / Count;
            }

            if (Count == 0)
            {
                return(null);
            }
            var n   = 4;
            var XtX = new GeneralMatrix(n, n);
            var Xty = new GeneralMatrix(n, 1);
            var numberOfUnknowns = 0;

            foreach (var session in this)
            {
                var m = session.Handles.Length;
                if (m < 2)
                {
                    continue;
                }
                numberOfUnknowns += m;

                var startDistance = session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Distance, session.Route.FirstPL).Value;
                for (var i = 0; i < m; i++)
                {
                    var longLat     = session.Route.GetLocationFromParameterizedLocation(session.Handles[i].ParameterizedLocation);
                    var p           = longLat.Project(averageProjectionOrigin); // projected point on earth (metres)
                    var q           = session.Handles[i].Location;              // point on map image (pixels)
                    var endDistance = (i != m - 1)
                              ? (session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Distance, session.Handles[i].ParameterizedLocation).Value +
                                 session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Distance, session.Handles[i + 1].ParameterizedLocation).Value) / 2
                              : session.Route.GetAttributeFromParameterizedLocation(WaypointAttribute.Distance, session.Route.LastPL).Value;
                    var w = endDistance - startDistance; // weight
                    startDistance = endDistance;

                    XtX.SetElement(0, 0, XtX.GetElement(0, 0) + w * (p.X * p.X + p.Y * p.Y));
                    XtX.SetElement(0, 2, XtX.GetElement(0, 2) + w * p.X);
                    XtX.SetElement(0, 3, XtX.GetElement(0, 3) - w * p.Y);
                    XtX.SetElement(1, 1, XtX.GetElement(1, 1) + w * (p.X * p.X + p.Y * p.Y));
                    XtX.SetElement(1, 2, XtX.GetElement(1, 2) + w * p.Y);
                    XtX.SetElement(1, 3, XtX.GetElement(1, 3) + w * p.X);
                    XtX.SetElement(2, 0, XtX.GetElement(2, 0) + w * p.X);
                    XtX.SetElement(2, 1, XtX.GetElement(2, 1) + w * p.Y);
                    XtX.SetElement(2, 2, XtX.GetElement(2, 2) + w);
                    XtX.SetElement(3, 0, XtX.GetElement(3, 0) - w * p.Y);
                    XtX.SetElement(3, 1, XtX.GetElement(3, 1) + w * p.X);
                    XtX.SetElement(3, 3, XtX.GetElement(3, 3) + w);

                    Xty.SetElement(0, 0, Xty.GetElement(0, 0) + w * (q.X * p.X - q.Y * p.Y));
                    Xty.SetElement(1, 0, Xty.GetElement(1, 0) + w * (q.X * p.Y + q.Y * p.X));
                    Xty.SetElement(2, 0, Xty.GetElement(2, 0) + w * q.X);
                    Xty.SetElement(3, 0, Xty.GetElement(3, 0) + w * q.Y);
                }
            }

            var T = new GeneralMatrix(3, 3);

            if (numberOfUnknowns == 0)
            {
                T = this[0].InitialTransformationMatrix;
            }
            else if (numberOfUnknowns == 1)
            {
                T = this[0].Handles[0].TransformationMatrix;
            }
            else
            {
                var B = XtX.QRD().Solve(Xty);

                T.SetElement(0, 0, B.GetElement(0, 0));
                T.SetElement(0, 1, B.GetElement(1, 0));
                T.SetElement(0, 2, B.GetElement(2, 0));
                T.SetElement(1, 0, B.GetElement(1, 0));
                T.SetElement(1, 1, -B.GetElement(0, 0));
                T.SetElement(1, 2, B.GetElement(3, 0));
                T.SetElement(2, 0, 0);
                T.SetElement(2, 1, 0);
                T.SetElement(2, 2, 1);
            }
            return(new Transformation(T, averageProjectionOrigin));
        }
Пример #17
0
        /// <summary>Generate magic square test matrix. *</summary>

        public static DotNetMatrix.GeneralMatrix magic(int n)
        {
            double[][] M = new double[n][];
            for (int i = 0; i < n; i++)
            {
                M[i] = new double[n];
            }

            // Odd order

            if ((n % 2) == 1)
            {
                int a = (n + 1) / 2;
                int b = (n + 1);
                for (int j = 0; j < n; j++)
                {
                    for (int i = 0; i < n; i++)
                    {
                        M[i][j] = n * ((i + j + a) % n) + ((i + 2 * j + b) % n) + 1;
                    }
                }

                // Doubly Even Order
            }
            else if ((n % 4) == 0)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (((i + 1) / 2) % 2 == ((j + 1) / 2) % 2)
                        {
                            M[i][j] = n * n - n * i - j;
                        }
                        else
                        {
                            M[i][j] = n * i + j + 1;
                        }
                    }
                }

                // Singly Even Order
            }
            else
            {
                int           p = n / 2;
                int           k = (n - 2) / 4;
                GeneralMatrix A = magic(p);
                for (int j = 0; j < p; j++)
                {
                    for (int i = 0; i < p; i++)
                    {
                        double aij = A.GetElement(i, j);
                        M[i][j]         = aij;
                        M[i][j + p]     = aij + 2 * p * p;
                        M[i + p][j]     = aij + 3 * p * p;
                        M[i + p][j + p] = aij + p * p;
                    }
                }
                for (int i = 0; i < p; i++)
                {
                    for (int j = 0; j < k; j++)
                    {
                        double t = M[i][j]; M[i][j] = M[i + p][j]; M[i + p][j] = t;
                    }
                    for (int j = n - k + 1; j < n; j++)
                    {
                        double t = M[i][j]; M[i][j] = M[i + p][j]; M[i + p][j] = t;
                    }
                }
                double t2 = M[k][0]; M[k][0] = M[k + p][0]; M[k + p][0] = t2;
                t2 = M[k][k]; M[k][k] = M[k + p][k]; M[k + p][k] = t2;
            }
            return(new GeneralMatrix(M));
        }
Пример #18
0
        /// <summary>
        /// Calculates the dissimilarity between the calling BitmapSymbol and
        /// BitmapSymbol S in terms of their polar coordinates using the
        /// modified Hausdorff distance (aka the mean distance).
        /// </summary>
        private SymbolRank Polar_Mod_Hausdorff(BitmapSymbol S)
        {
            int lower_rot_index = (int)Math.Floor(ALLOWED_ROTATION_AMOUNT * GRID_X_SIZE / 720.0);
            int upper_rot_index = GRID_X_SIZE - lower_rot_index; //trick

            List <Coord> A = new List <Coord>(_polarCoords);
            List <Coord> B = new List <Coord>(S._polarCoords);

            if (A.Count == 0 || B.Count == 0)
            {
                return(new SymbolRank());
            }

            double minA2B = double.PositiveInfinity;
            double distan = 0.0;
            int    besti  = 0; // the best translation in theta

#if FALSE
            Console.WriteLine("Your gate: ");
            Console.Write(_pMesh.ToString());

            Console.WriteLine("Your template: ");
            Console.Write(S._pMesh.ToString());
#endif

            // rotations in screen coordinates are the same as translations in polar coords
            // we have polar coords, so translate in X (theta) until you get the best orientation
            for (int i = 0; i < GRID_X_SIZE; i++)
            {
                if (i > lower_rot_index && i < upper_rot_index)
                {
                    continue;
                }

                distan = 0.0;
                // find the distance from each point in A to the nearest point in B using B_DTM
                foreach (Coord a in A)
                {
                    int y_ind = (int)a.Y;
                    int x_ind = (int)a.X - i; // translate by i on the theta (X) axis
                    if (x_ind < 0)
                    {
                        x_ind += GRID_X_SIZE;            // make sure we're still on the graph
                    }
                    //putting less weight on points that have small rel dist - y
                    double weight = Math.Pow((double)y_ind, POLAR_WEIGHT_DECAY_RATE);
                    distan += S._pDTM.GetElement(y_ind, x_ind) * weight;
                }

                // this is the best orientation if the total distance is the smallest
                if (distan < minA2B)
                {
                    minA2B = distan;
                    besti  = i;
                }
            }

            // set the best rotation angle (in radians)
            double bestRotAngle = besti * 2.0 * Math.PI / (double)GRID_X_SIZE;

            // we've already found the best orientation
            // find the distance from each point in B to the nearest point in A using A_DTM
            double minB2A = 0.0;
            foreach (Coord b in B)
            {
                int y_ind = (int)b.Y;
                int x_ind = (int)b.X - besti; // slide B back by besti
                if (x_ind < 0)
                {
                    x_ind += GRID_X_SIZE;
                }
                double weight = Math.Pow((double)y_ind, POLAR_WEIGHT_DECAY_RATE);
                minB2A += _pDTM.GetElement(y_ind, x_ind) * weight;
            }

            minA2B /= (double)A.Count;
            minB2A /= (double)B.Count;

#if FALSE
            Console.WriteLine("Finding best orientation match of your gate and " + S._name);
            Console.WriteLine("The best translation is " + besti + " which is " + bestRotAngle + " radians.");
            Console.WriteLine("A2B distance: " + minA2B + ", B2A distance: " + minB2A);
            string templateName = S._name;
#endif

            return(new SymbolRank(Math.Max(minA2B, minB2A), S, bestRotAngle));
        }