Changeset 17710
- Timestamp:
- 08/03/20 15:50:59 (3 years ago)
- 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 335 335 <DependentUpon>VRPEvaluationView.cs</DependentUpon> 336 336 </EmbeddedResource> 337 <EmbeddedResource Include="VRPSolutionView.resx"> 338 <DependentUpon>VRPSolutionView.cs</DependentUpon> 339 </EmbeddedResource> 337 340 </ItemGroup> 338 341 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.Designer.cs
r17226 r17710 46 46 private void InitializeComponent() { 47 47 this.tabControl1 = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl(); 48 this.tabPage1 = new System.Windows.Forms.TabPage();49 this.problemInstanceView = new HeuristicLab.MainForm.WindowsForms.ViewHost();50 48 this.tabPage2 = new System.Windows.Forms.TabPage(); 51 49 this.tourGroupBox = new System.Windows.Forms.GroupBox(); 52 50 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(); 53 55 this.tabControl1.SuspendLayout(); 54 this.tabPage1.SuspendLayout();55 56 this.tabPage2.SuspendLayout(); 56 57 this.tourGroupBox.SuspendLayout(); 58 this.tabPage3.SuspendLayout(); 59 this.tabPage1.SuspendLayout(); 57 60 this.SuspendLayout(); 58 61 // 59 62 // tabControl1 60 63 // 64 this.tabControl1.AllowDrop = true; 61 65 this.tabControl1.Controls.Add(this.tabPage1); 62 66 this.tabControl1.Controls.Add(this.tabPage2); 67 this.tabControl1.Controls.Add(this.tabPage3); 63 68 this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; 64 69 this.tabControl1.Location = new System.Drawing.Point(0, 0); … … 67 72 this.tabControl1.Size = new System.Drawing.Size(468, 415); 68 73 this.tabControl1.TabIndex = 0; 69 //70 // tabPage171 //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 // problemInstanceView82 //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;92 74 // 93 75 // tabPage2 … … 119 101 this.valueTextBox.Multiline = true; 120 102 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); 122 105 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; 124 156 // 125 157 // VRPSolutionView 126 158 // 127 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);128 159 this.Controls.Add(this.tabControl1); 129 160 this.Name = "VRPSolutionView"; 130 161 this.Size = new System.Drawing.Size(468, 415); 131 162 this.tabControl1.ResumeLayout(false); 132 this.tabPage1.ResumeLayout(false);133 163 this.tabPage2.ResumeLayout(false); 134 164 this.tourGroupBox.ResumeLayout(false); 165 this.tourGroupBox.PerformLayout(); 166 this.tabPage3.ResumeLayout(false); 167 this.tabPage1.ResumeLayout(false); 135 168 this.ResumeLayout(false); 136 169 … … 140 173 141 174 private HeuristicLab.MainForm.WindowsForms.DragOverTabControl tabControl1; 142 private System.Windows.Forms.TabPage tabPage1;143 private MainForm.WindowsForms.ViewHost problemInstanceView;144 175 private System.Windows.Forms.TabPage tabPage2; 145 176 private System.Windows.Forms.GroupBox tourGroupBox; 146 177 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; 147 182 } 148 183 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting.Views/3.4/VRPSolutionView.cs
r17226 r17710 58 58 59 59 UpdateTourView(); 60 61 evaluationViewHost.Content = Content.Evaluation; 60 62 } 61 63 … … 64 66 if (Content == null) { 65 67 problemInstanceView.Content = null; 68 evaluationViewHost.Content = null; 69 valueTextBox.Text = string.Empty; 66 70 } else { 67 71 UpdateContent(); -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs
r17709 r17710 27 27 using HeuristicLab.Optimization; 28 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 29 30 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 31 … … 33 34 /// An operator for analyzing the best solution of Vehicle Routing Problems. 34 35 /// </summary> 36 //TODO: remove this operator -> part of VRP problem analyze 35 37 [Item("BestVRPSolutionAnalyzer", "An operator for analyzing the best solution of Vehicle Routing Problems.")] 36 38 [StorableType("3e1bb409-0b8f-4324-826c-2190aa5fb2b6")] 37 39 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; 38 45 39 46 [Storable] private IScopeTreeLookupParameter<VRPEvaluation> evaluationParameter; … … 43 50 public ILookupParameter<VRPSolution> BestSolutionParameter => bestSolutionParameter; 44 51 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; 47 63 48 64 public bool EnabledByDefault { … … 54 70 private BestVRPSolutionAnalyzer(BestVRPSolutionAnalyzer original, Cloner cloner) 55 71 : base(original, cloner) { 72 problemInstanceParameter = cloner.Clone(original.problemInstanceParameter); 73 vrpToursParameter = cloner.Clone(original.vrpToursParameter); 56 74 evaluationParameter = cloner.Clone(original.evaluationParameter); 57 75 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); 59 81 } 60 82 public BestVRPSolutionAnalyzer() 61 83 : 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.")); 62 86 Parameters.Add(evaluationParameter = new ScopeTreeLookupParameter<VRPEvaluation>("EvaluationResult", "The qualities of the VRP solutions which should be analyzed.")); 63 87 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.")); 65 93 } 66 94 … … 72 100 var evaluations = EvaluationParameter.ActualValue; 73 101 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(); 75 104 76 var bestEvaluation = BestSolutionEvaluation Parameter.ActualValue;105 var bestEvaluation = BestSolutionEvaluationResult.ActualValue; 77 106 78 107 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 } 81 125 } 82 126 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/ConstraintRelaxation/Capacitated/CapacityRelaxationVRPAnalyzer.cs
r17698 r17710 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 30 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 31 using HeuristicLab.Problems.VehicleRouting.Variants; 31 32 … … 43 44 get { return (ScopeTreeLookupParameter<IVRPEncodedSolution>)Parameters["VRPTours"]; } 44 45 } 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"]; } 51 48 } 52 49 … … 79 76 Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance.")); 80 77 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.")); 84 79 85 80 Parameters.Add(new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.5))); … … 113 108 ResultCollection results = ResultsParameter.ActualValue; 114 109 115 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 116 ItemArray<DoubleValue> overloads = OverloadParameter.ActualValue; 110 ItemArray<CVRPEvaluation> evaluations = EvaluationParameter.ActualValue; 117 111 118 112 double sigma = SigmaParameter.Value.Value; … … 121 115 double maxPenalty = MaxPenaltyFactorParameter.Value.Value; 122 116 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; 125 119 } 126 120 127 121 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) 130 124 validCount++; 131 125 } 132 126 133 double factor = 1.0 - ((double)validCount / (double) qualities.Length);127 double factor = 1.0 - ((double)validCount / (double)evaluations.Length); 134 128 135 129 double min = cvrp.OverloadPenalty.Value / (1 + sigma); … … 142 136 cvrp.CurrentOverloadPenalty.Value = maxPenalty; 143 137 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; 146 140 } 147 141 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)); 150 144 } else { 151 (res ults["Current Overload Penalty"].Value as DoubleValue).Value = cvrp.CurrentOverloadPenalty.Value;145 (res.Value as DoubleValue).Value = cvrp.CurrentOverloadPenalty.Value; 152 146 } 153 147 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/ConstraintRelaxation/PickupAndDelivery/PickupViolationsRelaxationVRPAnalyzer.cs
r17698 r17710 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 30 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 31 using HeuristicLab.Problems.VehicleRouting.Variants; 31 32 … … 43 44 get { return (ScopeTreeLookupParameter<IVRPEncodedSolution>)Parameters["VRPTours"]; } 44 45 } 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"]; } 51 48 } 52 49 … … 79 76 Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance.")); 80 77 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.")); 84 79 85 80 Parameters.Add(new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.5))); … … 113 108 ResultCollection results = ResultsParameter.ActualValue; 114 109 115 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 116 ItemArray<IntValue> pickupViolations = PickupViolationsParameter.ActualValue; 110 ItemArray<CVRPPDTWEvaluation> evaluations = EvaluationParameter.ActualValue; 117 111 118 112 double sigma = SigmaParameter.Value.Value; … … 121 115 double maxPenalty = MaxPenaltyFactorParameter.Value.Value; 122 116 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; 125 119 } 126 120 127 121 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) 130 124 validCount++; 131 125 } 132 126 133 double factor = 1.0 - ((double)validCount / (double) qualities.Length);127 double factor = 1.0 - ((double)validCount / (double)evaluations.Length); 134 128 135 129 double min = pdp.PickupViolationPenalty.Value / (1 + sigma); … … 142 136 pdp.CurrentPickupViolationPenalty.Value = maxPenalty; 143 137 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; 146 140 } 147 141 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)); 150 144 } else { 151 (res ults["Current Pickup Violation Penalty"].Value as DoubleValue).Value = pdp.CurrentPickupViolationPenalty.Value;145 (res.Value as DoubleValue).Value = pdp.CurrentPickupViolationPenalty.Value; 152 146 } 153 147 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/ConstraintRelaxation/TimeWindowed/TimeWindowRelaxationVRPAnalyzer.cs
r17698 r17710 20 20 #endregion 21 21 22 using HEAL.Attic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Parameters; 28 using HEAL.Attic;29 29 using HeuristicLab.Problems.VehicleRouting.Interfaces; 30 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 30 31 using HeuristicLab.Problems.VehicleRouting.Variants; 31 32 … … 43 44 get { return (ScopeTreeLookupParameter<IVRPEncodedSolution>)Parameters["VRPTours"]; } 44 45 } 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"]; } 51 48 } 52 49 … … 79 76 Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance.")); 80 77 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.")); 84 79 85 80 Parameters.Add(new ValueParameter<DoubleValue>("Sigma", "The sigma applied to the penalty factor.", new DoubleValue(0.5))); … … 113 108 ResultCollection results = ResultsParameter.ActualValue; 114 109 115 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 116 ItemArray<DoubleValue> tardiness = TardinessParameter.ActualValue; 110 ItemArray<CVRPTWEvaluation> evaluations = EvaluationParameter.ActualValue; 117 111 118 112 double sigma = SigmaParameter.Value.Value; … … 121 115 double maxPenalty = MaxPenaltyFactorParameter.Value.Value; 122 116 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; 125 119 } 126 120 127 121 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) 130 124 validCount++; 131 125 } 132 126 133 double factor = 1.0 - ((double)validCount / (double) qualities.Length);127 double factor = 1.0 - ((double)validCount / (double)evaluations.Length); 134 128 135 129 double min = vrptw.TardinessPenalty.Value / (1 + sigma); … … 142 136 vrptw.CurrentTardinessPenalty.Value = maxPenalty; 143 137 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; 146 140 } 147 141 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)); 150 144 } else { 151 (res ults["Current Tardiness Penalty"].Value as DoubleValue).Value = vrptw.CurrentTardinessPenalty.Value;145 (res.Value as DoubleValue).Value = vrptw.CurrentTardinessPenalty.Value; 152 146 } 153 147 -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/VRPSolution.cs
r17698 r17710 22 22 using System; 23 23 using System.Drawing; 24 using HEAL.Attic; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 using HEAL.Attic;28 27 using HeuristicLab.Problems.VehicleRouting.Interfaces; 28 using HeuristicLab.Problems.VehicleRouting.ProblemInstances; 29 29 30 30 namespace HeuristicLab.Problems.VehicleRouting { … … 66 66 } 67 67 [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; } 71 71 set { 72 if ( quality!= value) {73 if (quality!= null) DeregisterQualityEvents();74 quality= value;75 if (quality!= null) RegisterQualityEvents();76 On QualityChanged();72 if (evaluation != value) { 73 //if (evaluation != null) DeregisterQualityEvents(); 74 evaluation = value; 75 //if (evaluation != null) RegisterQualityEvents(); 76 OnEvaluationChanged(); 77 77 } 78 78 } … … 81 81 public VRPSolution() : base() { } 82 82 83 public VRPSolution(IVRPProblemInstance problemInstance, IVRPEncodedSolution solution, DoubleValue quality)83 public VRPSolution(IVRPProblemInstance problemInstance, IVRPEncodedSolution solution, VRPEvaluation evaluation) 84 84 : base() { 85 85 this.problemInstance = problemInstance; 86 86 this.solution = solution; 87 this. quality = quality;87 this.evaluation = evaluation; 88 88 89 89 Initialize(); … … 96 96 if (problemInstance != null) RegisterProblemInstanceEvents(); 97 97 if (solution != null) RegisterSolutionEvents(); 98 if (quality!= null) RegisterQualityEvents();98 // TODO if (evaluation != null) RegisterQualityEvents(); 99 99 } 100 100 … … 106 106 private VRPSolution(VRPSolution original, Cloner cloner) 107 107 : 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); 110 110 111 // TODO: this seems very strange 111 112 if (original.ProblemInstance != null && cloner.ClonedObjectRegistered(original.ProblemInstance)) 112 this.ProblemInstance = (IVRPProblemInstance)cloner.Clone(original.ProblemInstance);113 this.ProblemInstance = cloner.Clone(original.ProblemInstance); 113 114 else 114 115 this.ProblemInstance = original.ProblemInstance; … … 130 131 changed(this, EventArgs.Empty); 131 132 } 132 public event EventHandler QualityChanged;133 private void On QualityChanged() {134 var changed = QualityChanged;133 public event EventHandler EvaluationChanged; 134 private void OnEvaluationChanged() { 135 var changed = EvaluationChanged; 135 136 if (changed != null) 136 137 changed(this, EventArgs.Empty); … … 149 150 Solution.ToStringChanged -= new EventHandler(Solution_ToStringChanged); 150 151 } 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 //} 157 158 158 159 private void ProblemInstance_ToStringChanged(object sender, EventArgs e) { … … 162 163 OnSolutionChanged(); 163 164 } 164 private void Quality_ValueChanged(object sender, EventArgs e) {165 OnQualityChanged();166 }165 //private void Quality_ValueChanged(object sender, EventArgs e) { 166 // OnQualityChanged(); 167 //} 167 168 #endregion 168 169 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r17709 r17710 96 96 } 97 97 98 public override void Evaluate(ISingleObjectiveSolutionContext<IVRPEncodedSolution> solutionContext, IRandom random, CancellationToken cancellationToken) { 99 solutionContext.EvaluationResult = ProblemInstance.Evaluate(solutionContext.EncodedSolution); 100 } 98 101 public override ISingleObjectiveEvaluationResult Evaluate(IVRPEncodedSolution solution, IRandom random, CancellationToken cancellationToken) { 99 102 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 } 100 144 } 101 145 … … 127 171 try { 128 172 //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; 131 176 } catch { 132 177 BestKnownQuality = double.NaN; … … 169 214 Operators.Add(new QualitySimilarityCalculator()); 170 215 Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 171 Operators.AddRange(ProblemInstance.Operators.OfType<IAnalyzer>());216 //Operators.AddRange(ProblemInstance.Operators.OfType<IAnalyzer>()); 172 217 } 173 218 … … 241 286 ErrorHandling.ShowErrorDialog(new Exception("The optimal solution does not seem to correspond with the problem data")); 242 287 else { 243 VRPSolution solution = new VRPSolution(ProblemInstance, encoding, new DoubleValue(0));288 VRPSolution solution = new VRPSolution(ProblemInstance, encoding, ProblemInstance.Evaluate(encoding)); 244 289 BestKnownSolutionParameter.Value = solution; 245 290 } … … 269 314 270 315 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)); 272 317 BestKnownSolution = solution; 273 318 }
Note: See TracChangeset
for help on using the changeset viewer.