Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/16/17 15:16:55 (8 years ago)
Author:
abeham
Message:

#2205: added results tab to solution view to analyze vrp solution in more detail

  • reorganized insertion infos and adapted some evaluators and instances
Location:
branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluation.cs

    r14185 r14677  
    2323
    2424namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
    25   public class CVRPPDTWInsertionInfo : CVRPTWInsertionInfo {
     25  public class CVRPPDTWStopInsertionInfo : CVRPTWStopInsertionInfo {
    2626    private List<int> visited;
    2727
     
    3636    }
    3737
    38     public CVRPPDTWInsertionInfo(int start, int end, double spareCapacity, double tourStartTime,
     38    public CVRPPDTWStopInsertionInfo(int start, int end, double distance, double spareCapacity,
    3939      double arrivalTime, double leaveTime, double spareTime, double waitingTime, List<int> visited, double arrivalSpareCapacity)
    40       : base(start, end, spareCapacity, tourStartTime, arrivalTime, leaveTime, spareTime, waitingTime) {
     40      : base(start, end, distance, spareCapacity, arrivalTime, leaveTime, spareTime, waitingTime) {
    4141      this.visited = visited;
    4242      this.arrivalSpareCapacity = arrivalSpareCapacity;
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPPDTW/CVRPPDTWEvaluator.cs

    r14185 r14677  
    4343
    4444    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    45       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    46       eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     45      var cvrpInstance = (IHomogenousCapacitatedProblemInstance)instance;
     46      double capacity = cvrpInstance.Capacity.Value;
    4747      double originalQuality = eval.Quality;
    4848
    49       IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    5049      DoubleArray demand = instance.Demand;
    5150
    52       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     51      var vrptw = (ITimeWindowedProblemInstance)instance;
    5352      DoubleArray dueTime = vrptw.DueTime;
    5453      DoubleArray readyTime = vrptw.ReadyTime;
    5554      DoubleArray serviceTimes = vrptw.ServiceTime;
    5655
    57       IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     56      var pdp = (IPickupAndDeliveryProblemInstance)instance;
    5857      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;
    5958
    60       double capacity = cvrpInstance.Capacity.Value;
    6159
    6260      double time = 0.0;
     
    7371      double tourStartTime = readyTime[0];
    7472      time = tourStartTime;
     73
     74      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime);
     75      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    7576
    7677      //simulate a tour, start and end at depot
     
    8485
    8586        //drive there
    86         double currentDistace = vrptw.GetDistance(start, end, solution);
    87         time += currentDistace;
    88         distance += currentDistace;
     87        double currentDistance = vrptw.GetDistance(start, end, solution);
     88        time += currentDistance;
     89        distance += currentDistance;
    8990
    9091        double arrivalTime = time;
     
    115116
    116117        bool validPickupDelivery =
    117           validPickupDelivery =
    118118          ((demand[end] >= 0) ||
    119119           (stops.ContainsKey(pickupDeliveryLocation[end])));
     
    129129
    130130        double spareCapacity = capacity - currentLoad;
    131         CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,
     131        var stopInfo = new CVRPPDTWStopInsertionInfo(start, end, currentDistance, spareCapacity,
    132132          arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity);
    133133        tourInfo.AddStopInsertionInfo(stopInfo);
     
    141141      eval.VehicleUtilization += 1;
    142142
    143       (eval as CVRPEvaluation).Overload += overweight;
     143      ((CVRPEvaluation)eval).Overload += overweight;
    144144      double tourPenalty = 0;
    145145      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    148148      tourPenalty += penalty;
    149149
    150       (eval as CVRPTWEvaluation).Tardiness += tardiness;
    151       (eval as CVRPTWEvaluation).TravelTime += time;
     150      ((CVRPTWEvaluation)eval).Tardiness += tardiness;
     151      ((CVRPTWEvaluation)eval).TravelTime += time;
    152152
    153153      penalty = tardiness * vrptw.TardinessPenalty.Value;
     
    156156      tourPenalty += penalty;
    157157
    158       (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
     158      ((CVRPPDTWEvaluation)eval).PickupViolations += pickupViolations;
    159159      penalty = pickupViolations * pdp.PickupViolationPenalty.Value;
    160160      eval.Penalty += penalty;
     
    169169    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    170170      out bool feasible) {
    171       CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo;
     171      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     172      var insertionInfo = (CVRPPDTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    172173
    173174      double costs = 0;
     
    175176      bool tourFeasible = true;
    176177
    177       ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     178      var cvrp = (ICapacitatedProblemInstance)instance;
    178179      double overloadPenalty = cvrp.OverloadPenalty.Value;
    179180
    180       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     181      var vrptw = (ITimeWindowedProblemInstance)instance;
    181182      DoubleArray dueTime = vrptw.DueTime;
    182183      DoubleArray readyTime = vrptw.ReadyTime;
     
    184185      double tardinessPenalty = vrptw.TardinessPenalty.Value;
    185186
    186       IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     187      IPickupAndDeliveryProblemInstance pdp = (IPickupAndDeliveryProblemInstance)instance;
    187188      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;
    188189      double pickupPenalty = pdp.PickupViolationPenalty.Value;
     
    215216
    216217      if (index > 0)
    217         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     218        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    218219      else
    219         time = insertionInfo.TourStartTime;
     220        time = tourInfo.TourStartTime;
    220221
    221222      time += instance.GetDistance(insertionInfo.Start, customer, solution);
     
    228229      time += instance.GetDistance(customer, insertionInfo.End, solution);
    229230
    230       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     231      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    231232      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    232         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     233        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    233234
    234235        if (demand >= 0) {
     
    246247        } else if (validPickup) {
    247248          if (nextStop.SpareCapacity < 0) {
     249            // ABE: The costs decrease when there is overload!?
    248250            costs += Math.Max(demand, nextStop.SpareCapacity) * overloadPenalty;
    249251          }
     
    263265          //check due date, decrease tardiness
    264266          if (nextStop.SpareTime < 0) {
     267            // ABE: Again, the costs decrease when there is tardiness!?
    265268            costs += Math.Max(nextStop.SpareTime, additionalTime) * tardinessPenalty;
    266269          }
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluation.cs

    r14185 r14677  
    2020#endregion
    2121
     22using System;
     23using System.Globalization;
     24using System.Text;
    2225
    2326namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
    24   public class CVRPTWInsertionInfo : CVRPInsertionInfo {
    25     private double tourStartTime;
    26 
    27     public double TourStartTime {
    28       get { return tourStartTime; }
    29     }
     27  public class CVRPTWStopInsertionInfo : CVRPStopInsertionInfo {
    3028
    3129    private double arrivalTime;
     
    5351    }
    5452
    55     public CVRPTWInsertionInfo(int start, int end, double spareCapacity, double tourStartTime, double arrivalTime, double leaveTime, double spareTime, double waitingTime)
    56       : base(start, end, spareCapacity) {
    57       this.tourStartTime = tourStartTime;
     53    public CVRPTWStopInsertionInfo(int start, int end, double distance, double spareCapacity, double arrivalTime, double leaveTime, double spareTime, double waitingTime)
     54      : base(start, end, distance, spareCapacity) {
    5855      this.arrivalTime = arrivalTime;
    5956      this.leaveTime = leaveTime;
    6057      this.spareTime = spareTime;
    6158      this.waitingTime = waitingTime;
     59    }
     60
     61    protected override void GetStopInsertionReport(StringBuilder builder) {
     62      base.GetStopInsertionReport(builder);
     63      builder.Append("SpareTime:\t");
     64      builder.AppendLine(SpareTime.ToString(CultureInfo.CurrentCulture));
     65      builder.Append("ArrivalTime:\t");
     66      builder.AppendLine(ArrivalTime.ToString(CultureInfo.CurrentCulture));
     67      builder.Append("WaitingTime:\t");
     68      builder.AppendLine(Math.Max(0, WaitingTime).ToString(CultureInfo.CurrentCulture));
     69      builder.Append("LeaveTime:\t");
     70      builder.AppendLine(LeaveTime.ToString(CultureInfo.CurrentCulture));
     71    }
     72  }
     73
     74  public class CVRPTWTourInsertionInfo : CVRPTourInsertionInfo {
     75    private double tourStartTime;
     76
     77    public double TourStartTime {
     78      get { return tourStartTime; }
     79    }
     80
     81    public CVRPTWTourInsertionInfo(int vehicle, double capacity, double tourStartTime)
     82      : base(vehicle, capacity) {
     83      this.tourStartTime = tourStartTime;
     84    }
     85
     86    protected override void GetTourInsertionReport(StringBuilder builder) {
     87      base.GetTourInsertionReport(builder);
     88      builder.Append("Tour start:\t");
     89      builder.AppendLine(TourStartTime.ToString(CultureInfo.CurrentCulture));
    6290    }
    6391  }
     
    6694    public double Tardiness { get; set; }
    6795    public double TravelTime { get; set; }
     96
     97    protected override void GetEvaluationReport(StringBuilder builder) {
     98      base.GetEvaluationReport(builder);
     99      builder.Append("TravelTime:\t");
     100      builder.AppendLine(TravelTime.ToString(CultureInfo.CurrentCulture));
     101      builder.Append("Tardiness:\t");
     102      builder.AppendLine(Tardiness.ToString(CultureInfo.CurrentCulture));
     103    }
    68104  }
    69105}
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs

    r14185 r14677  
    4646
    4747    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour, IVRPEncoding solution) {
    48       TourInsertionInfo tourInfo = new TourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)));
    49       eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
     48      var cvrpInstance = (IHomogenousCapacitatedProblemInstance)instance;
     49
    5050      double originalQuality = eval.Quality;
    5151
    52       IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
    5352      DoubleArray demand = instance.Demand;
    5453
    55       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     54      var vrptw = (ITimeWindowedProblemInstance)instance;
    5655      DoubleArray dueTime = vrptw.DueTime;
    5756      DoubleArray readyTime = vrptw.ReadyTime;
     
    6766
    6867      double capacity = cvrpInstance.Capacity.Value;
    69       for (int i = 0; i <= tour.Stops.Count; i++) {
    70         int end = 0;
    71         if (i < tour.Stops.Count)
    72           end = tour.Stops[i];
    73 
    74         delivered += demand[end];
    75       }
    76 
    77       double spareCapacity = capacity - delivered;
    78 
     68     
    7969      double tourStartTime = readyTime[0];
    8070      time = tourStartTime;
     71
     72      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), cvrpInstance.Capacity.Value, tourStartTime);
     73      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    8174
    8275      //simulate a tour, start and end at depot
     
    9083
    9184        //drive there
    92         double currentDistace = vrptw.GetDistance(start, end, solution);
    93         time += currentDistace;
    94         distance += currentDistace;
     85        double currentDistance = vrptw.GetDistance(start, end, solution);
     86        time += currentDistance;
     87        distance += currentDistance;
     88        delivered += demand[end];
    9589
    9690        double arrivalTime = time;
     
    117111        time += currentServiceTime;
    118112
    119         CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);
     113        var stopInfo = new CVRPTWStopInsertionInfo(start, end, currentDistance, capacity - delivered, arrivalTime, time, spareTime, waitTime);
    120114        tourInfo.AddStopInsertionInfo(stopInfo);
    121115      }
     
    130124      }
    131125
    132       (eval as CVRPEvaluation).Overload += overweight;
     126      ((CVRPEvaluation)eval).Overload += overweight;
    133127      double tourPenalty = 0;
    134128      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    151145    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    152146      out bool feasible) {
    153       CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
     147      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     148      var insertionInfo = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    154149
    155150      double costs = 0;
    156151      feasible = tourInsertionInfo.Penalty < double.Epsilon;
    157152
    158       ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     153      var cvrp = (ICapacitatedProblemInstance)instance;
    159154      double overloadPenalty = cvrp.OverloadPenalty.Value;
    160155
    161       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     156      var vrptw = (ITimeWindowedProblemInstance)instance;
    162157      DoubleArray dueTime = vrptw.DueTime;
    163158      DoubleArray readyTime = vrptw.ReadyTime;
     
    172167
    173168      double demand = instance.Demand[customer];
    174       if (demand > insertionInfo.SpareCapacity) {
     169      if (demand > tourInfo.SpareCapacity) {
    175170        feasible = false;
    176         if (insertionInfo.SpareCapacity >= 0)
    177           costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     171        if (tourInfo.SpareCapacity >= 0)
     172          costs += (demand - tourInfo.SpareCapacity) * overloadPenalty;
    178173        else
    179174          costs += demand * overloadPenalty;
     
    184179
    185180      if (index > 0)
    186         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     181        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    187182      else
    188         time = insertionInfo.TourStartTime;
     183        time = tourInfo.TourStartTime;
    189184
    190185      time += instance.GetDistance(insertionInfo.Start, customer, solution);
     
    197192      time += instance.GetDistance(customer, insertionInfo.End, solution);
    198193
    199       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     194      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    200195      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    201         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     196        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    202197
    203198        if (additionalTime < 0) {
     
    254249      base.SetResultParameters(tourEvaluation);
    255250
    256       TardinessParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).Tardiness;
    257       TravelTimeParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).TravelTime;
     251      TardinessParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).Tardiness;
     252      TravelTimeParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).TravelTime;
    258253    }
    259254
Note: See TracChangeset for help on using the changeset viewer.