Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/13/11 16:00:19 (13 years ago)
Author:
svonolfe
Message:

Added support for incremental evaluation to improve performance (#1177)

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

Legend:

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

    r4454 r6752  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Core;
     28using HeuristicLab.Common;
    2629
    2730namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
     31  public class CVRPInsertionInfo : StopInsertionInfo {
     32    private double spareCapacity;
     33
     34    public double SpareCapacity {
     35      get { return spareCapacity; }
     36    }
     37
     38    public CVRPInsertionInfo(int start, int end, double spareCapacity)
     39      : base(start, end) {
     40      this.spareCapacity = spareCapacity;
     41    }
     42  }
     43 
    2844  public class CVRPEvaluation: VRPEvaluation {
    2945    public double Overload { get; set; }
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs

    r4752 r6752  
    4848
    4949    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     50      TourInsertionInfo tourInfo = new TourInsertionInfo();
     51      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     52     
    5053      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    5154      DoubleArray demand = instance.Demand;
     
    5457      double overweight = 0.0;
    5558      double distance = 0.0;
     59
     60      double capacity = cvrpInstance.Capacity.Value;
     61      for (int i = 0; i <= tour.Stops.Count; i++) {
     62        int end = 0;
     63        if (i < tour.Stops.Count)
     64          end = tour.Stops[i];
     65
     66        delivered += demand[end];
     67      }
     68
     69      double spareCapacity = capacity - delivered;
    5670
    5771      //simulate a tour, start and end at depot
     
    6882        distance += currentDistace;
    6983
    70         delivered += demand[end];
     84        CVRPInsertionInfo stopInfo = new CVRPInsertionInfo(start, end, spareCapacity);
     85        tourInfo.AddStopInsertionInfo(stopInfo);
    7186      }
    7287
     
    7792      eval.VehicleUtilization += 1;
    7893
    79       double capacity = cvrpInstance.Capacity.Value;
    8094      if (delivered > capacity) {
    8195        overweight = delivered - capacity;
     
    86100      eval.Penalty += penalty;
    87101      eval.Quality += penalty;
     102      tourInfo.Penalty = penalty;
     103    }
     104
     105    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     106      out bool feasible) {
     107      CVRPInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPInsertionInfo;
     108     
     109      double costs = 0;
     110      feasible = tourInsertionInfo.Penalty < double.Epsilon;
     111
     112      ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     113      double overloadPenalty = cvrp.OverloadPenalty.Value;
     114
     115      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     116      double newDistance =
     117        instance.GetDistance(insertionInfo.Start, customer) +
     118        instance.GetDistance(customer, insertionInfo.End);
     119      costs += instance.DistanceFactor.Value * (newDistance - distance);
     120
     121      double demand = instance.Demand[customer];
     122      if (demand > insertionInfo.SpareCapacity) {
     123        feasible = false;
     124
     125        if(insertionInfo.SpareCapacity >= 0)
     126          costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     127        else
     128          costs += demand * overloadPenalty;
     129      }
     130     
     131      return costs;
    88132    }
    89133
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluation.cs

    r6710 r6752  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Common;
    2628
    2729namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
     30  public class CVRPPDTWInsertionInfo : CVRPTWInsertionInfo {
     31    private List<int> visited;
     32
     33    public List<int> Visited {
     34      get { return visited; }
     35    }
     36
     37    private double arrivalSpareCapacity;
     38
     39    public double ArrivalSpareCapacity {
     40      get { return arrivalSpareCapacity;  }
     41    }
     42
     43    public CVRPPDTWInsertionInfo(int start, int end, double spareCapacity, double arrivalTime, double leaveTime, double spareTime, double waitingTime, List<int> visited, double arrivalSpareCapacity)
     44      : base(start, end, spareCapacity, arrivalTime, leaveTime, spareTime, waitingTime) {
     45        this.visited = visited;
     46        this.arrivalSpareCapacity = arrivalSpareCapacity;
     47    }
     48  }
     49 
    2850  public class CVRPPDTWEvaluation: CVRPTWEvaluation {
    2951    public int PickupViolations { get; set; }
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs

    r6710 r6752  
    4848
    4949    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     50      TourInsertionInfo tourInfo = new TourInsertionInfo();
     51      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     52
    5053      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    5154      DoubleArray demand = instance.Demand;
     
    8689        distance += currentDistace;
    8790
     91        double arrivalTime = time;
     92
    8893        //check if it was serviced on time
    8994        if (time > dueTime[end])
     
    9499        if (time < readyTime[end])
    95100          currentWaitingTime = readyTime[end] - time;
     101
     102        double waitTime = readyTime[end] - time;
     103
    96104        waitingTime += currentWaitingTime;
    97105        time += currentWaitingTime;
     106
     107        double spareTime = dueTime[end] - time;
    98108
    99109        //service
     
    103113
    104114        //Pickup / deliver
     115        double arrivalSpareCapacity = capacity - currentLoad;
     116
    105117        bool validPickupDelivery =
    106118          validPickupDelivery =
     
    110122        if (validPickupDelivery) {
    111123          currentLoad += demand[end];
    112 
    113           if (currentLoad > capacity)
    114             overweight += currentLoad - capacity;
    115124        } else {
    116125          pickupViolations++;
    117126        }
     127
     128        if (currentLoad > capacity)
     129          overweight += currentLoad - capacity;
     130
     131        double spareCapacity = capacity - currentLoad;
     132        CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity);
     133        tourInfo.AddStopInsertionInfo(stopInfo);
    118134
    119135        stops.Add(end, true);
     
    126142
    127143      (eval as CVRPEvaluation).Overload += overweight;
     144      double tourPenalty = 0;
    128145      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
    129146      eval.Penalty += penalty;
    130147      eval.Quality += penalty;
     148      tourPenalty += penalty;
    131149
    132150      (eval as CVRPTWEvaluation).Tardiness += tardiness;
     
    136154      eval.Penalty += penalty;
    137155      eval.Quality += penalty;
     156      tourPenalty += penalty;
    138157
    139158      (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
    140159      penalty = pickupViolations * pdp.PickupViolationPenalty.Value;
    141160      eval.Penalty += penalty;
     161      tourPenalty += penalty;
    142162
    143163      eval.Quality += penalty;
    144164      eval.Quality += time * vrptw.TimeFactor.Value;
     165      tourInfo.Penalty = tourPenalty;
     166    }
     167
     168    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     169      out bool feasible) {
     170      CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo;
     171
     172      double costs = 0;
     173      feasible = tourInsertionInfo.Penalty < double.Epsilon;
     174      bool tourFeasible = true;
     175
     176      ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     177      double overloadPenalty = cvrp.OverloadPenalty.Value;
     178
     179      ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     180      DoubleArray dueTime = vrptw.DueTime;
     181      DoubleArray readyTime = vrptw.ReadyTime;
     182      DoubleArray serviceTimes = vrptw.ServiceTime;
     183      double tardinessPenalty = vrptw.TardinessPenalty.Value;
     184
     185      IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     186      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;
     187      double pickupPenalty = pdp.PickupViolationPenalty.Value;
     188
     189      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     190      double newDistance =
     191        instance.GetDistance(insertionInfo.Start, customer) +
     192        instance.GetDistance(customer, insertionInfo.End);
     193      costs += instance.DistanceFactor.Value * (newDistance - distance);
     194
     195      double demand = instance.Demand[customer];
     196      if (demand > insertionInfo.ArrivalSpareCapacity) {
     197        tourFeasible = feasible = false;
     198        if (insertionInfo.ArrivalSpareCapacity >= 0)
     199          costs += (demand - insertionInfo.ArrivalSpareCapacity) * overloadPenalty;
     200        else
     201          costs += demand * overloadPenalty;
     202      }
     203      int destination = pickupDeliveryLocation[customer];
     204
     205      bool validPickup = true;
     206      if (demand < 0 && !insertionInfo.Visited.Contains(destination)) {
     207        tourFeasible = feasible = false;
     208        validPickup = false;
     209        costs += pickupPenalty;
     210      }
     211
     212      double time = 0;
     213      double tardiness = 0;
     214
     215      if (index > 0)
     216        time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     217      time += instance.GetDistance(insertionInfo.Start, customer);
     218      if (time > dueTime[customer]) {
     219        tardiness += time - dueTime[customer];
     220      }
     221      if (time < readyTime[customer])
     222        time += readyTime[customer] - time;
     223      time += serviceTimes[customer];
     224      time += instance.GetDistance(customer, insertionInfo.End);
     225
     226      double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     227      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
     228        CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     229
     230        if (demand >= 0) {
     231          if (nextStop.End == destination) {
     232            demand = 0;
     233            costs -= pickupPenalty;
     234            if (tourInsertionInfo.Penalty == pickupPenalty && tourFeasible)
     235              feasible = true;
     236          } else if (nextStop.SpareCapacity < 0) {
     237            costs += demand * overloadPenalty;
     238          } else if (nextStop.SpareCapacity < demand) {
     239            tourFeasible = feasible = false;
     240            costs += (demand - nextStop.SpareCapacity) * overloadPenalty;
     241          }
     242        } else if (validPickup) {
     243          if (nextStop.SpareCapacity < 0) {
     244            costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty;
     245          }
     246        }
     247
     248        if (additionalTime < 0) {
     249          //arrive earlier than before
     250          //wait probably
     251          if (nextStop.WaitingTime < 0) {
     252            double wait = nextStop.WaitingTime - additionalTime;
     253            if (wait > 0)
     254              additionalTime += wait;
     255          } else {
     256            additionalTime = 0;
     257          }
     258
     259          //check due date, decrease tardiness
     260          if (nextStop.SpareTime < 0) {
     261            costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty;
     262          }
     263        } else {
     264          //arrive later than before, probably don't have to wait
     265          if (nextStop.WaitingTime > 0) {
     266            additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime);
     267          }
     268
     269          //check due date
     270          if (nextStop.SpareTime > 0) {
     271            double spare = nextStop.SpareTime - additionalTime;
     272            if (spare < 0)
     273              tardiness += -spare;
     274          } else {
     275            tardiness += additionalTime;
     276          }
     277        }
     278      }
     279
     280      costs += additionalTime * vrptw.TimeFactor.Value;
     281
     282      if (tardiness > 0) {
     283        tourFeasible = feasible = false;
     284      }
     285
     286      costs += tardiness * tardinessPenalty;
     287
     288      return costs;
    145289    }
    146290
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluation.cs

    r4454 r6752  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Common;
    2628
    2729namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
     30  public class CVRPTWInsertionInfo : CVRPInsertionInfo {
     31    private double arrivalTime;
     32
     33    public double ArrivalTime {
     34      get { return arrivalTime; }
     35    }
     36
     37    private double leaveTime;
     38
     39    public double LeaveTime {
     40      get { return leaveTime; }
     41    }
     42
     43    private double spareTime;
     44
     45    public double SpareTime {
     46      get { return spareTime; }
     47    }
     48
     49    private double waitingTime;
     50
     51    public double WaitingTime {
     52      get { return waitingTime; }
     53    }
     54
     55    public CVRPTWInsertionInfo(int start, int end, double spareCapacity, double arrivalTime, double leaveTime, double spareTime, double waitingTime)
     56      : base(start, end, spareCapacity) {
     57        this.arrivalTime = arrivalTime;
     58        this.leaveTime = leaveTime;
     59        this.spareTime = spareTime;
     60        this.waitingTime = waitingTime;
     61    }
     62  }
     63 
    2864  public class CVRPTWEvaluation: CVRPEvaluation {
    2965    public double Tardiness { get; set; }
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs

    r4752 r6752  
    5252
    5353    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     54      TourInsertionInfo tourInfo = new TourInsertionInfo();
     55      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     56     
    5457      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    5558      DoubleArray demand = instance.Demand;
     
    6770      double overweight = 0.0;
    6871      double distance = 0.0;
     72
     73      double capacity = cvrpInstance.Capacity.Value;
     74      for (int i = 0; i <= tour.Stops.Count; i++) {
     75        int end = 0;
     76        if (i < tour.Stops.Count)
     77          end = tour.Stops[i];
     78
     79        delivered += demand[end];
     80      }
     81
     82      double spareCapacity = capacity - delivered;
    6983
    7084      //simulate a tour, start and end at depot
     
    8296        distance += currentDistace;
    8397
     98        double arrivalTime = time;
     99
    84100        //check if it was serviced on time
    85101        if (time > dueTime[end])
     
    90106        if (time < readyTime[end])
    91107          currentWaitingTime = readyTime[end] - time;
     108
     109        double waitTime = readyTime[end]-time;
     110
    92111        waitingTime += currentWaitingTime;
    93112        time += currentWaitingTime;
     113
     114        double spareTime = dueTime[end] - time;
    94115
    95116        //service
     
    97118        serviceTime += currentServiceTime;
    98119        time += currentServiceTime;
    99         delivered += demand[end];
     120
     121        CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, arrivalTime, time, spareTime, waitTime);
     122        tourInfo.AddStopInsertionInfo(stopInfo);
    100123      }
    101124
     
    105128      eval.VehicleUtilization += 1;
    106129
    107       double capacity = cvrpInstance.Capacity.Value;
    108130      if (delivered > capacity) {
    109131        overweight = delivered - capacity;
     
    111133
    112134      (eval as CVRPEvaluation).Overload += overweight;
     135      double tourPenalty = 0;
    113136      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
    114137      eval.Penalty += penalty;
    115138      eval.Quality += penalty;
     139      tourPenalty += penalty;
    116140
    117141      (eval as CVRPTWEvaluation).Tardiness += tardiness;
     
    121145      eval.Penalty += penalty;
    122146      eval.Quality += penalty;
     147      tourPenalty += penalty;
    123148      eval.Quality += time * vrptw.TimeFactor.Value;
     149      tourInfo.Penalty = tourPenalty;
     150    }
     151
     152    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     153      out bool feasible) {
     154      CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
     155
     156      double costs = 0;
     157      feasible = tourInsertionInfo.Penalty < double.Epsilon;
     158
     159      ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     160      double overloadPenalty = cvrp.OverloadPenalty.Value;
     161
     162      ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     163      DoubleArray dueTime = vrptw.DueTime;
     164      DoubleArray readyTime = vrptw.ReadyTime;
     165      DoubleArray serviceTimes = vrptw.ServiceTime;
     166      double tardinessPenalty = vrptw.TardinessPenalty.Value;
     167
     168      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     169      double newDistance =
     170        instance.GetDistance(insertionInfo.Start, customer) +
     171        instance.GetDistance(customer, insertionInfo.End);
     172      costs += instance.DistanceFactor.Value * (newDistance - distance);
     173
     174      double demand = instance.Demand[customer];
     175      if (demand > insertionInfo.SpareCapacity) {
     176        feasible = false;
     177        if (insertionInfo.SpareCapacity >= 0)
     178          costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     179        else
     180          costs += demand * overloadPenalty;
     181      }
     182
     183      double time = 0;
     184      double tardiness = 0;
     185
     186      if (index > 0)
     187        time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     188      time += instance.GetDistance(insertionInfo.Start, customer);
     189      if (time > dueTime[customer]) {
     190        tardiness += time - dueTime[customer];
     191      }
     192      if (time < readyTime[customer])
     193        time += readyTime[customer] - time;
     194      time += serviceTimes[customer];
     195      time += instance.GetDistance(customer, insertionInfo.End);
     196
     197      double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     198      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
     199        CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     200
     201        if (additionalTime < 0) {
     202          //arrive earlier than before
     203          //wait probably
     204          if (nextStop.WaitingTime < 0) {
     205            double wait = nextStop.WaitingTime - additionalTime;
     206            if (wait > 0)
     207              additionalTime += wait;
     208          } else {
     209            additionalTime = 0;
     210          }
     211
     212          //check due date, decrease tardiness
     213          if (nextStop.SpareTime < 0) {
     214            costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty;
     215          }
     216        } else {
     217          //arrive later than before, probably don't have to wait
     218          if (nextStop.WaitingTime > 0) {
     219            additionalTime -= Math.Min(additionalTime, nextStop.WaitingTime);           
     220          }
     221
     222          //check due date
     223          if (nextStop.SpareTime > 0) {
     224            double spare = nextStop.SpareTime - additionalTime;
     225            if (spare < 0)
     226              tardiness += -spare;
     227          } else {
     228            tardiness += additionalTime;
     229          }
     230        }
     231      }
     232
     233      costs += additionalTime * vrptw.TimeFactor.Value;
     234
     235      if (tardiness > 0) {
     236        feasible = false;
     237      }
     238
     239      costs += tardiness * tardinessPenalty;
     240
     241      return costs;
    124242    }
    125243
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs

    r4752 r6752  
    4141  public class SingleDepotVRPEvaluator: VRPEvaluator {
    4242    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
     43      TourInsertionInfo tourInfo = new TourInsertionInfo();
     44      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     45     
    4346      double distance = 0.0;
    4447      double quality = 0.0;
     
    5659        double currentDistace = instance.GetDistance(start, end);
    5760        distance += currentDistace;
     61
     62        StopInsertionInfo stopInfo = new StopInsertionInfo(start, end);
     63        tourInfo.AddStopInsertionInfo(stopInfo);
    5864      }
    5965
     
    6773
    6874      eval.Quality += quality;
     75    }
     76
     77    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer,
     78      out bool feasible) {
     79      StopInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index);
     80     
     81      double costs = 0;
     82      feasible = true;
     83
     84      double distance = instance.GetDistance(insertionInfo.Start, insertionInfo.End);
     85      double newDistance =
     86        instance.GetDistance(insertionInfo.Start, customer) +
     87        instance.GetDistance(customer, insertionInfo.End);
     88
     89      costs += instance.DistanceFactor.Value * (newDistance - distance);
     90
     91      return costs;
    6992    }
    7093   
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluation.cs

    r4454 r6752  
    2424using System.Linq;
    2525using System.Text;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Core;
     28using HeuristicLab.Common;
    2629
    2730namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
     31  public class StopInsertionInfo {   
     32    private int start;
     33
     34    public int Start {
     35      get { return start; }
     36    }
     37
     38    private int end;
     39
     40    public int End {
     41      get { return end; }
     42    }
     43       
     44    public StopInsertionInfo(int start, int end)
     45      : base() {
     46        this.start = start;
     47        this.end = end;
     48    }
     49  }
     50
     51  public class TourInsertionInfo {
     52    public double Penalty { get; set; }
     53
     54    private List<StopInsertionInfo> stopInsertionInfos;
     55
     56    public TourInsertionInfo()
     57      : base() {
     58      stopInsertionInfos = new List<StopInsertionInfo>();
     59    }
     60
     61    public void AddStopInsertionInfo(StopInsertionInfo info) {
     62      stopInsertionInfos.Add(info);
     63    }
     64
     65   public StopInsertionInfo GetStopInsertionInfo(int stop) {
     66      return stopInsertionInfos[stop];
     67    }
     68
     69    public int GetStopCount() {
     70      return stopInsertionInfos.Count;
     71    }
     72  }
     73
     74  public class InsertionInfo {
     75    private List<TourInsertionInfo> tourInsertionInfos;
     76   
     77    public InsertionInfo()
     78      : base() {
     79        tourInsertionInfos = new List<TourInsertionInfo>();
     80    }
     81
     82    public void AddTourInsertionInfo(TourInsertionInfo info) {     
     83      tourInsertionInfos.Add(info);
     84    }
     85
     86    public TourInsertionInfo GetTourInsertionInfo(int tour) {
     87      return tourInsertionInfos[tour];
     88    }
     89  }
     90 
    2891  public class VRPEvaluation {
    2992    public double Quality { get; set; }
    3093    public double Distance { get; set; }
    3194    public int VehicleUtilization { get; set; }
     95    public InsertionInfo InsertionInfo { get; set; }
    3296
    3397    public double Penalty { get; set; }
     98
     99    public VRPEvaluation() {
     100      InsertionInfo = new InsertionInfo();
     101    }
    34102  }
    35103}
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluator.cs

    r5127 r6752  
    109109    }
    110110
     111    protected abstract double GetTourInsertionCosts(IVRPProblemInstance instance, TourInsertionInfo tourInsertionInfo, int index, int customer, out bool feasible);
     112
     113    public double GetInsertionCosts(IVRPProblemInstance instance, VRPEvaluation eval, int customer, int tour, int index, out bool feasible) {
     114      bool tourFeasible;
     115      double costs = GetTourInsertionCosts(
     116        instance,
     117        eval.InsertionInfo.GetTourInsertionInfo(tour), index,
     118        customer, out tourFeasible);
     119
     120      feasible = tourFeasible;
     121
     122      return costs;
     123    }
     124
    111125    public VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution) {
    112126      VRPEvaluation evaluation = CreateTourEvaluation();
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r6711 r6752  
    230230    }
    231231
     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);
     234    }
     235
    232236    protected void EvalBestKnownSolution() {
    233237      if (BestKnownSolution != null) {
Note: See TracChangeset for help on using the changeset viewer.