Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/29/11 15:51:56 (13 years ago)
Author:
svonolfe
Message:

Added support for multi depot CVRP instances (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs

    r6838 r6851  
    3838  [Item("CVRPEvaluator", "Represents a single depot CVRP evaluator.")]
    3939  [StorableClass]
    40   public class CVRPEvaluator: SingleDepotVRPEvaluator {
     40  public class CVRPEvaluator: VRPEvaluator {
    4141    public ILookupParameter<DoubleValue> OverloadParameter {
    4242      get { return (ILookupParameter<DoubleValue>)Parameters["Overload"]; }
     
    7979
    8080        //drive there
    81         double currentDistace = instance.GetDistance(start, end);
     81        double currentDistace = instance.GetDistance(start, end, solution);
    8282        distance += currentDistace;
    8383
     
    103103    }
    104104
    105     protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     105    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    106106      out bool feasible) {
    107107      CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo;
     
    113113      double overloadPenalty = cvrp.OverloadPenalty.Value;
    114114
    115       double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     115      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution);
    116116      double newDistance =
    117         instance.GetDistance(insertionInfo.Start, customer) +
    118         instance.GetDistance(customer, insertionInfo.End);
     117        instance.GetDistance(insertionInfo.Start, customer, solution) +
     118        instance.GetDistance(customer, insertionInfo.End, solution);
    119119      costs += instance.DistanceFactor.Value * (newDistance - distance);
    120120
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs

    r6838 r6851  
    8585
    8686        //drive there
    87         double currentDistace = vrptw.GetDistance(start, end);
     87        double currentDistace = vrptw.GetDistance(start, end, solution);
    8888        time += currentDistace;
    8989        distance += currentDistace;
     
    166166    }
    167167
    168     protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     168    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    169169      out bool feasible) {
    170170      CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo;
     
    187187      double pickupPenalty = pdp.PickupViolationPenalty.Value;
    188188
    189       double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     189      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution);
    190190      double newDistance =
    191         instance.GetDistance(insertionInfo.Start, customer) +
    192         instance.GetDistance(customer, insertionInfo.End);
     191        instance.GetDistance(insertionInfo.Start, customer, solution) +
     192        instance.GetDistance(customer, insertionInfo.End, solution);
    193193      costs += instance.DistanceFactor.Value * (newDistance - distance);
    194194
     
    215215      if (index > 0)
    216216        time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
    217       time += instance.GetDistance(insertionInfo.Start, customer);
     217      time += instance.GetDistance(insertionInfo.Start, customer, solution);
    218218      if (time > dueTime[customer]) {
    219219        tardiness += time - dueTime[customer];
     
    222222        time += readyTime[customer] - time;
    223223      time += serviceTimes[customer];
    224       time += instance.GetDistance(customer, insertionInfo.End);
     224      time += instance.GetDistance(customer, insertionInfo.End, solution);
    225225
    226226      double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs

    r6838 r6851  
    9292
    9393        //drive there
    94         double currentDistace = vrptw.GetDistance(start, end);
     94        double currentDistace = vrptw.GetDistance(start, end, solution);
    9595        time += currentDistace;
    9696        distance += currentDistace;
     
    150150    }
    151151
    152     protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     152    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    153153      out bool feasible) {
    154154      CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
     
    166166      double tardinessPenalty = vrptw.TardinessPenalty.Value;
    167167
    168       double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     168      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution);
    169169      double newDistance =
    170         instance.GetDistance(insertionInfo.Start, customer) +
    171         instance.GetDistance(customer, insertionInfo.End);
     170        instance.GetDistance(insertionInfo.Start, customer, solution) +
     171        instance.GetDistance(customer, insertionInfo.End, solution);
    172172      costs += instance.DistanceFactor.Value * (newDistance - distance);
    173173
     
    186186      if (index > 0)
    187187        time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
    188       time += instance.GetDistance(insertionInfo.Start, customer);
     188      time += instance.GetDistance(insertionInfo.Start, customer, solution);
    189189      if (time > dueTime[customer]) {
    190190        tardiness += time - dueTime[customer];
     
    193193        time += readyTime[customer] - time;
    194194      time += serviceTimes[customer];
    195       time += instance.GetDistance(customer, insertionInfo.End);
     195      time += instance.GetDistance(customer, insertionInfo.End, solution);
    196196
    197197      double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs

    r6838 r6851  
    5757
    5858        //drive there
    59         double currentDistace = instance.GetDistance(start, end);
     59        double currentDistace = instance.GetDistance(start, end, solution);
    6060        distance += currentDistace;
    6161
     
    7575    }
    7676
    77     protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     77    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    7878      out bool feasible) {
    7979      StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
     
    8282      feasible = true;
    8383
    84       double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     84      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End, solution);
    8585      double newDistance =
    86         instance.GetDistance(insertionInfo.Start, customer) +
    87         instance.GetDistance(customer, insertionInfo.End);
     86        instance.GetDistance(insertionInfo.Start, customer, solution) +
     87        instance.GetDistance(customer, insertionInfo.End, solution);
    8888
    8989      costs += instance.DistanceFactor.Value * (newDistance - distance);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluator.cs

    r6838 r6851  
    103103    }
    104104
    105     protected abstract double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer, out bool feasible);
     105    protected abstract double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer, out bool feasible);
    106106
    107     public double GetInsertionCosts(IVRPProblemInstance instance, VRPEvaluation eval, int customer, int tour, int index, out bool feasible) {
     107    public double GetInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, VRPEvaluation eval, int customer, int tour, int index, out bool feasible) {
    108108      bool tourFeasible;
    109109      double costs = GetTourInsertionCosts(
    110110        instance,
     111        solution,
    111112        eval.InsertionInfo.GetTourInsertionInfo(tour), index,
    112113        customer, out tourFeasible);
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r6838 r6851  
    188188    }
    189189
     190    public virtual double[] GetCoordinates(int city) {
     191      double[] coordinates = new double[Coordinates.Columns];
     192
     193      for (int i = 0; i < Coordinates.Columns; i++) {
     194        coordinates[i] = Coordinates[city, i];
     195      }
     196
     197      return coordinates;
     198    }
     199
     200    public virtual double GetDemand(int city) {
     201      return Demand[city];
     202    }
     203
    190204    //cache for performance improvement
    191205    private DoubleMatrix distanceMatrix = null;
    192206    private IVRPEvaluator evaluator = null;
    193207
    194     public double GetDistance(int start, int end) {
     208    public virtual double GetDistance(int start, int end, IVRPEncoding solution) {
    195209      double distance = 0.0;
    196210      if (distanceMatrix == null && UseDistanceMatrix.Value) {
     
    206220    }
    207221
     222    public virtual double GetInsertionDistance(int start, int customer, int end, IVRPEncoding solution) {
     223      double distance = GetDistance(start, end, solution);
     224      double newDistance =
     225        GetDistance(start, customer, solution) +
     226        GetDistance(customer, end, solution);
     227
     228      return newDistance - distance;
     229    }
     230
    208231    public bool Feasible(IVRPEncoding solution) {
    209232      return evaluator.Feasible(
     
    230253    }
    231254
    232     public double GetInsertionCosts(VRPEvaluation eval, int customer, int tour, int index, out bool feasible) {
    233       return evaluator.GetInsertionCosts(this, eval, customer, tour, index, out feasible);
     255    public double GetInsertionCosts(VRPEvaluation eval, IVRPEncoding solution, int customer, int tour, int index, out bool feasible) {
     256      return evaluator.GetInsertionCosts(this, solution, eval, customer, tour, index, out feasible);
    234257    }
    235258
Note: See TracChangeset for help on using the changeset viewer.