- Timestamp:
- 11/19/10 15:43:21 (14 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.