Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/03/20 15:50:59 (4 years ago)
Author:
abeham
Message:

#2521: working on VRP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/ConstraintRelaxation/Capacitated/CapacityRelaxationVRPAnalyzer.cs

    r17698 r17710  
    2020#endregion
    2121
     22using HEAL.Attic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2627using HeuristicLab.Optimization;
    2728using HeuristicLab.Parameters;
    28 using HEAL.Attic;
    2929using HeuristicLab.Problems.VehicleRouting.Interfaces;
     30using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    3031using HeuristicLab.Problems.VehicleRouting.Variants;
    3132
     
    4344      get { return (ScopeTreeLookupParameter<IVRPEncodedSolution>)Parameters["VRPTours"]; }
    4445    }
    45     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    46       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    47     }
    48 
    49     public ScopeTreeLookupParameter<DoubleValue> OverloadParameter {
    50       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Overload"]; }
     46    public ScopeTreeLookupParameter<CVRPEvaluation> EvaluationParameter {
     47      get { return (ScopeTreeLookupParameter<CVRPEvaluation>)Parameters["EvaluationResult"]; }
    5148    }
    5249
     
    7976      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance."));
    8077      Parameters.Add(new ScopeTreeLookupParameter<IVRPEncodedSolution>("VRPTours", "The VRP tours which should be evaluated."));
    81       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the VRP solutions which should be analyzed."));
    82 
    83       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Overload", "The overloads of the VRP solutions which should be analyzed."));
     78      Parameters.Add(new ScopeTreeLookupParameter<CVRPEvaluation>("EvaluationResult", "The evaluations of the VRP solutions which should be analyzed."));
    8479
    8580      Parameters.Add(new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.5)));
     
    113108      ResultCollection results = ResultsParameter.ActualValue;
    114109
    115       ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    116       ItemArray<DoubleValue> overloads = OverloadParameter.ActualValue;
     110      ItemArray<CVRPEvaluation> evaluations = EvaluationParameter.ActualValue;
    117111
    118112      double sigma = SigmaParameter.Value.Value;
     
    121115      double maxPenalty = MaxPenaltyFactorParameter.Value.Value;
    122116
    123       for (int j = 0; j < qualities.Length; j++) {
    124         qualities[j].Value -= overloads[j].Value * cvrp.OverloadPenalty.Value;
     117      for (int j = 0; j < evaluations.Length; j++) {
     118        evaluations[j].Quality -= evaluations[j].Overload * cvrp.OverloadPenalty.Value;
    125119      }
    126120
    127121      int validCount = 0;
    128       for (int j = 0; j < qualities.Length; j++) {
    129         if (overloads[j].Value == 0)
     122      for (int j = 0; j < evaluations.Length; j++) {
     123        if (evaluations[j].Overload == 0)
    130124          validCount++;
    131125      }
    132126
    133       double factor = 1.0 - ((double)validCount / (double)qualities.Length);
     127      double factor = 1.0 - ((double)validCount / (double)evaluations.Length);
    134128
    135129      double min = cvrp.OverloadPenalty.Value / (1 + sigma);
     
    142136        cvrp.CurrentOverloadPenalty.Value = maxPenalty;
    143137
    144       for (int j = 0; j < qualities.Length; j++) {
    145         qualities[j].Value += overloads[j].Value * cvrp.CurrentOverloadPenalty.Value;
     138      for (int j = 0; j < evaluations.Length; j++) {
     139        evaluations[j].Quality += evaluations[j].Overload * cvrp.CurrentOverloadPenalty.Value;
    146140      }
    147141
    148       if (!results.ContainsKey("Current Overload Penalty")) {
    149         results.Add(new Result("Current Overload Penalty", new DoubleValue(cvrp.CurrentOverloadPenalty.Value)));
     142      if (!results.TryGetValue("Current Overload Penalty", out IResult res) || !(res.Value is DoubleValue)) {
     143        results.AddOrUpdateResult("Current Overload Penalty", new DoubleValue(cvrp.CurrentOverloadPenalty.Value));
    150144      } else {
    151         (results["Current Overload Penalty"].Value as DoubleValue).Value = cvrp.CurrentOverloadPenalty.Value;
     145        (res.Value as DoubleValue).Value = cvrp.CurrentOverloadPenalty.Value;
    152146      }
    153147
Note: See TracChangeset for help on using the changeset viewer.