Beispiel #1
0
        // methodId - integer from 1 - 4
        // 1 - constant probability
        // 2 - variable probability
        // 3 - lotteries comparison
        // 4 - probability comparison
        public DialogController(PartialUtility partialUtility, int methodId, double p = 0.5)
        {
            _methodId                = methodId;
            DisplayObject            = new DisplayObject();
            PointsList               = partialUtility.PointsValues;
            DisplayObject.PointsList = PointsList;
            DisplayObject.P          = p;
            _zeroUtilityPoint        = partialUtility.PointsValues.Find(o => o.Y == 0);
            _oneUtilityPoint         = partialUtility.PointsValues.Find(o => o.Y == 1);

            if (_methodId == 1)
            {
                createConstantProbabilityObject();
            }
            else if (_methodId == 2)
            {
                createVariableProbabilityObject();
            }
            else if (_methodId == 3)
            {
                createLotteriesComparisonObject();
            }
            else if (_methodId == 4)
            {
                createProbabilityComparisonObject();
            }
        }
Beispiel #2
0
        private double CheckEdgePoints(PartialUtility partialUtility)
        {
            var criterionId  = partialUtility.Criterion.ID;
            var criterionMax = partialUtility.Criterion.MaxValue;
            var criterionMin = partialUtility.Criterion.MinValue;

            var lowestAbscissa  = partialUtility.PointsValues.Min(o => o.X);
            var highestAbscissa = partialUtility.PointsValues.Max(o => o.X);

            var lowestUtility  = partialUtility.PointsValues.Min(o => o.Y);
            var highestUtility = partialUtility.PointsValues.Max(o => o.Y);

            if (lowestAbscissa != criterionMin)
            {
                throw new ImproperFileStructureException("criterion " + criterionId +
                                                         " data set is not valid for UTA - lowest abscissa equals " + lowestAbscissa.ToString("G", CultureInfo.InvariantCulture) +
                                                         " and it should be the same like the lowest value for this criterion in performance_table.xml: " +
                                                         criterionMin.ToString("G", CultureInfo.InvariantCulture) + ".");
            }

            if (highestAbscissa != criterionMax)
            {
                throw new ImproperFileStructureException("criterion " + criterionId +
                                                         " data set is not valid for UTA - highest abscissa equals " + highestAbscissa.ToString("G", CultureInfo.InvariantCulture) +
                                                         " and it should be the same like the highest value for this criterion performance_table.xml: " +
                                                         criterionMax.ToString("G", CultureInfo.InvariantCulture) + ".");
            }


            if (lowestUtility != 0)
            {
                throw new ImproperFileStructureException("criterion " + criterionId +
                                                         " data set is not valid for UTA - lowest utility value of each function should be equal to 0 and it is " +
                                                         lowestUtility.ToString("G", CultureInfo.InvariantCulture) + ".");
            }


            return(highestUtility);
        }
Beispiel #3
0
        private void CheckFunctionMonotonicity(PartialUtility partialUtility)
        {
            var criterionId        = partialUtility.Criterion.ID;
            var criterionDirection = partialUtility.Criterion.CriterionDirection;

            for (var i = 1; i < partialUtility.PointsValues.Count; i++)
            {
                if (criterionDirection.Equals("Gain"))
                {
                    if (partialUtility.PointsValues[i].Y < partialUtility.PointsValues[i - 1].Y)
                    {
                        throw new ImproperFileStructureException("criterion " + criterionId + " - data set is not valid for Assess method. Utility function has to be increasing for criterion direction '" + criterionDirection + "'.");
                    }
                }
                else if (criterionDirection.Equals("Cost"))
                {
                    if (partialUtility.PointsValues[i].Y > partialUtility.PointsValues[i - 1].Y)
                    {
                        throw new ImproperFileStructureException("criterion " + criterionId + " - data set is not valid for Assess method. Utility function has to be descending  for criterion direction '" + criterionDirection + "'.");
                    }
                }
            }
        }
