private static Dictionary <string, decimal> CalculateCriteriaRdvs(Decision decision)
        {
            // add inverse criteria comparisons
            var criteriaComparisons = decision.CriteriaComparisons.ToList();

            // add inverses
            var inverseCriteriaComparisons = criteriaComparisons.Select(cc =>
            {
                var inverseCc = new CriteriaComparison(cc.CriterionTwo, cc.CriterionOne);
                inverseCc.SetWeight(GetInverseWeight(cc.Weight.Value));
                return(inverseCc);
            }).ToList();

            criteriaComparisons.AddRange(inverseCriteriaComparisons);

            var totalCritCompWeight = criteriaComparisons.Sum(cc => GetWeightFactor(cc.Weight.Value));

            // build RDVs for each criterion
            var criteriaRdvs = criteriaComparisons.GroupBy(c => c.CriterionOne).Select(g =>
                                                                                       new
            {
                Criteria = g.Key,
                Rdv      = g.Sum(cc => GetWeightFactor(cc.Weight.Value)) / totalCritCompWeight
            }).ToDictionary(d => d.Criteria, d => d.Rdv);

            return(criteriaRdvs);
        }
Example #2
0
        private void UpdateCriteriaComparisons()
        {
            var currentHashCodes  = new HashSet <int>(CriteriaComparisons.Select(c => c.GetHashCode()));
            var proposedHashCodes = new HashSet <int>();

            for (int i = 0; i < Criteria.Items.Count(); i++)
            {
                for (int j = i + 1; j < Criteria.Items.Count(); j++)
                {
                    var cc = new CriteriaComparison(Criteria.Items.ElementAt(i), Criteria.Items.ElementAt(j));
                    cc.OnWeightChange += OnWeightChange;
                    var hashCode = cc.GetHashCode();
                    proposedHashCodes.Add(hashCode);
                    if (!currentHashCodes.Contains(hashCode))
                    {
                        CriteriaComparisons.Add(cc);
                    }
                }
            }

            foreach (var exitstingCc in CriteriaComparisons.ToList())
            {
                if (!proposedHashCodes.Contains(exitstingCc.GetHashCode()))
                {
                    exitstingCc.OnWeightChange -= OnWeightChange;
                    CriteriaComparisons.Remove(exitstingCc);
                }
            }

            CriteriaComparisons = CriteriaComparisons.OrderBy(c => c.CriterionOne).ToList();
        }