Changeset 4860 for branches/VRP/HeuristicLab.Problems.VehicleRouting
- Timestamp:
- 11/19/10 15:43:21 (14 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Analyzer/BestSolution/BestVRPSolutionAnalyzer.cs
r4752 r4860 62 62 } 63 63 64 public LookupParameter<DoubleValue> BestKnownQualityParameter { 65 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 66 } 67 public LookupParameter<VRPSolution> BestKnownSolutionParameter { 68 get { return (LookupParameter<VRPSolution>)Parameters["BestKnownSolution"]; } 69 } 70 64 71 [StorableConstructor] 65 72 private BestVRPSolutionAnalyzer(bool deserializing) : base(deserializing) { } … … 69 76 Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The problem instance.")); 70 77 Parameters.Add(new ScopeTreeLookupParameter<IVRPEncoding>("VRPTours", "The VRP tours which should be evaluated.")); 78 79 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance.")); 80 Parameters.Add(new LookupParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance.")); 71 81 72 82 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the VRP solutions which should be analyzed.")); … … 86 96 } 87 97 98 [StorableHook(HookType.AfterDeserialization)] 99 private void AfterDeserializationHook() { 100 #region Backwards Compatibility 101 if (!Parameters.ContainsKey("BestKnownQuality")) { 102 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance.")); 103 } 104 if (!Parameters.ContainsKey("BestKnownSolution")) { 105 Parameters.Add(new LookupParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance.")); 106 } 107 #endregion 108 } 109 88 110 public override IOperation Apply() { 89 111 IVRPProblemInstance problemInstance = ProblemInstanceParameter.ActualValue; … … 96 118 97 119 int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 120 121 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 98 122 99 123 IVRPEncoding best = solutions[i].Clone() as IVRPEncoding; … … 116 140 } 117 141 142 if (bestKnownQuality == null || 143 qualities[i].Value < bestKnownQuality.Value) { 144 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value); 145 BestKnownSolutionParameter.ActualValue = (VRPSolution)solution.Clone(); 146 } 147 118 148 return base.Apply(); 119 149 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/HeuristicLab.Problems.VehicleRouting-3.4.csproj
r4383 r4860 227 227 <Compile Include="Interfaces\IVRPEncoding.cs" /> 228 228 <Compile Include="Interfaces\IVRPProblemInstance.cs" /> 229 <Compile Include="SolutionParser.cs" /> 229 230 <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedProblemInstance.cs" /> 230 231 <Compile Include="Variants\Capacitated\Heterogenous\IHeterogenousCapacitatedOperator.cs" /> -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs
r4363 r4860 32 32 IValueParameter<IVRPEvaluator> EvaluatorParameter { get; } 33 33 IValueParameter<IVRPCreator> SolutionCreatorParameter { get; } 34 IValueParameter<DoubleValue> BestKnownQualityParameter { get; } 35 IValueParameter<VRPSolution> BestKnownSolutionParameter { get; } 34 36 IEnumerable<IOperator> Operators { get; } 35 37 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPProblemInstance.cs
r4752 r4860 77 77 Parameters.Add(new ValueParameter<DoubleValue>("Capacity", "The capacity of each vehicle.", new DoubleValue(0))); 78 78 Parameters.Add(new ValueParameter<DoubleValue>("EvalOverloadPenalty", "The overload penalty considered in the evaluation.", new DoubleValue(100))); 79 80 AttachEventHandlers(); 79 81 } 80 82 … … 85 87 protected CVRPProblemInstance(CVRPProblemInstance original, Cloner cloner) 86 88 : base(original, cloner) { 89 AttachEventHandlers(); 87 90 } 91 92 [StorableHook(HookType.AfterDeserialization)] 93 private void AfterDeserializationHook() { 94 AttachEventHandlers(); 95 } 96 97 private void AttachEventHandlers() { 98 CapacityParameter.ValueChanged += new EventHandler(CapacityParameter_ValueChanged); 99 CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged); 100 OverloadPenaltyParameter.ValueChanged += new EventHandler(OverloadPenaltyParameter_ValueChanged); 101 OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged); 102 } 103 104 #region Event handlers 105 void CapacityParameter_ValueChanged(object sender, EventArgs e) { 106 CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged); 107 BestKnownSolution = null; 108 } 109 void Capacity_ValueChanged(object sender, EventArgs e) { 110 BestKnownSolution = null; 111 } 112 void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) { 113 OverloadPenaltyParameter.Value.ValueChanged += new EventHandler(OverloadPenalty_ValueChanged); 114 EvalBestKnownSolution(); 115 } 116 void OverloadPenalty_ValueChanged(object sender, EventArgs e) { 117 EvalBestKnownSolution(); 118 } 119 #endregion 88 120 } 89 121 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWProblemInstance.cs
r4752 r4860 103 103 Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0))); 104 104 Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100))); 105 106 AttachEventHandlers(); 105 107 } 106 108 … … 111 113 protected CVRPTWProblemInstance(CVRPTWProblemInstance original, Cloner cloner) 112 114 : base(original, cloner) { 115 AttachEventHandlers(); 113 116 } 117 118 [StorableHook(HookType.AfterDeserialization)] 119 private void AfterDeserializationHook() { 120 AttachEventHandlers(); 121 } 122 123 private void AttachEventHandlers() { 124 TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged); 125 TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged); 126 TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged); 127 TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged); 128 } 129 130 #region Event handlers 131 void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) { 132 TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged); 133 EvalBestKnownSolution(); 134 } 135 void TardinessPenalty_ValueChanged(object sender, EventArgs e) { 136 EvalBestKnownSolution(); 137 } 138 void TimeFactorParameter_ValueChanged(object sender, EventArgs e) { 139 TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged); 140 EvalBestKnownSolution(); 141 } 142 void TimeFactor_ValueChanged(object sender, EventArgs e) { 143 EvalBestKnownSolution(); 144 } 145 #endregion 114 146 } 115 147 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r4752 r4860 77 77 } 78 78 79 protected OptionalValueParameter<DoubleValue> BestKnownQualityParameter { 80 get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 81 } 82 protected OptionalValueParameter<VRPSolution> BestKnownSolutionParameter { 83 get { return (OptionalValueParameter<VRPSolution>)Parameters["BestKnownSolution"]; } 84 } 85 86 IValueParameter<DoubleValue> IVRPProblemInstance.BestKnownQualityParameter { 87 get { return BestKnownQualityParameter; } 88 } 89 90 IValueParameter<VRPSolution> IVRPProblemInstance.BestKnownSolutionParameter { 91 get { return BestKnownSolutionParameter; } 92 } 93 79 94 public DoubleMatrix Coordinates { 80 95 get { return CoordinatesParameter.Value; } … … 109 124 get { return DistanceFactorParameter.Value; } 110 125 set { DistanceFactorParameter.Value = value; } 126 } 127 128 public DoubleValue BestKnownQuality { 129 get { return BestKnownQualityParameter.Value; } 130 set { BestKnownQualityParameter.Value = value; } 131 } 132 public VRPSolution BestKnownSolution { 133 get { return BestKnownSolutionParameter.Value; } 134 set { BestKnownSolutionParameter.Value = value; } 111 135 } 112 136 … … 171 195 public double Evaluate(Tour tour) { 172 196 return EvaluatorParameter.Value.Evaluate(this, tour).Quality; 197 } 198 199 protected void EvalBestKnownSolution() { 200 if (BestKnownSolution != null) { 201 //call evaluator 202 BestKnownQuality = new DoubleValue(Evaluate(BestKnownSolution.Solution)); 203 BestKnownSolution.Quality = BestKnownQuality; 204 } else { 205 BestKnownQuality = null; 206 } 173 207 } 174 208 … … 192 226 Parameters.Add(new ValueParameter<IVRPCreator>("SolutionCreator", "The operator which should be used to create new VRP solutions.", Creator)); 193 227 Parameters.Add(new ValueParameter<IVRPEvaluator>("Evaluator", "The operator which should be used to evaluate VRP solutions.", Evaluator)); 228 229 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance.")); 230 Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance.")); 231 232 AttachEventHandlers(); 194 233 } 195 234 196 235 protected VRPProblemInstance(VRPProblemInstance original, Cloner cloner) 197 236 : base(original, cloner) { 198 } 237 AttachEventHandlers(); 238 } 239 240 [StorableHook(HookType.AfterDeserialization)] 241 private void AfterDeserializationHook() { 242 #region Backwards Compatibility 243 if (!Parameters.ContainsKey("BestKnownSolution")) { 244 Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this TSP instance.")); 245 } 246 #endregion 247 248 AttachEventHandlers(); 249 } 250 251 private void AttachEventHandlers() { 252 BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged); 253 DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactorParameter_ValueChanged); 254 DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged); 255 FleetUsageFactorParameter.ValueChanged += new EventHandler(FleetUsageFactorParameter_ValueChanged); 256 FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged); 257 DistanceMatrixParameter.ValueChanged += new EventHandler(DistanceMatrixParameter_ValueChanged); 258 if (DistanceMatrix != null) { 259 DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged); 260 DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset); 261 } 262 UseDistanceMatrixParameter.ValueChanged += new EventHandler(UseDistanceMatrixParameter_ValueChanged); 263 UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged); 264 } 265 266 #region Event handlers 267 void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) { 268 EvalBestKnownSolution(); 269 } 270 void DistanceFactorParameter_ValueChanged(object sender, EventArgs e) { 271 DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged); 272 EvalBestKnownSolution(); 273 } 274 void DistanceFactor_ValueChanged(object sender, EventArgs e) { 275 EvalBestKnownSolution(); 276 } 277 void FleetUsageFactorParameter_ValueChanged(object sender, EventArgs e) { 278 FleetUsageFactorParameter.Value.ValueChanged += new EventHandler(FleetUsageFactor_ValueChanged); 279 EvalBestKnownSolution(); 280 } 281 void FleetUsageFactor_ValueChanged(object sender, EventArgs e) { 282 EvalBestKnownSolution(); 283 } 284 void DistanceMatrixParameter_ValueChanged(object sender, EventArgs e) { 285 if (DistanceMatrix != null) { 286 DistanceMatrix.ItemChanged += new EventHandler<EventArgs<int, int>>(DistanceMatrix_ItemChanged); 287 DistanceMatrix.Reset += new EventHandler(DistanceMatrix_Reset); 288 } 289 EvalBestKnownSolution(); 290 } 291 void DistanceMatrix_Reset(object sender, EventArgs e) { 292 EvalBestKnownSolution(); 293 } 294 void DistanceMatrix_ItemChanged(object sender, EventArgs<int, int> e) { 295 EvalBestKnownSolution(); 296 } 297 void UseDistanceMatrixParameter_ValueChanged(object sender, EventArgs e) { 298 UseDistanceMatrix.ValueChanged += new EventHandler(UseDistanceMatrix_ValueChanged); 299 EvalBestKnownSolution(); 300 } 301 void UseDistanceMatrix_ValueChanged(object sender, EventArgs e) { 302 EvalBestKnownSolution(); 303 } 304 #endregion 199 305 } 200 306 } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r4752 r4860 64 64 get { return BestKnownQualityParameter; } 65 65 } 66 public OptionalValueParameter<VRPSolution> BestKnownSolutionParameter { 67 get { return (OptionalValueParameter<VRPSolution>)Parameters["BestKnownSolution"]; } 68 } 66 69 public IValueParameter<IVRPCreator> SolutionCreatorParameter { 67 70 get { return (IValueParameter<IVRPCreator>)Parameters["SolutionCreator"]; } … … 82 85 get { return ProblemInstanceParameter.Value; } 83 86 set { ProblemInstanceParameter.Value = value; } 87 } 88 89 public VRPSolution BestKnownSolution { 90 get { return BestKnownSolutionParameter.Value; } 91 set { BestKnownSolutionParameter.Value = value; } 84 92 } 85 93 … … 111 119 Parameters.Add(new ValueParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance")); 112 120 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance.")); 121 Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance.")); 113 122 114 123 operators = new List<IOperator>(); … … 172 181 Parameters.Remove("SolutionCreator"); 173 182 183 if (Parameters.ContainsKey("BestKnownSolution")) 184 Parameters.Remove("BestKnownSolution"); 185 186 if (Parameters.ContainsKey("BestKnownQuality")) 187 Parameters.Remove("BestKnownQuality"); 188 189 174 190 if (ProblemInstance != null) { 175 191 ProblemInstance.SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); … … 177 193 Parameters.Add(ProblemInstance.EvaluatorParameter); 178 194 Parameters.Add(ProblemInstance.SolutionCreatorParameter); 195 196 Parameters.Add(ProblemInstance.BestKnownQualityParameter); 197 Parameters.Add(ProblemInstance.BestKnownSolutionParameter); 179 198 } 180 199 } … … 251 270 int problemSize = parser.Demands.Length; 252 271 253 if (parser.Depot != 1) 254 throw new Exception("Invalid depot specification"); 255 256 if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D) 257 throw new Exception("Invalid weight type"); 272 if (parser.Depot != 1) { 273 ErrorHandling.ShowErrorDialog(new Exception("Invalid depot specification")); 274 return; 275 } 276 277 if (parser.WeightType != TSPLIBParser.TSPLIBEdgeWeightType.EUC_2D) { 278 ErrorHandling.ShowErrorDialog(new Exception("Invalid weight type")); 279 return; 280 } 258 281 259 282 CVRPTWProblemInstance problem = new CVRPTWProblemInstance(); … … 337 360 this.ProblemInstance = problem; 338 361 } 362 363 public void ImportSolution(string solutionFileName) { 364 SolutionParser parser = new SolutionParser(solutionFileName); 365 parser.Parse(); 366 367 HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding encoding = new Encodings.Potvin.PotvinEncoding(ProblemInstance); 368 369 int cities = 0; 370 foreach (List<int> route in parser.Routes) { 371 Tour tour = new Tour(); 372 tour.Stops.AddRange(route); 373 cities += tour.Stops.Count; 374 375 encoding.Tours.Add(tour); 376 } 377 378 if (cities != ProblemInstance.Coordinates.Rows - 1) 379 ErrorHandling.ShowErrorDialog(new Exception("The optimal solution does not seem to correspond with the problem data")); 380 else { 381 VRPSolution solution = new VRPSolution(ProblemInstance, encoding, new DoubleValue(0)); 382 ProblemInstance.BestKnownSolutionParameter.Value = solution; 383 } 384 } 339 385 } 340 386 }
Note: See TracChangeset
for help on using the changeset viewer.