Beispiel #4
0
        public void ChangeValue(double value, PartialUtility partialUtility, int indexOfPointValue)
        {
            if (value < partialUtility.PointsValues[indexOfPointValue].MinValue ||
                value > partialUtility.PointsValues[indexOfPointValue].MaxValue)
            {
                throw new ArgumentException("Value not in range", "PointsValues.Y");
            }
            var count          = 0;
            var criterionIndex = -1;

            for (var numOfCriterion = 0; numOfCriterion < Result.PartialUtilityFunctions.Count; numOfCriterion++)
            {
                if (Result.PartialUtilityFunctions[numOfCriterion].Criterion.Name == partialUtility.Criterion.Name)
                {
                    criterionIndex = numOfCriterion;
                    break;
                }
                else
                {
                    count += Result.PartialUtilityFunctions[numOfCriterion].Criterion.LinearSegments;
                }
            }

            if (indexOfPointValue < partialUtility.PointsValues.Count - 1)
            {
                if (indexOfPointValue > 0)
                {
                    arrayOfValues[count - 1 + indexOfPointValue + 1] += partialUtility.PointsValues[indexOfPointValue].Y - value;
                    arrayOfValues[count - 1 + indexOfPointValue]     -= partialUtility.PointsValues[indexOfPointValue].Y - value;
                    partialUtility.PointsValues[indexOfPointValue].Y  = value;
                    Result.PartialUtilityFunctions[criterionIndex]    = partialUtility;
                }
            }
            else
            {
                var currentCount = 0;
                var subValue     = (partialUtility.PointsValues[indexOfPointValue].Y - value) / (Result.PartialUtilityFunctions.Count - 1);
                for (var partialUtilityIndex = 0; partialUtilityIndex < Result.PartialUtilityFunctions.Count; partialUtilityIndex++)
                {
                    currentCount += Result.PartialUtilityFunctions[partialUtilityIndex].Criterion.LinearSegments;
                    if (partialUtilityIndex != criterionIndex)
                    {
                        var pointValue = Result.PartialUtilityFunctions[partialUtilityIndex].PointsValues;
                        pointValue[pointValue.Count - 1].Y += subValue;
                        arrayOfValues[currentCount - 1]    += subValue;
                        Result.PartialUtilityFunctions[partialUtilityIndex].PointsValues = pointValue;
                    }
                }

                partialUtility.PointsValues[indexOfPointValue].Y -= subValue * (Result.PartialUtilityFunctions.Count - 1);
                arrayOfValues[count - 1 + indexOfPointValue]     -= subValue * (Result.PartialUtilityFunctions.Count - 1);
                Result.PartialUtilityFunctions[criterionIndex]    = partialUtility;
            }

            UpdateMinMax();

            var finalReferenceList    = CreateRanking(arrayOfValues, transientMatrix, arternativesList);
            var finalReferenceRanking = new FinalRanking(finalReferenceList);
            var tau = CalculateKendallCoefficient(finalReferenceRanking);
            var restOfReferenceList  = CreateRanking(arrayOfValues, otherAlternativesMatrix, otherAlternatives);
            var allFinalRankingEntry = finalReferenceList.Concat(restOfReferenceList).ToList();

            allFinalRankingEntry = allFinalRankingEntry.OrderByDescending(o => o.Utility).ToList();
            for (var i = 0; i < allFinalRankingEntry.Count; i++)
            {
                allFinalRankingEntry[i].Position = i + 1;
            }
            Result.FinalRanking.FinalRankingCollection = new ObservableCollection <FinalRankingEntry>(allFinalRankingEntry);
            Result.KendallCoefficient = tau;
        }
