Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/13/12 10:29:26 (12 years ago)
Author:
svonolfe
Message:

Adapted VRP implementation to changes of r8904 - instance consuming (#1981)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r8720 r8905  
    3939
    4040namespace HeuristicLab.Problems.VehicleRouting {
     41  public interface IVRPInstanceConsumer : 
     42    IProblemInstanceConsumer<CVRPData>, IProblemInstanceConsumer<CVRPTWData>,
     43    IProblemInstanceConsumer<MDCVRPData>, IProblemInstanceConsumer<MDCVRPTWData>,
     44    IProblemInstanceConsumer<PDPTWData> {
     45  }
     46
    4147  [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")]
    4248  [Creatable("Problems")]
    4349  [StorableClass]
    44   public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IProblemInstanceConsumer<IVRPData> {
     50  public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IVRPInstanceConsumer {
    4551    public string Filename { get; set; }
    4652
     
    352358    }
    353359
    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
    385407  }
    386408}
Note: See TracChangeset for help on using the changeset viewer.