Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17710


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

#2521: working on VRP

Location:
branches/2521_ProblemRefactoring
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting.Views/3.4/HeuristicLab.Problems.VehicleRouting.Views-3.4.csproj

    r17709 r17710  
    335335      <DependentUpon>VRPEvaluationView.cs</DependentUpon>
    336336    </EmbeddedResource>
     337    <EmbeddedResource Include="VRPSolutionView.resx">
     338      <DependentUpon>VRPSolutionView.cs</DependentUpon>
     339    </EmbeddedResource>
    337340  </ItemGroup>
    338341  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.Designer.cs

    r17226 r17710  
    4646    private void InitializeComponent() {
    4747      this.tabControl1 = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl();
    48       this.tabPage1 = new System.Windows.Forms.TabPage();
    49       this.problemInstanceView = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5048      this.tabPage2 = new System.Windows.Forms.TabPage();
    5149      this.tourGroupBox = new System.Windows.Forms.GroupBox();
    5250      this.valueTextBox = new System.Windows.Forms.TextBox();
     51      this.tabPage3 = new System.Windows.Forms.TabPage();
     52      this.problemInstanceView = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     53      this.tabPage1 = new System.Windows.Forms.TabPage();
     54      this.evaluationViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5355      this.tabControl1.SuspendLayout();
    54       this.tabPage1.SuspendLayout();
    5556      this.tabPage2.SuspendLayout();
    5657      this.tourGroupBox.SuspendLayout();
     58      this.tabPage3.SuspendLayout();
     59      this.tabPage1.SuspendLayout();
    5760      this.SuspendLayout();
    5861      //
    5962      // tabControl1
    6063      //
     64      this.tabControl1.AllowDrop = true;
    6165      this.tabControl1.Controls.Add(this.tabPage1);
    6266      this.tabControl1.Controls.Add(this.tabPage2);
     67      this.tabControl1.Controls.Add(this.tabPage3);
    6368      this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
    6469      this.tabControl1.Location = new System.Drawing.Point(0, 0);
     
    6772      this.tabControl1.Size = new System.Drawing.Size(468, 415);
    6873      this.tabControl1.TabIndex = 0;
    69       //
    70       // tabPage1
    71       //
    72       this.tabPage1.BackColor = System.Drawing.SystemColors.Window;
    73       this.tabPage1.Controls.Add(this.problemInstanceView);
    74       this.tabPage1.Location = new System.Drawing.Point(4, 22);
    75       this.tabPage1.Name = "tabPage1";
    76       this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
    77       this.tabPage1.Size = new System.Drawing.Size(460, 389);
    78       this.tabPage1.TabIndex = 0;
    79       this.tabPage1.Text = "ProblemInstance";
    80       //
    81       // problemInstanceView
    82       //
    83       this.problemInstanceView.Caption = "View";
    84       this.problemInstanceView.Content = null;
    85       this.problemInstanceView.Dock = System.Windows.Forms.DockStyle.Fill;
    86       this.problemInstanceView.Location = new System.Drawing.Point(3, 3);
    87       this.problemInstanceView.Name = "problemInstanceView";
    88       this.problemInstanceView.ReadOnly = false;
    89       this.problemInstanceView.Size = new System.Drawing.Size(454, 383);
    90       this.problemInstanceView.TabIndex = 0;
    91       this.problemInstanceView.ViewType = null;
    9274      //
    9375      // tabPage2
     
    119101      this.valueTextBox.Multiline = true;
    120102      this.valueTextBox.Name = "valueTextBox";
    121       this.valueTextBox.Size = new System.Drawing.Size(403, 507);
     103      this.valueTextBox.ReadOnly = true;
     104      this.valueTextBox.Size = new System.Drawing.Size(448, 364);
    122105      this.valueTextBox.TabIndex = 0;
    123       this.valueTextBox.ReadOnly = true;
     106      //
     107      // tabPage3
     108      //
     109      this.tabPage3.Controls.Add(this.evaluationViewHost);
     110      this.tabPage3.Location = new System.Drawing.Point(4, 22);
     111      this.tabPage3.Name = "tabPage3";
     112      this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
     113      this.tabPage3.Size = new System.Drawing.Size(460, 389);
     114      this.tabPage3.TabIndex = 2;
     115      this.tabPage3.Text = "Evaluation";
     116      this.tabPage3.UseVisualStyleBackColor = true;
     117      //
     118      // problemInstanceView
     119      //
     120      this.problemInstanceView.Caption = "View";
     121      this.problemInstanceView.Content = null;
     122      this.problemInstanceView.Dock = System.Windows.Forms.DockStyle.Fill;
     123      this.problemInstanceView.Enabled = false;
     124      this.problemInstanceView.Location = new System.Drawing.Point(3, 3);
     125      this.problemInstanceView.Name = "problemInstanceView";
     126      this.problemInstanceView.ReadOnly = false;
     127      this.problemInstanceView.Size = new System.Drawing.Size(454, 383);
     128      this.problemInstanceView.TabIndex = 0;
     129      this.problemInstanceView.ViewsLabelVisible = true;
     130      this.problemInstanceView.ViewType = null;
     131      //
     132      // tabPage1
     133      //
     134      this.tabPage1.BackColor = System.Drawing.SystemColors.Window;
     135      this.tabPage1.Controls.Add(this.problemInstanceView);
     136      this.tabPage1.Location = new System.Drawing.Point(4, 22);
     137      this.tabPage1.Name = "tabPage1";
     138      this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
     139      this.tabPage1.Size = new System.Drawing.Size(460, 389);
     140      this.tabPage1.TabIndex = 0;
     141      this.tabPage1.Text = "ProblemInstance";
     142      //
     143      // evaluationViewHost
     144      //
     145      this.evaluationViewHost.Caption = "View";
     146      this.evaluationViewHost.Content = null;
     147      this.evaluationViewHost.Dock = System.Windows.Forms.DockStyle.Fill;
     148      this.evaluationViewHost.Enabled = false;
     149      this.evaluationViewHost.Location = new System.Drawing.Point(3, 3);
     150      this.evaluationViewHost.Name = "evaluationViewHost";
     151      this.evaluationViewHost.ReadOnly = false;
     152      this.evaluationViewHost.Size = new System.Drawing.Size(454, 383);
     153      this.evaluationViewHost.TabIndex = 2;
     154      this.evaluationViewHost.ViewsLabelVisible = true;
     155      this.evaluationViewHost.ViewType = null;
    124156      //
    125157      // VRPSolutionView
    126158      //
    127       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    128159      this.Controls.Add(this.tabControl1);
    129160      this.Name = "VRPSolutionView";
    130161      this.Size = new System.Drawing.Size(468, 415);
    131162      this.tabControl1.ResumeLayout(false);
    132       this.tabPage1.ResumeLayout(false);
    133163      this.tabPage2.ResumeLayout(false);
    134164      this.tourGroupBox.ResumeLayout(false);
     165      this.tourGroupBox.PerformLayout();
     166      this.tabPage3.ResumeLayout(false);
     167      this.tabPage1.ResumeLayout(false);
    135168      this.ResumeLayout(false);
    136169
     
    140173
    141174    private HeuristicLab.MainForm.WindowsForms.DragOverTabControl tabControl1;
    142     private System.Windows.Forms.TabPage tabPage1;
    143     private MainForm.WindowsForms.ViewHost problemInstanceView;
    144175    private System.Windows.Forms.TabPage tabPage2;
    145176    private System.Windows.Forms.GroupBox tourGroupBox;
    146177    private System.Windows.Forms.TextBox valueTextBox;
     178    private System.Windows.Forms.TabPage tabPage3;
     179    private System.Windows.Forms.TabPage tabPage1;
     180    private MainForm.WindowsForms.ViewHost problemInstanceView;
     181    private MainForm.WindowsForms.ViewHost evaluationViewHost;
    147182  }
    148183}
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs

    r17226 r17710  
    5858
    5959      UpdateTourView();
     60
     61      evaluationViewHost.Content = Content.Evaluation;
    6062    }
    6163
     
    6466      if (Content == null) {
    6567        problemInstanceView.Content = null;
     68        evaluationViewHost.Content = null;
     69        valueTextBox.Text = string.Empty;
    6670      } else {
    6771        UpdateContent();
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs

    r17709 r17710  
    2727using HeuristicLab.Optimization;
    2828using HeuristicLab.Parameters;
     29using HeuristicLab.Problems.VehicleRouting.Interfaces;
    2930using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    3031
     
    3334  /// An operator for analyzing the best solution of Vehicle Routing Problems.
    3435  /// </summary>
     36  //TODO: remove this operator -> part of VRP problem analyze
    3537  [Item("BestVRPSolutionAnalyzer", "An operator for analyzing the best solution of Vehicle Routing Problems.")]
    3638  [StorableType("3e1bb409-0b8f-4324-826c-2190aa5fb2b6")]
    3739  public sealed class BestVRPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {
     40
     41    [Storable] private ILookupParameter<IVRPProblemInstance> problemInstanceParameter;
     42    public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter => problemInstanceParameter;
     43    [Storable] private IScopeTreeLookupParameter<IVRPEncodedSolution> vrpToursParameter;
     44    public IScopeTreeLookupParameter<IVRPEncodedSolution> VRPToursParameter => vrpToursParameter;
    3845
    3946    [Storable] private IScopeTreeLookupParameter<VRPEvaluation> evaluationParameter;
     
    4350    public ILookupParameter<VRPSolution> BestSolutionParameter => bestSolutionParameter;
    4451
    45     [Storable] private IResultParameter<VRPEvaluation> bestEvaluationParameter;
    46     public IResultParameter<VRPEvaluation> BestSolutionEvaluationParameter => bestEvaluationParameter;
     52    [Storable] private ILookupParameter<VRPSolution> bestFeasibleSolutionParameter;
     53    public ILookupParameter<VRPSolution> BestFeasibleSolutionParameter => bestFeasibleSolutionParameter;
     54
     55    [Storable] private IResultParameter<VRPEvaluation> bestEvaluationResult;
     56    public IResultParameter<VRPEvaluation> BestSolutionEvaluationResult => bestEvaluationResult;
     57    [Storable] private IResultParameter<VRPEvaluation> bestFeasibleEvaluationResult;
     58    public IResultParameter<VRPEvaluation> BestFeasibleSolutionEvaluationResult => bestFeasibleEvaluationResult;
     59    [Storable] private IResultParameter<VRPSolution> bestSolutionResult;
     60    public IResultParameter<VRPSolution> BestSolutionResult => bestSolutionResult;
     61    [Storable] private IResultParameter<VRPSolution> bestFeasibleSolutionResult;
     62    public IResultParameter<VRPSolution> BestFeasibleSolutionResult => bestFeasibleSolutionResult;
    4763
    4864    public bool EnabledByDefault {
     
    5470    private BestVRPSolutionAnalyzer(BestVRPSolutionAnalyzer original, Cloner cloner)
    5571      : base(original, cloner) {
     72      problemInstanceParameter = cloner.Clone(original.problemInstanceParameter);
     73      vrpToursParameter = cloner.Clone(original.vrpToursParameter);
    5674      evaluationParameter = cloner.Clone(original.evaluationParameter);
    5775      bestSolutionParameter = cloner.Clone(original.bestSolutionParameter);
    58       bestEvaluationParameter = cloner.Clone(original.bestEvaluationParameter);
     76      bestFeasibleSolutionParameter = cloner.Clone(original.bestFeasibleSolutionParameter);
     77      bestEvaluationResult = cloner.Clone(original.bestEvaluationResult);
     78      bestFeasibleEvaluationResult = cloner.Clone(original.bestFeasibleEvaluationResult);
     79      bestSolutionResult = cloner.Clone(original.bestSolutionResult);
     80      bestFeasibleSolutionResult = cloner.Clone(original.bestFeasibleSolutionResult);
    5981    }
    6082    public BestVRPSolutionAnalyzer()
    6183      : base() {
     84      Parameters.Add(problemInstanceParameter = new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance."));
     85      Parameters.Add(vrpToursParameter = new ScopeTreeLookupParameter<IVRPEncodedSolution>("VRPTours", "The VRP encoded solution."));
    6286      Parameters.Add(evaluationParameter = new ScopeTreeLookupParameter<VRPEvaluation>("EvaluationResult", "The qualities of the VRP solutions which should be analyzed."));
    6387      Parameters.Add(bestSolutionParameter = new LookupParameter<VRPSolution>("BestSolution", "The best-so-far solution."));
    64       Parameters.Add(bestEvaluationParameter = new ResultParameter<VRPEvaluation>("Best VRP Evaluation", "The best VRP evaluation.", "Results"));
     88      Parameters.Add(bestFeasibleSolutionParameter = new LookupParameter<VRPSolution>("BestFeasibleSolution", "The best-so-far feasible solution."));
     89      Parameters.Add(bestEvaluationResult = new ResultParameter<VRPEvaluation>("Best VRP Solution Evaluation", "The best VRP evaluation.", "Results"));
     90      Parameters.Add(bestFeasibleEvaluationResult = new ResultParameter<VRPEvaluation>("Best Feasible VRP Solution Evaluation", "The best feasible VRP evaluation.", "Results"));
     91      Parameters.Add(bestSolutionResult = new ResultParameter<VRPSolution>("Best VRP Solution", "The best-so-far VRP solution."));
     92      Parameters.Add(bestFeasibleSolutionResult = new ResultParameter<VRPSolution>("Best feasible VRP Solution", "The best-so-far feasible VRP solution."));
    6593    }
    6694
     
    72100      var evaluations = EvaluationParameter.ActualValue;
    73101
    74       int i = evaluations.Select((x, index) => new { index, Eval = x }).OrderBy(x => x.Eval.Quality).First().index;
     102      var bestInPop = evaluations.Select((x, index) => new { index, Eval = x }).OrderBy(x => x.Eval.Quality).First();
     103      var bestFeasibleInPop = evaluations.Select((x, index) => new { index, Eval = x }).Where(x => x.Eval.IsFeasible).OrderBy(x => x.Eval.Quality).FirstOrDefault();
    75104
    76       var bestEvaluation = BestSolutionEvaluationParameter.ActualValue;
     105      var bestEvaluation = BestSolutionEvaluationResult.ActualValue;
    77106     
    78107      var bestSolution = BestSolutionParameter.ActualValue;
    79       if (bestSolution == null || evaluations[i].Quality <= bestSolution.Quality.Value) {
    80         BestSolutionEvaluationParameter.ActualValue = (VRPEvaluation)evaluations[i].Clone();
     108      if (bestSolution == null || bestInPop.Eval.Quality < bestSolution.Evaluation.Quality) {
     109        var best = new VRPSolution(ProblemInstanceParameter.ActualValue,
     110          VRPToursParameter.ActualValue[bestInPop.index], (VRPEvaluation)bestInPop.Eval.Clone());
     111        BestSolutionParameter.ActualValue = best;
     112        BestSolutionResult.ActualValue = best;
     113        BestSolutionEvaluationResult.ActualValue = (VRPEvaluation)bestInPop.Eval.Clone();
     114      };
     115
     116      if (bestFeasibleInPop != null) {
     117        var bestFeasibleSolution = BestFeasibleSolutionParameter.ActualValue;
     118        if (bestFeasibleSolution == null || bestFeasibleInPop.Eval.Quality < bestFeasibleSolution.Evaluation.Quality) {
     119          var bestFeasible = new VRPSolution(ProblemInstanceParameter.ActualValue,
     120          VRPToursParameter.ActualValue[bestFeasibleInPop.index], (VRPEvaluation)bestFeasibleInPop.Eval.Clone());
     121          BestFeasibleSolutionParameter.ActualValue = bestFeasible;
     122          bestFeasibleSolutionResult.ActualValue = bestFeasible;
     123          BestFeasibleSolutionEvaluationResult.ActualValue = (VRPEvaluation)bestFeasibleInPop.Eval.Clone();
     124        }
    81125      }
    82126
  • 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
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/ConstraintRelaxation/PickupAndDelivery/PickupViolationsRelaxationVRPAnalyzer.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<IntValue> PickupViolationsParameter {
    50       get { return (ScopeTreeLookupParameter<IntValue>)Parameters["PickupViolations"]; }
     46    public ScopeTreeLookupParameter<CVRPPDTWEvaluation> EvaluationParameter {
     47      get { return (ScopeTreeLookupParameter<CVRPPDTWEvaluation>)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<IntValue>("PickupViolations", "The pickup violation of the VRP solutions which should be analyzed."));
     78      Parameters.Add(new ScopeTreeLookupParameter<CVRPPDTWEvaluation>("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<IntValue> pickupViolations = PickupViolationsParameter.ActualValue;
     110      ItemArray<CVRPPDTWEvaluation> 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 -= pickupViolations[j].Value * pdp.PickupViolationPenalty.Value;
     117      for (int j = 0; j < evaluations.Length; j++) {
     118        evaluations[j].Quality -= evaluations[j].PickupViolations * pdp.PickupViolationPenalty.Value;
    125119      }
    126120
    127121      int validCount = 0;
    128       for (int j = 0; j < qualities.Length; j++) {
    129         if (pickupViolations[j].Value == 0)
     122      for (int j = 0; j < evaluations.Length; j++) {
     123        if (evaluations[j].PickupViolations == 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 = pdp.PickupViolationPenalty.Value / (1 + sigma);
     
    142136        pdp.CurrentPickupViolationPenalty.Value = maxPenalty;
    143137
    144       for (int j = 0; j < qualities.Length; j++) {
    145         qualities[j].Value += pickupViolations[j].Value * pdp.CurrentPickupViolationPenalty.Value;
     138      for (int j = 0; j < evaluations.Length; j++) {
     139        evaluations[j].Quality += evaluations[j].PickupViolations * pdp.CurrentPickupViolationPenalty.Value;
    146140      }
    147141
    148       if (!results.ContainsKey("Current Pickup Violation Penalty")) {
    149         results.Add(new Result("Current Pickup Violation Penalty", new DoubleValue(pdp.CurrentPickupViolationPenalty.Value)));
     142      if (!results.TryGetValue("Current Pickup Violation Penalty", out IResult res) || !(res.Value is DoubleValue)) {
     143        results.AddOrUpdateResult("Current Pickup Violation Penalty", new DoubleValue(pdp.CurrentPickupViolationPenalty.Value));
    150144      } else {
    151         (results["Current Pickup Violation Penalty"].Value as DoubleValue).Value = pdp.CurrentPickupViolationPenalty.Value;
     145        (res.Value as DoubleValue).Value = pdp.CurrentPickupViolationPenalty.Value;
    152146      }
    153147
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/ConstraintRelaxation/TimeWindowed/TimeWindowRelaxationVRPAnalyzer.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> TardinessParameter {
    50       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Tardiness"]; }
     46    public ScopeTreeLookupParameter<CVRPTWEvaluation> EvaluationParameter {
     47      get { return (ScopeTreeLookupParameter<CVRPTWEvaluation>)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>("Tardiness", "The tardiness of the VRP solutions which should be analyzed."));
     78      Parameters.Add(new ScopeTreeLookupParameter<CVRPTWEvaluation>("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> tardiness = TardinessParameter.ActualValue;
     110      ItemArray<CVRPTWEvaluation> 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 -= tardiness[j].Value * vrptw.TardinessPenalty.Value;
     117      for (int j = 0; j < evaluations.Length; j++) {
     118        evaluations[j].Quality -= evaluations[j].Tardiness * vrptw.TardinessPenalty.Value;
    125119      }
    126120
    127121      int validCount = 0;
    128       for (int j = 0; j < qualities.Length; j++) {
    129         if (tardiness[j].Value == 0)
     122      for (int j = 0; j < evaluations.Length; j++) {
     123        if (evaluations[j].Tardiness == 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 = vrptw.TardinessPenalty.Value / (1 + sigma);
     
    142136        vrptw.CurrentTardinessPenalty.Value = maxPenalty;
    143137
    144       for (int j = 0; j < qualities.Length; j++) {
    145         qualities[j].Value += tardiness[j].Value * vrptw.CurrentTardinessPenalty.Value;
     138      for (int j = 0; j < evaluations.Length; j++) {
     139        evaluations[j].Quality += evaluations[j].Tardiness * vrptw.CurrentTardinessPenalty.Value;
    146140      }
    147141
    148       if (!results.ContainsKey("Current Tardiness Penalty")) {
    149         results.Add(new Result("Current Tardiness Penalty", new DoubleValue(vrptw.CurrentTardinessPenalty.Value)));
     142      if (!results.TryGetValue("Current Tardiness Penalty", out IResult res) || !(res.Value is DoubleValue)) {
     143        results.AddOrUpdateResult("Current Tardiness Penalty", new DoubleValue(vrptw.CurrentTardinessPenalty.Value));
    150144      } else {
    151         (results["Current Tardiness Penalty"].Value as DoubleValue).Value = vrptw.CurrentTardinessPenalty.Value;
     145        (res.Value as DoubleValue).Value = vrptw.CurrentTardinessPenalty.Value;
    152146      }
    153147
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/VRPSolution.cs

    r17698 r17710  
    2222using System;
    2323using System.Drawing;
     24using HEAL.Attic;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    27 using HEAL.Attic;
    2827using HeuristicLab.Problems.VehicleRouting.Interfaces;
     28using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    2929
    3030namespace HeuristicLab.Problems.VehicleRouting {
     
    6666    }
    6767    [Storable]
    68     private DoubleValue quality;
    69     public DoubleValue Quality {
    70       get { return quality; }
     68    private VRPEvaluation evaluation;
     69    public VRPEvaluation Evaluation {
     70      get { return evaluation; }
    7171      set {
    72         if (quality != value) {
    73           if (quality != null) DeregisterQualityEvents();
    74           quality = value;
    75           if (quality != null) RegisterQualityEvents();
    76           OnQualityChanged();
     72        if (evaluation != value) {
     73          //if (evaluation != null) DeregisterQualityEvents();
     74          evaluation = value;
     75          //if (evaluation != null) RegisterQualityEvents();
     76          OnEvaluationChanged();
    7777        }
    7878      }
     
    8181    public VRPSolution() : base() { }
    8282
    83     public VRPSolution(IVRPProblemInstance problemInstance, IVRPEncodedSolution solution, DoubleValue quality)
     83    public VRPSolution(IVRPProblemInstance problemInstance, IVRPEncodedSolution solution, VRPEvaluation evaluation)
    8484      : base() {
    8585      this.problemInstance = problemInstance;
    8686      this.solution = solution;
    87       this.quality = quality;
     87      this.evaluation = evaluation;
    8888
    8989      Initialize();
     
    9696      if (problemInstance != null) RegisterProblemInstanceEvents();
    9797      if (solution != null) RegisterSolutionEvents();
    98       if (quality != null) RegisterQualityEvents();
     98      // TODO if (evaluation != null) RegisterQualityEvents();
    9999    }
    100100
     
    106106    private VRPSolution(VRPSolution original, Cloner cloner)
    107107      : base(original, cloner) {
    108       this.solution = (IVRPEncodedSolution)cloner.Clone(original.solution);
    109       this.quality = (DoubleValue)cloner.Clone(original.quality);
     108      this.solution = cloner.Clone(original.solution);
     109      this.evaluation = cloner.Clone(original.evaluation);
    110110
     111      // TODO: this seems very strange
    111112      if (original.ProblemInstance != null && cloner.ClonedObjectRegistered(original.ProblemInstance))
    112         this.ProblemInstance = (IVRPProblemInstance)cloner.Clone(original.ProblemInstance);
     113        this.ProblemInstance = cloner.Clone(original.ProblemInstance);
    113114      else
    114115        this.ProblemInstance = original.ProblemInstance;
     
    130131        changed(this, EventArgs.Empty);
    131132    }
    132     public event EventHandler QualityChanged;
    133     private void OnQualityChanged() {
    134       var changed = QualityChanged;
     133    public event EventHandler EvaluationChanged;
     134    private void OnEvaluationChanged() {
     135      var changed = EvaluationChanged;
    135136      if (changed != null)
    136137        changed(this, EventArgs.Empty);
     
    149150      Solution.ToStringChanged -= new EventHandler(Solution_ToStringChanged);
    150151    }
    151     private void RegisterQualityEvents() {
    152       Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
    153     }
    154     private void DeregisterQualityEvents() {
    155       Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
    156     }
     152    //private void RegisterQualityEvents() {
     153    //  Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
     154    //}
     155    //private void DeregisterQualityEvents() {
     156    //  Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
     157    //}
    157158
    158159    private void ProblemInstance_ToStringChanged(object sender, EventArgs e) {
     
    162163      OnSolutionChanged();
    163164    }
    164     private void Quality_ValueChanged(object sender, EventArgs e) {
    165       OnQualityChanged();
    166     }
     165    //private void Quality_ValueChanged(object sender, EventArgs e) {
     166    //  OnQualityChanged();
     167    //}
    167168    #endregion
    168169  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r17709 r17710  
    9696    }
    9797
     98    public override void Evaluate(ISingleObjectiveSolutionContext<IVRPEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) {
     99      solutionContext.EvaluationResult = ProblemInstance.Evaluate(solutionContext.EncodedSolution);
     100    }
    98101    public override ISingleObjectiveEvaluationResult Evaluate(IVRPEncodedSolution solution, IRandom random, CancellationToken cancellationToken) {
    99102      return ProblemInstance.Evaluate(solution);
     103    }
     104
     105    public override void Analyze(ISingleObjectiveSolutionContext<IVRPEncodedSolution>[] solutionContexts, ResultCollection results, IRandom random) {
     106      base.Analyze(solutionContexts, results, random);
     107      var evaluations = solutionContexts.Select(x => (VRPEvaluation)x.EvaluationResult);
     108
     109      var bestInPop = evaluations.Select((x, index) => new { index, Eval = x }).OrderBy(x => x.Eval.Quality).First();
     110      IResult bestSolutionResult;
     111      if (!results.TryGetValue("Best VRP Solution", out bestSolutionResult) || !(bestSolutionResult.Value is VRPSolution)) {
     112        var best = new VRPSolution(ProblemInstance, solutionContexts[bestInPop.index].EncodedSolution, (VRPEvaluation)bestInPop.Eval.Clone());
     113        if (bestSolutionResult != null)
     114          bestSolutionResult.Value = best;
     115        else results.Add(bestSolutionResult = new Result("Best VRP Solution", best));
     116      }
     117
     118      var bestSolution = (VRPSolution)bestSolutionResult.Value;
     119      if (bestSolution == null || bestInPop.Eval.Quality < bestSolution.Evaluation.Quality) {
     120        var best = new VRPSolution(ProblemInstance,
     121          (IVRPEncodedSolution)solutionContexts[bestInPop.index].EncodedSolution.Clone(),
     122          (VRPEvaluation)bestInPop.Eval.Clone());
     123        bestSolutionResult.Value = best;
     124      };
     125
     126      var bestValidInPop = evaluations.Select((x, index) => new { index, Eval = x }).Where(x => x.Eval.IsFeasible).OrderBy(x => x.Eval.Quality).FirstOrDefault();
     127      IResult bestValidSolutionResult;
     128      if (!results.TryGetValue("Best Valid VRP Solution", out bestValidSolutionResult) || !(bestValidSolutionResult.Value is VRPSolution)) {
     129        var bestValid = new VRPSolution(ProblemInstance, solutionContexts[bestValidInPop.index].EncodedSolution, (VRPEvaluation)bestValidInPop.Eval.Clone());
     130        if (bestValidSolutionResult != null)
     131          bestValidSolutionResult.Value = bestValid;
     132        else results.Add(bestValidSolutionResult = new Result("Best Valid VRP Solution", bestValid));
     133      }
     134
     135      if (bestValidInPop != null) {
     136        var bestValidSolution = (VRPSolution)bestValidSolutionResult.Value;
     137        if (bestValidSolution == null || bestValidInPop.Eval.Quality < bestValidSolution.Evaluation.Quality) {
     138          var best = new VRPSolution(ProblemInstance,
     139            (IVRPEncodedSolution)solutionContexts[bestValidInPop.index].EncodedSolution.Clone(),
     140            (VRPEvaluation)bestValidInPop.Eval.Clone());
     141          bestValidSolutionResult.Value = best;
     142        };
     143      }
    100144    }
    101145
     
    127171      try {
    128172        //call evaluator
    129         BestKnownQuality = ProblemInstance.Evaluate(BestKnownSolution.Solution).Quality;
    130         BestKnownSolution.Quality = new DoubleValue(BestKnownQuality);
     173        var evaluation = ProblemInstance.Evaluate(BestKnownSolution.Solution);
     174        BestKnownQuality = evaluation.Quality;
     175        BestKnownSolution.Evaluation = evaluation;
    131176      } catch {
    132177        BestKnownQuality = double.NaN;
     
    169214      Operators.Add(new QualitySimilarityCalculator());
    170215      Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    171       Operators.AddRange(ProblemInstance.Operators.OfType<IAnalyzer>());
     216      //Operators.AddRange(ProblemInstance.Operators.OfType<IAnalyzer>());
    172217    }
    173218
     
    241286        ErrorHandling.ShowErrorDialog(new Exception("The optimal solution does not seem to correspond with the problem data"));
    242287      else {
    243         VRPSolution solution = new VRPSolution(ProblemInstance, encoding, new DoubleValue(0));
     288        VRPSolution solution = new VRPSolution(ProblemInstance, encoding, ProblemInstance.Evaluate(encoding));
    244289        BestKnownSolutionParameter.Value = solution;
    245290      }
     
    269314
    270315      if (instance.BestKnownSolution != null) {
    271         VRPSolution solution = new VRPSolution(ProblemInstance, instance.BestKnownSolution, new DoubleValue(0));
     316        VRPSolution solution = new VRPSolution(ProblemInstance, instance.BestKnownSolution, ProblemInstance.Evaluate(instance.BestKnownSolution));
    272317        BestKnownSolution = solution;
    273318      }
Note: See TracChangeset for help on using the changeset viewer.