Beispiel #5
0
        private void CheckEdgePoints(PartialUtility partialUtility)
        {
            var criterionId        = partialUtility.Criterion.ID;
            var criterionDirection = partialUtility.Criterion.CriterionDirection;
            var criterionMax       = partialUtility.Criterion.MaxValue;
            var criterionMin       = partialUtility.Criterion.MinValue;

            var lowestAbscissa  = partialUtility.PointsValues[0].X;
            var highestAbscissa = partialUtility.PointsValues[partialUtility.PointsValues.Count - 1].X;

            var lowestAbscissaUtility  = partialUtility.PointsValues[0].Y;
            var highestAbscissaUtility = partialUtility.PointsValues[partialUtility.PointsValues.Count - 1].Y;

            if (lowestAbscissa != criterionMin)
            {
                throw new ImproperFileStructureException("criterion " + criterionId +
                                                         " - data set is not valid for Assess method. Lowest abscissa equals " + lowestAbscissa.ToString("G", CultureInfo.InvariantCulture) +
                                                         " and it should be the same like the lowest value for this criterion in performance_table.xml: " +
                                                         criterionMin.ToString("G", CultureInfo.InvariantCulture) + ".");
            }

            if (lowestAbscissa != criterionMin)
            {
                throw new ImproperFileStructureException("criterion " + criterionId +
                                                         " - data set is not valid for Assess method. Lowest abscissa equals " + lowestAbscissa.ToString("G", CultureInfo.InvariantCulture) +
                                                         " and it should be the same like the lowest value for this criterion in performance_table.xml: " +
                                                         criterionMin.ToString("G", CultureInfo.InvariantCulture) + ".");
            }

            if (highestAbscissa != criterionMax)
            {
                throw new ImproperFileStructureException("criterion " + criterionId +
                                                         " - data set is not valid for Assess method. Highest abscissa equals " + lowestAbscissa.ToString("G", CultureInfo.InvariantCulture) +
                                                         " and it should be the same like the highest value for this criterion performance_table.xml: " +
                                                         criterionMax.ToString("G", CultureInfo.InvariantCulture) + ".");
            }

            if (criterionDirection.Equals("Gain"))
            {
                if (lowestAbscissaUtility != 0)
                {
                    throw new ImproperFileStructureException("criterion " + criterionId +
                                                             " - data set is not valid for Assess method. Lowest utility value of each function should be equal to 0 and it is " +
                                                             lowestAbscissaUtility.ToString("G", CultureInfo.InvariantCulture) + ".");
                }
                if (highestAbscissaUtility != 1)
                {
                    throw new ImproperFileStructureException("criterion " + criterionId +
                                                             " - data set is not valid for Assess method. Highest utility value of each function should be equal to 1 and it is " +
                                                             highestAbscissaUtility.ToString("G", CultureInfo.InvariantCulture) + ".");
                }
            }
            else if (criterionDirection.Equals("Cost"))
            {
                if (lowestAbscissaUtility != 1)
                {
                    throw new ImproperFileStructureException("criterion " + criterionId +
                                                             " - data set is not valid for Assess method. Highest utility value of each function should be equal to 1 and it is " +
                                                             lowestAbscissaUtility.ToString("G", CultureInfo.InvariantCulture) + ".");
                }
                if (highestAbscissaUtility != 0)
                {
                    throw new ImproperFileStructureException("criterion " + criterionId +
                                                             " - data set is not valid for Assess method. Lowest utility value of each function should be equal to 0 and it is " +
                                                             highestAbscissaUtility.ToString("G", CultureInfo.InvariantCulture) + ".");
                }
            }
        }
        public PartialUtilityTabViewModel(PartialUtility partialUtility, Results results, Action calculateUtilities, Action restartCoefficientsAssessment)
        {
            _partialUtility                = partialUtility;
            _calculateUtilities            = calculateUtilities;
            _restartCoefficientsAssessment = restartCoefficientsAssessment;
            _results = results;

            _initialPointsValues = new List <PartialUtilityValues>
            {
                new PartialUtilityValues(PointsValues[0].X, PointsValues[0].Y),
                new PartialUtilityValues(PointsValues.Last().X, PointsValues.Last().Y)
            };

            Name  = $"{Criterion.Name} - Utility";
            Title = $"{Criterion.Name} - Partial Utility Function";

            IsMethodSet = Criterion.Method != Criterion.MethodOptionsList[0];
            if (IsMethodSet)
            {
                DialogController = new DialogController(_partialUtility,
                                                        Criterion.MethodOptionsList.IndexOf(Criterion.Method), Criterion.Probability ?? 0.5);
            }
            else
            {
                // choose first method as default, to prevent from not selecting any method at all in radio buttons
                Criterion.Method = Criterion.MethodOptionsList[1];
            }

            const double verticalAxisExtraSpace   = 0.0001;
            var          horizontalAxisExtraSpace = (Criterion.MaxValue - Criterion.MinValue) * 0.0001;

            // plot initializer
            _line = new LineSeries
            {
                Color           = _lineColor,
                StrokeThickness = 3,
                MarkerFill      = _lineColor,
                MarkerType      = MarkerType.Circle,
                MarkerSize      = 6
            };

            _placeholderLine = new LineSeries
            {
                Color                 = _placeholderLineColor,
                StrokeThickness       = 3,
                MarkerStroke          = _placeholderMarkerColor,
                MarkerStrokeThickness = 2,
                MarkerFill            = OxyColors.Transparent,
                MarkerType            = MarkerType.Circle,
                MarkerSize            = 9
            };

            PlotModel = new ViewResolvingPlotModel
            {
                Series             = { _line, _placeholderLine },
                DefaultFont        = "Segoe UI",
                DefaultFontSize    = 14,
                Padding            = new OxyThickness(0, 0, 0, 0),
                PlotAreaBackground = OxyColors.White,
                Axes =
                {
                    new LinearAxis
                    {
                        Position           = AxisPosition.Left,
                        Title              = "Partial Utility",
                        FontSize           = 16,
                        MajorGridlineStyle = LineStyle.Solid,
                        MajorGridlineColor = _gridColor,
                        AbsoluteMinimum    = 0 - verticalAxisExtraSpace,
                        AbsoluteMaximum    = 1 + verticalAxisExtraSpace,
                        Minimum            = 0 - verticalAxisExtraSpace,
                        Maximum            = 1 + verticalAxisExtraSpace,
                        MajorTickSize      = 8,
                        IntervalLength     = 30,
                        AxisTitleDistance  = 12
                    },
                    new LinearAxis
                    {
                        Position           = AxisPosition.Bottom,
                        Title              = "Criterion Value",
                        FontSize           = 16,
                        MajorGridlineStyle = LineStyle.Solid,
                        MajorGridlineColor = _gridColor,
                        AbsoluteMinimum    = Criterion.MinValue - horizontalAxisExtraSpace,
                        AbsoluteMaximum    = Criterion.MaxValue + horizontalAxisExtraSpace,
                        Minimum            = Criterion.MinValue - horizontalAxisExtraSpace,
                        Maximum            = Criterion.MaxValue + horizontalAxisExtraSpace,
                        MajorTickSize      = 8,
                        AxisTitleDistance  = 4
                    }
                }
            };
            PlotModel.MouseDown += (sender, args) =>
            {
                if (args.ChangedButton != OxyMouseButton.Left)
                {
                    return;
                }
                DeselectRectangle();
            };
            InitializePlotIfMethodIsSet();
        }