- Timestamp:
- 05/21/12 13:46:48 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/VRPMoveMaker.cs
r6607 r7852 63 63 64 64 private void UpdateMoveEvaluation() { 65 IVRPEvaluator evaluator = ProblemInstance. EvaluatorParameter.Value;65 IVRPEvaluator evaluator = ProblemInstance.SolutionEvaluator; 66 66 ICollection<IParameter> addedParameters = new List<IParameter>(); 67 67 -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPProblemInstance.cs
r6854 r7852 31 31 namespace HeuristicLab.Problems.VehicleRouting.Interfaces { 32 32 public interface IVRPProblemInstance: IItem { 33 IV alueParameter<IVRPEvaluator> EvaluatorParameter { get; }33 IVRPEvaluator SolutionEvaluator { get; } 34 34 IVRPEvaluator MoveEvaluator { get; } 35 IValueParameter<IVRPCreator> SolutionCreatorParameter { get; }36 IValueParameter<DoubleValue> BestKnownQualityParameter { get; }37 IValueParameter<VRPSolution> BestKnownSolutionParameter { get; }38 35 IEnumerable<IOperator> Operators { get; } 36 37 event EventHandler EvaluationChanged; 39 38 40 39 DoubleMatrix Coordinates { get; } -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPProblemInstance.cs
r6851 r7852 119 119 #region Event handlers 120 120 void CapacityParameter_ValueChanged(object sender, EventArgs e) { 121 BestKnownSolution = null;121 EvalBestKnownSolution(); 122 122 } 123 123 void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPProblemInstance.cs
r6711 r7852 121 121 void CapacityParameter_ValueChanged(object sender, EventArgs e) { 122 122 CapacityParameter.Value.ValueChanged += new EventHandler(Capacity_ValueChanged); 123 BestKnownSolution = null;123 EvalBestKnownSolution(); 124 124 } 125 125 void Capacity_ValueChanged(object sender, EventArgs e) { 126 BestKnownSolution = null;126 EvalBestKnownSolution(); 127 127 } 128 128 void OverloadPenaltyParameter_ValueChanged(object sender, EventArgs e) { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs
r7543 r7852 38 38 [StorableClass] 39 39 public abstract class VRPProblemInstance : ParameterizedNamedItem, IVRPProblemInstance, IStatefulItem { 40 public IValueParameter<IVRPEvaluator> EvaluatorParameter {41 get { return (ValueParameter<IVRPEvaluator>)Parameters["Evaluator"]; }42 }43 44 40 IVRPEvaluator moveEvaluator; 45 41 46 42 public IVRPEvaluator MoveEvaluator { 47 43 get { 48 if ( EvaluatorParameter.Value== null)44 if (evaluator == null) 49 45 return null; 50 46 else { 51 47 if (moveEvaluator == null) { 52 moveEvaluator = EvaluatorParameter.Value.Clone() as IVRPEvaluator;48 moveEvaluator = evaluator.Clone() as IVRPEvaluator; 53 49 54 50 foreach (IParameter parameter in moveEvaluator.Parameters) { … … 68 64 } 69 65 70 public IValueParameter<IVRPCreator> SolutionCreatorParameter {71 get { return (ValueParameter<IVRPCreator>)Parameters["SolutionCreator"]; }72 }73 74 66 protected abstract IEnumerable<IOperator> GetOperators(); 75 67 protected abstract IEnumerable<IOperator> GetAnalyzers(); … … 104 96 } 105 97 106 protected OptionalValueParameter<DoubleValue> BestKnownQualityParameter {107 get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }108 }109 protected OptionalValueParameter<VRPSolution> BestKnownSolutionParameter {110 get { return (OptionalValueParameter<VRPSolution>)Parameters["BestKnownSolution"]; }111 }112 113 IValueParameter<DoubleValue> IVRPProblemInstance.BestKnownQualityParameter {114 get { return BestKnownQualityParameter; }115 }116 117 IValueParameter<VRPSolution> IVRPProblemInstance.BestKnownSolutionParameter {118 get { return BestKnownSolutionParameter; }119 }120 121 98 public DoubleMatrix Coordinates { 122 99 get { return CoordinatesParameter.Value; } … … 151 128 get { return DistanceFactorParameter.Value; } 152 129 set { DistanceFactorParameter.Value = value; } 153 }154 155 public DoubleValue BestKnownQuality {156 get { return BestKnownQualityParameter.Value; }157 set { BestKnownQualityParameter.Value = value; }158 }159 public VRPSolution BestKnownSolution {160 get { return BestKnownSolutionParameter.Value; }161 set { BestKnownSolutionParameter.Value = value; }162 130 } 163 131 … … 205 173 private IVRPEvaluator evaluator = null; 206 174 175 public IVRPEvaluator SolutionEvaluator { 176 get { 177 return evaluator; 178 } 179 } 180 207 181 public virtual double GetDistance(int start, int end, IVRPEncoding solution) { 208 182 double distance = 0.0; … … 259 233 } 260 234 235 236 public event EventHandler EvaluationChanged; 237 261 238 protected void EvalBestKnownSolution() { 262 if (BestKnownSolution != null) { 263 //call evaluator 264 BestKnownQuality = new DoubleValue(Evaluate(BestKnownSolution.Solution).Quality); 265 BestKnownSolution.Quality = BestKnownQuality; 266 } else { 267 BestKnownQuality = null; 268 } 239 EventHandler tmp = EvaluationChanged; 240 if (tmp != null) 241 tmp(this, null); 269 242 } 270 243 … … 286 259 Parameters.Add(new ValueParameter<DoubleValue>("EvalDistanceFactor", "The distance factor considered in the evaluation.", new DoubleValue(1))); 287 260 288 Parameters.Add(new ValueParameter<IVRPCreator>("SolutionCreator", "The operator which should be used to create new VRP solutions.", Creator)); 289 Parameters.Add(new ValueParameter<IVRPEvaluator>("Evaluator", "The operator which should be used to evaluate VRP solutions.", Evaluator)); 290 291 Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this VRP instance.")); 292 Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance.")); 293 261 evaluator = Evaluator; 294 262 AttachEventHandlers(); 295 263 } … … 297 265 protected VRPProblemInstance(VRPProblemInstance original, Cloner cloner) 298 266 : base(original, cloner) { 299 AttachEventHandlers(); 267 evaluator = Evaluator; 268 AttachEventHandlers(); 300 269 } 301 270 302 271 [StorableHook(HookType.AfterDeserialization)] 303 272 private void AfterDeserializationHook() { 273 evaluator = Evaluator; 304 274 AttachEventHandlers(); 305 275 } 306 276 307 277 private void AttachEventHandlers() { 308 evaluator = EvaluatorParameter.Value;309 EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);310 BestKnownSolutionParameter.ValueChanged += new EventHandler(BestKnownSolutionParameter_ValueChanged);311 278 DistanceFactorParameter.ValueChanged += new EventHandler(DistanceFactorParameter_ValueChanged); 312 279 DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged); … … 329 296 330 297 #region Event handlers 331 void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {332 moveEvaluator = null;333 evaluator = EvaluatorParameter.Value;334 }335 336 void BestKnownSolutionParameter_ValueChanged(object sender, EventArgs e) {337 EvalBestKnownSolution();338 }339 298 void DistanceFactorParameter_ValueChanged(object sender, EventArgs e) { 340 299 DistanceFactorParameter.Value.ValueChanged += new EventHandler(DistanceFactor_ValueChanged); -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r7203 r7852 92 92 } 93 93 94 public DoubleValue BestKnownQuality { 95 get { return BestKnownQualityParameter.Value; } 96 set { BestKnownQualityParameter.Value = value; } 97 } 98 94 99 public ISingleObjectiveEvaluator Evaluator { 95 get { return ProblemInstance.EvaluatorParameter.Value; }100 get { return EvaluatorParameter.Value; } 96 101 } 97 102 … … 101 106 102 107 public ISolutionCreator SolutionCreator { 103 get { return ProblemInstance.SolutionCreatorParameter.Value; }108 get { return SolutionCreatorParameter.Value; } 104 109 } 105 110 … … 121 126 Parameters.Add(new OptionalValueParameter<VRPSolution>("BestKnownSolution", "The best known solution of this VRP instance.")); 122 127 128 Parameters.Add(new ConstrainedValueParameter<IVRPCreator>("SolutionCreator", "The operator which should be used to create new VRP solutions.")); 129 Parameters.Add(new ValueParameter<IVRPEvaluator>("Evaluator", "The operator which should be used to evaluate VRP solutions.")); 130 131 EvaluatorParameter.Hidden = true; 132 123 133 operators = new List<IOperator>(); 124 134 … … 175 185 176 186 private void AttachProblemInstanceEventHandlers() { 177 if (Parameters.ContainsKey("Evaluator")) 178 Parameters.Remove("Evaluator"); 179 180 if (Parameters.ContainsKey("SolutionCreator")) 181 Parameters.Remove("SolutionCreator"); 182 183 if (Parameters.ContainsKey("BestKnownSolution")) 184 Parameters.Remove("BestKnownSolution"); 185 186 if (Parameters.ContainsKey("BestKnownQuality")) 187 Parameters.Remove("BestKnownQuality"); 188 187 var solutionCreatorParameter = SolutionCreatorParameter as ConstrainedValueParameter<IVRPCreator>; 188 solutionCreatorParameter.ValidValues.Clear(); 189 189 190 190 if (ProblemInstance != null) { 191 ProblemInstance.SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 192 ProblemInstance.EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 193 Parameters.Add(ProblemInstance.EvaluatorParameter); 194 Parameters.Add(ProblemInstance.SolutionCreatorParameter); 195 196 Parameters.Add(ProblemInstance.BestKnownQualityParameter); 197 Parameters.Add(ProblemInstance.BestKnownSolutionParameter); 191 EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator; 192 foreach (IVRPCreator creator in ProblemInstance.Operators.Where(o => o is IVRPCreator)) { 193 solutionCreatorParameter.ValidValues.Add(creator); 194 } 195 ProblemInstance.EvaluationChanged += new EventHandler(ProblemInstance_EvaluationChanged); 196 } 197 } 198 199 void ProblemInstance_EvaluationChanged(object sender, EventArgs e) { 200 if (BestKnownSolution != null) { 201 //call evaluator 202 BestKnownQuality = new DoubleValue(ProblemInstance.Evaluate(BestKnownSolution.Solution).Quality); 203 BestKnownSolution.Quality = BestKnownQuality; 204 } else { 205 BestKnownQuality = null; 198 206 } 199 207 } … … 260 268 parser.Parse(); 261 269 270 this.Name = parser.ProblemName; 262 271 MDCVRPTWProblemInstance problem = new MDCVRPTWProblemInstance(); 263 272 … … 291 300 parser.Parse(); 292 301 302 this.Name = parser.ProblemName; 293 303 CVRPPDTWProblemInstance problem = new CVRPPDTWProblemInstance(); 294 304 … … 444 454 else { 445 455 VRPSolution solution = new VRPSolution(ProblemInstance, encoding, new DoubleValue(0)); 446 ProblemInstance.BestKnownSolutionParameter.Value = solution;456 BestKnownSolutionParameter.Value = solution; 447 457 } 448 458 }
Note: See TracChangeset
for help on using the changeset viewer.