Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/16/17 15:16:55 (7 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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          }
Note: See TracChangeset for help on using the changeset viewer.