Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/22/12 17:37:33 (12 years ago)
Author:
svonolfe
Message:

Added support for included TSPLib CVRP instances (#1177)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r7861 r7871  
    3636using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    3737using HeuristicLab.Problems.VehicleRouting.Variants;
     38using HeuristicLab.Problems.Instances;
     39using System.Reflection;
     40using HeuristicLab.Problems.VehicleRouting.Interpreters;
    3841
    3942namespace HeuristicLab.Problems.VehicleRouting {
     
    4144  [Creatable("Problems")]
    4245  [StorableClass]
    43   public sealed class VehicleRoutingProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent {
     46  public sealed class VehicleRoutingProblem : ParameterizedNamedItem, ISingleObjectiveHeuristicOptimizationProblem, IStorableContent, IProblemInstanceConsumer<IVRPData> {
    4447    public string Filename { get; set; }
    4548
     
    466469      }
    467470    }
     471
     472    public void Load(IVRPData data) {
     473      Type interpreterType = typeof(IVRPDataInterpreter<>).MakeGenericType(data.GetType());
     474      var interpreters = ApplicationManager.Manager.GetInstances(interpreterType);
     475      if (interpreters.Count() > 0) {
     476        IVRPDataInterpreter interpreter = interpreters.First() as IVRPDataInterpreter;
     477        VRPInstanceDescription instance = interpreter.Interpret(data);
     478
     479        Name = instance.Name;
     480        Description = instance.Description;
     481        ProblemInstance = instance.ProblemInstance;
     482
     483        OnReset();
     484
     485        if (instance.BestKnownQuality != null) {
     486          BestKnownQuality = new DoubleValue((double)instance.BestKnownQuality);
     487        }
     488
     489        if (instance.BestKnownSolution != null) {
     490          VRPSolution solution = new VRPSolution(ProblemInstance, instance.BestKnownSolution, new DoubleValue(0));
     491          BestKnownSolutionParameter.Value = solution;
     492        }
     493      } else {
     494        throw new Exception("Cannot find an interpreter for " + data.GetType());
     495      }   
     496    }
    468497  }
    469498}
Note: See TracChangeset for help on using the changeset viewer.