Esempio n. 1
0
        public void loadDynamicUI()
        {
            flowLayoutPanel1.Controls.Clear();

            List <CriteriaWeight> criteriaWeightList = criteriaWeightController.getCriteriaWeightListName(currentTopicId);

            for (int i = 0; i < criteriaWeightList.Count; i++)
            {
                int    countUC          = flowLayoutPanel1.Controls.Count + 1;
                int    criteriaWeightId = criteriaWeightList.ElementAt(i).criteriaWeightId;
                int    criteria1Id      = criteriaWeightList.ElementAt(i).criteria1Id;
                int    criteria2Id      = criteriaWeightList.ElementAt(i).criteria2Id;
                string criteria1Name    = criteriaWeightList.ElementAt(i).criteria1Name;
                string criteria2Name    = criteriaWeightList.ElementAt(i).criteria2Name;
                double importanceLevel  = criteriaWeightList.ElementAt(i).importanceLevel;

                PairwiseComparisonUserControl pairwiseComparisonUserControl = new PairwiseComparisonUserControl(countUC, criteriaWeightId, criteria1Id, criteria2Id, criteria1Name, criteria2Name, importanceLevel);
                pairwiseComparisonUserControl.Parent = flowLayoutPanel1;
                flowLayoutPanel1.Controls.Add(pairwiseComparisonUserControl);
            }
        }
        public double[] criteriaPriorityVector(string topicId)
        {
            // 1. Pairwise Comparison Matrix

            // 1.1. Get list of criteria Id for mapping
            List <int> criteriaIdList = new List <int>();

            foreach (Criteria criteria in criteriaController.getCriteriaList(topicId))
            {
                criteriaIdList.Add(criteria.criteriaId);
            }

            int countCriteria = criteriaIdList.Count;

            // 1.2. Mapping criteriaId to index
            Dictionary <int, int> criteriaId2Idx = new Dictionary <int, int>();

            for (int i = 0; i < countCriteria; i++)
            {
                criteriaId2Idx.Add(criteriaIdList.ElementAt(i), i);
            }

            // 1.3. Create list of data for each criteria weight
            // [[criteria1id, criteria2id, importancelvl], [criteria1id, criteria2id, importancelvl], ...]
            List <List <double> > cwData = new List <List <double> >();

            foreach (CriteriaWeight criteriaWeight in criteriaWeightController.getCriteriaWeightListName(topicId))
            {
                int    criteria1Id     = criteriaWeight.criteria1Id;
                int    criteria2Id     = criteriaWeight.criteria2Id;
                double importanceLevel = criteriaWeight.importanceLevel;

                int criteria1Idx, criteria2Idx;
                criteriaId2Idx.TryGetValue(criteria1Id, out criteria1Idx);
                criteriaId2Idx.TryGetValue(criteria2Id, out criteria2Idx);
                cwData.Add(new List <double>()
                {
                    criteria1Idx, criteria2Idx, importanceLevel
                });
            }

            // 1.4. Prepare blank matrix with value 1 in main diagonal
            double[][] pcMatrix = new double[countCriteria][];
            for (int i = 0; i < countCriteria; i++)
            {
                pcMatrix[i] = new double[countCriteria];
                for (int j = 0; j < countCriteria; j++)
                {
                    if (i == j)
                    {
                        pcMatrix[i][j] = 1;
                    }
                }
            }

            // 1.5. Fill other value in matrix
            foreach (List <double> cw in cwData)
            {
                int    criteria1Idx    = Convert.ToInt32(cw.ElementAt(0));
                int    criteria2Idx    = Convert.ToInt32(cw.ElementAt(1));
                double importanceLevel = cw.ElementAt(2);

                pcMatrix[criteria1Idx][criteria2Idx] = importanceLevel;
                pcMatrix[criteria2Idx][criteria1Idx] = 1 / importanceLevel;
            }

            // 2. Normalize Matrix
            double[][] normalizedPcMatrix = cloneMatrix(pcMatrix, countCriteria);

            // 2.1. Sum by Column
            double[] colSum = new double[countCriteria];
            for (int i = 0; i < countCriteria; i++)
            {
                double tempSum = 0;
                for (int j = 0; j < countCriteria; j++)
                {
                    tempSum += pcMatrix[j][i];
                }
                colSum[i] = tempSum;
            }

            // 2.2. Divide each cell by sum of the column
            for (int i = 0; i < countCriteria; i++)
            {
                for (int j = 0; j < countCriteria; j++)
                {
                    normalizedPcMatrix[i][j] = normalizedPcMatrix[i][j] / colSum[j];
                }
            }

            // 3. Calculate Priority Vector
            double[] priorityVec = new double[countCriteria];
            for (int i = 0; i < countCriteria; i++)
            {
                double tempSum = 0;
                for (int j = 0; j < countCriteria; j++)
                {
                    tempSum += normalizedPcMatrix[i][j];
                }
                priorityVec[i] = tempSum / countCriteria;
            }

            return(priorityVec);
        }