Changeset 10483 for branches/LogResidualEvaluator/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
- Timestamp:
- 02/20/14 14:56:39 (11 years ago)
- Location:
- branches/LogResidualEvaluator
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LogResidualEvaluator
- Property svn:mergeinfo changed
-
branches/LogResidualEvaluator/HeuristicLab.Problems.VehicleRouting
- Property svn:mergeinfo changed
-
branches/LogResidualEvaluator/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r9456 r10483 39 39 40 40 namespace HeuristicLab.Problems.VehicleRouting { 41 public interface IVRPInstanceConsumer :42 IProblemInstanceConsumer<CVRPData>, IProblemInstanceConsumer<CVRPTWData>,43 IProblemInstanceConsumer<MDCVRPData>, IProblemInstanceConsumer<MDCVRPTWData>,44 IProblemInstanceConsumer<PDPTWData> {45 }46 47 41 [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")] 48 42 [Creatable("Problems")] 49 43 [StorableClass] 50 public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, I VRPInstanceConsumer{44 public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IProblemInstanceConsumer<VRPData> { 51 45 public string Filename { get; set; } 52 46 … … 143 137 AttachEventHandlers(); 144 138 AttachProblemInstanceEventHandlers(); 139 140 EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator; 145 141 } 146 142 … … 153 149 : base(original, cloner) { 154 150 this.AttachEventHandlers(); 151 this.AttachProblemInstanceEventHandlers(); 152 153 ProblemInstance.SolutionEvaluator = EvaluatorParameter.Value; 155 154 } 156 155 … … 173 172 AttachEventHandlers(); 174 173 AttachProblemInstanceEventHandlers(); 174 175 ProblemInstance.SolutionEvaluator = EvaluatorParameter.Value; 175 176 } 176 177 … … 189 190 private void AttachProblemInstanceEventHandlers() { 190 191 if (ProblemInstance != null) { 191 EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator;192 192 ProblemInstance.EvaluationChanged += new EventHandler(ProblemInstance_EvaluationChanged); 193 193 } … … 209 209 210 210 void ProblemInstance_EvaluationChanged(object sender, EventArgs e) { 211 EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator;212 211 EvalBestKnownSolution(); 213 212 } … … 216 215 InitializeOperators(); 217 216 AttachProblemInstanceEventHandlers(); 217 218 EvaluatorParameter.Value = ProblemInstance.SolutionEvaluator; 218 219 219 220 OnSolutionCreatorChanged(); … … 383 384 } 384 385 } 385 386 public void Load(CVRPData data) { 387 Load(data, new CVRPInterpreter()); 388 } 389 390 public void Load(CVRPTWData data) { 391 Load(data, new CVRPTWInterpreter()); 392 } 393 394 public void Load(MDCVRPData data) { 395 Load(data, new MDCVRPInterpreter()); 396 } 397 398 public void Load(MDCVRPTWData data) { 399 Load(data, new MDCVRPTWInterpreter()); 400 } 401 402 public void Load(PDPTWData data) { 403 Load(data, new PDPTWInterpreter()); 386 #endregion 387 388 #region IProblemInstanceConsumer<VRPData> Members 389 390 public void Load(VRPData data) { 391 Type interpreterType = typeof(IVRPDataInterpreter<>).MakeGenericType(data.GetType()); 392 var interpreters = ApplicationManager.Manager.GetInstances(interpreterType); 393 IVRPDataInterpreter interpreter = null; 394 foreach (object i in interpreters) { 395 var parentInterfaces = i.GetType().BaseType.GetInterfaces(); 396 var interfaces = i.GetType().GetInterfaces().Except(parentInterfaces); 397 var interpreterInterface = interfaces.First(j => typeof(IVRPDataInterpreter).IsAssignableFrom(j)); 398 var interpreterDataType = interpreterInterface.GetGenericArguments()[0]; 399 if (interpreterDataType == data.GetType()) { 400 interpreter = i as IVRPDataInterpreter; 401 break; 402 } 403 } 404 405 if (interpreter == null) 406 throw new ArgumentException("No interpreter found for the VRP type"); 407 Load(data, interpreter); 404 408 } 405 409
Note: See TracChangeset
for help on using the changeset viewer.