Changeset 8905 for trunk/sources/HeuristicLab.Problems.VehicleRouting
- Timestamp:
- 11/13/12 10:29:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs
r8720 r8905 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 41 47 [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")] 42 48 [Creatable("Problems")] 43 49 [StorableClass] 44 public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, I ProblemInstanceConsumer<IVRPData>{50 public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IVRPInstanceConsumer { 45 51 public string Filename { get; set; } 46 52 … … 352 358 } 353 359 354 public void Load(IVRPData data) { 355 Type interpreterType = typeof(IVRPDataInterpreter<>).MakeGenericType(data.GetType()); 356 var interpreters = ApplicationManager.Manager.GetInstances(interpreterType); 357 if (interpreters.Count() > 0) { 358 IVRPDataInterpreter interpreter = interpreters.First() as IVRPDataInterpreter; 359 VRPInstanceDescription instance = interpreter.Interpret(data); 360 361 Name = instance.Name; 362 Description = instance.Description; 363 if (ProblemInstance != null && instance.ProblemInstance != null && 364 instance.ProblemInstance.GetType() == ProblemInstance.GetType()) 365 SetProblemInstance(instance.ProblemInstance); 366 else 367 ProblemInstance = instance.ProblemInstance; 368 369 OnReset(); 370 BestKnownQuality = null; 371 BestKnownSolution = null; 372 373 if (instance.BestKnownQuality != null) { 374 BestKnownQuality = new DoubleValue((double)instance.BestKnownQuality); 375 } 376 377 if (instance.BestKnownSolution != null) { 378 VRPSolution solution = new VRPSolution(ProblemInstance, instance.BestKnownSolution, new DoubleValue(0)); 379 BestKnownSolution = solution; 380 } 381 } else { 382 throw new Exception("Cannot find an interpreter for " + data.GetType()); 383 } 384 } 360 #region Instance Consuming 361 public void Load(IVRPData data, IVRPDataInterpreter interpreter) { 362 VRPInstanceDescription instance = interpreter.Interpret(data); 363 364 Name = instance.Name; 365 Description = instance.Description; 366 if (ProblemInstance != null && instance.ProblemInstance != null && 367 instance.ProblemInstance.GetType() == ProblemInstance.GetType()) 368 SetProblemInstance(instance.ProblemInstance); 369 else 370 ProblemInstance = instance.ProblemInstance; 371 372 OnReset(); 373 BestKnownQuality = null; 374 BestKnownSolution = null; 375 376 if (instance.BestKnownQuality != null) { 377 BestKnownQuality = new DoubleValue((double)instance.BestKnownQuality); 378 } 379 380 if (instance.BestKnownSolution != null) { 381 VRPSolution solution = new VRPSolution(ProblemInstance, instance.BestKnownSolution, new DoubleValue(0)); 382 BestKnownSolution = solution; 383 } 384 } 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()); 404 } 405 406 #endregion 385 407 } 386 408 }
Note: See TracChangeset
for help on using the changeset viewer.