コード例 #1
0
        private static List <(string option, string criteria, decimal adjustedRdv)> CalculateCriteriaAdjustedOptionRdvs(Decision decision, Dictionary <string, decimal> criteriaRdvs)
        {
            var adjustedOptionCriteriaRdvs = new List <(string option, string criteria, decimal adjustedRdv)>();

            foreach (var crit in decision.Criteria.Items)
            {
                var ocs = decision.OptionComparisons.Where(oc => oc.Criterion == crit).ToList();
                // add inverses
                var inverseOcs = ocs.Select(cc =>
                {
                    var inverseOc = new OptionComparison(crit, cc.OptionTwo, cc.OptionOne);
                    inverseOc.SetWeight(GetInverseWeight(cc.Weight.Value));
                    return(inverseOc);
                }).ToList();
                ocs.AddRange(inverseOcs);

                var totalWeight = ocs.Sum(oc => GetWeightFactor(oc.Weight.Value));

                // calculate the total RDV for each option for this criterion
                var optionRdvs = ocs.GroupBy(c => c.OptionOne).Select(g =>
                                                                      new
                {
                    Option = g.Key,
                    Rdv    = g.Sum(cc => GetWeightFactor(cc.Weight.Value)) / totalWeight
                }).ToList();

                // record the criteria-RDV-adjusted option total RDV
                foreach (var optionRdv in optionRdvs)
                {
                    var adjustedOptionRdv = criteriaRdvs[crit] * optionRdv.Rdv;
                    adjustedOptionCriteriaRdvs.Add((optionRdv.Option, crit, adjustedOptionRdv));
                }
            }
            return(adjustedOptionCriteriaRdvs);
        }
コード例 #2
0
ファイル: Decision.cs プロジェクト: timplourde/dcidr-blazor
        private void UpdateOptionComparisons()
        {
            var currentHashCodes  = new HashSet <int>(OptionComparisons.Select(c => c.GetHashCode()));
            var proposedHashCodes = new HashSet <int>();

            foreach (var crit in Criteria.Items)
            {
                for (int i = 0; i < Options.Items.Count(); i++)
                {
                    for (int j = i + 1; j < Options.Items.Count(); j++)
                    {
                        var oc = new OptionComparison(crit, Options.Items.ElementAt(i), Options.Items.ElementAt(j));
                        oc.OnWeightChange += OnWeightChange;
                        var hashCode = oc.GetHashCode();
                        proposedHashCodes.Add(hashCode);
                        if (!currentHashCodes.Contains(hashCode))
                        {
                            OptionComparisons.Add(oc);
                        }
                    }
                }
            }

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

            OptionComparisons = OptionComparisons.OrderBy(b => b.Criterion).ToList();
        }