Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/04/14 16:21:15 (11 years ago)
Author:
pfleck
Message:

#2152

  • Removed generic argument of VRPInstanceProvider.
  • Removed specific IProblemInstanceConsumer interfaces.
  • Added dynamic lookup of compatible interpreter.
File:
1 edited

Legend:

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

    r10363 r10435  
    3939
    4040namespace HeuristicLab.Problems.VehicleRouting {
    41   public interface IVRPInstanceConsumer :
    42     IProblemInstanceConsumer<CVRPData>, IProblemInstanceConsumer<CVRPTWData>,
    43     IProblemInstanceConsumer<MDCVRPData>, IProblemInstanceConsumer<MDCVRPTWData>,
    44     IProblemInstanceConsumer<PDPTWData> {
    45   }
    46 
    4741  [Item("Vehicle Routing Problem", "Represents a Vehicle Routing Problem.")]
    4842  [Creatable("Problems")]
    4943  [StorableClass]
    50   public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IVRPInstanceConsumer {
     44  public sealed class VehicleRoutingProblem : Problem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IProblemInstanceConsumer<VRPData> {
    5145    public string Filename { get; set; }
    5246
     
    390384      }
    391385    }
    392 
    393     public void Load(CVRPData data) {
    394       Load(data, new CVRPInterpreter());
    395     }
    396 
    397     public void Load(CVRPTWData data) {
    398       Load(data, new CVRPTWInterpreter());
    399     }
    400 
    401     public void Load(MDCVRPData data) {
    402       Load(data, new MDCVRPInterpreter());
    403     }
    404 
    405     public void Load(MDCVRPTWData data) {
    406       Load(data, new MDCVRPTWInterpreter());
    407     }
    408 
    409     public void Load(PDPTWData data) {
    410       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);
    411408    }
    412409
Note: See TracChangeset for help on using the changeset viewer.