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/MultiDepotVRP/MDCVRP/MDCVRPTW
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWEvaluator.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);
    4745      double originalQuality = eval.Quality;
    4846
    49       IHeterogenousCapacitatedProblemInstance cvrpInstance = instance as IHeterogenousCapacitatedProblemInstance;
     47      var cvrpInstance = (IHeterogenousCapacitatedProblemInstance)instance;
    5048      DoubleArray demand = instance.Demand;
    5149
    52       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     50      var vrptw = (ITimeWindowedProblemInstance)instance;
    5351      DoubleArray dueTime = vrptw.DueTime;
    5452      DoubleArray readyTime = vrptw.ReadyTime;
    5553      DoubleArray serviceTimes = vrptw.ServiceTime;
    5654
    57       IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     55      var pdp = (IPickupAndDeliveryProblemInstance)instance;
    5856      IntArray pickupDeliveryLocation = pdp.PickupDeliveryLocation;
    5957
    60       IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
     58      var mdp = (IMultiDepotProblemInstance)instance;
    6159      IntArray vehicleAssignment = mdp.VehicleDepotAssignment;
    6260      int depots = mdp.Depots.Value;
     
    8179      double tourStartTime = readyTime[0];
    8280      time = tourStartTime;
     81
     82      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime);
     83      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    8384
    8485      //simulate a tour, start and end at depot
     
    9293
    9394        //drive there
    94         double currentDistace = vrptw.GetDistance(start, end, solution);
    95         time += currentDistace;
    96         distance += currentDistace;
     95        double currentDistance = vrptw.GetDistance(start, end, solution);
     96        time += currentDistance;
     97        distance += currentDistance;
    9798
    9899        double arrivalTime = time;
     
    129130          //Pickup / deliver
    130131          bool validPickupDelivery =
    131             validPickupDelivery =
    132132            ((demand[end - 1] >= 0) ||
    133133             (stops.ContainsKey(pickupDeliveryLocation[end - 1])));
     
    144144
    145145        double spareCapacity = capacity - currentLoad;
    146         CVRPPDTWInsertionInfo stopInfo = new CVRPPDTWInsertionInfo(start, end, spareCapacity, tourStartTime,
     146        var stopInfo = new CVRPPDTWStopInsertionInfo(start, end, currentDistance, spareCapacity,
    147147          arrivalTime, time, spareTime, waitTime, new List<int>(stops.Keys), arrivalSpareCapacity);
    148148        tourInfo.AddStopInsertionInfo(stopInfo);
     
    156156      eval.VehicleUtilization += 1;
    157157
    158       (eval as CVRPEvaluation).Overload += overweight;
     158      ((CVRPEvaluation)eval).Overload += overweight;
    159159      double tourPenalty = 0;
    160160      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    163163      tourPenalty += penalty;
    164164
    165       (eval as CVRPTWEvaluation).Tardiness += tardiness;
     165      ((CVRPTWEvaluation)eval).Tardiness += tardiness;
    166166      (eval as CVRPTWEvaluation).TravelTime += time;
    167167
     
    171171      tourPenalty += penalty;
    172172
    173       (eval as CVRPPDTWEvaluation).PickupViolations += pickupViolations;
     173      ((CVRPPDTWEvaluation)eval).PickupViolations += pickupViolations;
    174174      penalty = pickupViolations * pdp.PickupViolationPenalty.Value;
    175175      eval.Penalty += penalty;
     
    184184    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    185185      out bool feasible) {
    186       CVRPPDTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPPDTWInsertionInfo;
     186      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     187      var insertionInfo = (CVRPPDTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    187188
    188189      double costs = 0;
     
    230231
    231232      if (index > 0)
    232         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     233        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    233234      else
    234         time = insertionInfo.TourStartTime;
     235        time = tourInfo.TourStartTime;
    235236
    236237      time += startDistance;
     
    246247      time += endDistance;
    247248
    248       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     249      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    249250      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    250         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     251        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    251252
    252253        if (demand >= 0) {
  • branches/OptimizationNetworks/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPTWEvaluator.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);
    5048      double originalQuality = eval.Quality;
    5149
    52       IHeterogenousCapacitatedProblemInstance cvrpInstance = instance as IHeterogenousCapacitatedProblemInstance;
     50      var cvrpInstance = (IHeterogenousCapacitatedProblemInstance)instance;
    5351      DoubleArray demand = instance.Demand;
    54 
    55       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     52     
     53      var vrptw = (ITimeWindowedProblemInstance)instance;
    5654      DoubleArray dueTime = vrptw.DueTime;
    5755      DoubleArray readyTime = vrptw.ReadyTime;
    5856      DoubleArray serviceTimes = vrptw.ServiceTime;
    5957
    60       IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
     58      var mdp = (IMultiDepotProblemInstance)instance;
    6159      IntArray vehicleAssignment = mdp.VehicleDepotAssignment;
    6260      int depots = mdp.Depots.Value;
     
    7573
    7674      double capacity = cvrpInstance.Capacity[vehicle];
    77       for (int i = 0; i < tour.Stops.Count; i++) {
    78         delivered += instance.GetDemand(tour.Stops[i]);
    79       }
    80 
    81       double spareCapacity = capacity - delivered;
    8275
    8376      double tourStartTime = vrptw.ReadyTime[depot];
    8477      time = tourStartTime;
     78
     79      var tourInfo = new CVRPTWTourInsertionInfo(solution.GetVehicleAssignment(solution.GetTourIndex(tour)), capacity, tourStartTime);
     80      eval.InsertionInfo.AddTourInsertionInfo(tourInfo);
    8581
    8682      //simulate a tour, start and end at depot
     
    9086          start = tour.Stops[i - 1];
    9187        int end = 0;
    92         if (i < tour.Stops.Count)
     88        if (i < tour.Stops.Count) {
    9389          end = tour.Stops[i];
     90          delivered += instance.GetDemand(end);
     91        }
    9492
    9593        //drive there
    96         double currentDistace = vrptw.GetDistance(start, end, solution);
    97         time += currentDistace;
    98         distance += currentDistace;
     94        double currentDistance = vrptw.GetDistance(start, end, solution);
     95        time += currentDistance;
     96        distance += currentDistance;
    9997
    10098        double arrivalTime = time;
     
    129127        time += currentServiceTime;
    130128
    131         CVRPTWInsertionInfo stopInfo = new CVRPTWInsertionInfo(start, end, spareCapacity, tourStartTime, arrivalTime, time, spareTime, waitTime);
     129        var stopInfo = new CVRPTWStopInsertionInfo(start, end, currentDistance, capacity - delivered, arrivalTime, time, spareTime, waitTime);
    132130        tourInfo.AddStopInsertionInfo(stopInfo);
    133131      }
     
    142140      }
    143141
    144       (eval as CVRPEvaluation).Overload += overweight;
     142      ((CVRPEvaluation)eval).Overload += overweight;
    145143      double tourPenalty = 0;
    146144      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     
    149147      tourPenalty += penalty;
    150148
    151       (eval as CVRPTWEvaluation).Tardiness += tardiness;
    152       (eval as CVRPTWEvaluation).TravelTime += time;
     149      ((CVRPTWEvaluation)eval).Tardiness += tardiness;
     150      ((CVRPTWEvaluation)eval).TravelTime += time;
    153151
    154152      penalty = tardiness * vrptw.TardinessPenalty.Value;
     
    163161    protected override double GetTourInsertionCosts(IVRPProblemInstance instance, IVRPEncoding solution, TourInsertionInfo tourInsertionInfo, int index, int customer,
    164162      out bool feasible) {
    165       CVRPTWInsertionInfo insertionInfo = tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo;
     163      var tourInfo = (CVRPTWTourInsertionInfo)tourInsertionInfo;
     164      var insertionInfo = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index);
    166165
    167166      double costs = 0;
    168167      feasible = tourInsertionInfo.Penalty < double.Epsilon;
    169168
    170       ICapacitatedProblemInstance cvrp = instance as ICapacitatedProblemInstance;
     169      var cvrp = (ICapacitatedProblemInstance)instance;
    171170      double overloadPenalty = cvrp.OverloadPenalty.Value;
    172171
    173       ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     172      var vrptw = (ITimeWindowedProblemInstance)instance;
    174173      DoubleArray dueTime = vrptw.DueTime;
    175174      DoubleArray readyTime = vrptw.ReadyTime;
     
    177176      double tardinessPenalty = vrptw.TardinessPenalty.Value;
    178177
    179       IMultiDepotProblemInstance mdp = instance as IMultiDepotProblemInstance;
     178      var mdp = (IMultiDepotProblemInstance)instance;
    180179      int depots = mdp.Depots.Value;
    181180
     
    184183
    185184      double demand = instance.GetDemand(customer);
    186       if (demand > insertionInfo.SpareCapacity) {
     185      if (demand > tourInfo.SpareCapacity) {
    187186        feasible = false;
    188187
    189         if (insertionInfo.SpareCapacity >= 0)
    190           costs += (demand - insertionInfo.SpareCapacity) * overloadPenalty;
     188        if (tourInfo.SpareCapacity >= 0)
     189          costs += (demand - tourInfo.SpareCapacity) * overloadPenalty;
    191190        else
    192191          costs += demand * overloadPenalty;
     
    197196
    198197      if (index > 0)
    199         time = (tourInsertionInfo.GetStopInsertionInfo(index - 1) as CVRPTWInsertionInfo).LeaveTime;
     198        time = ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index - 1)).LeaveTime;
    200199      else
    201         time = insertionInfo.TourStartTime;
     200        time = tourInfo.TourStartTime;
    202201
    203202      time += startDistance;
     
    213212      time += endDistance;
    214213
    215       double additionalTime = time - (tourInsertionInfo.GetStopInsertionInfo(index) as CVRPTWInsertionInfo).ArrivalTime;
     214      double additionalTime = time - ((CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(index)).ArrivalTime;
    216215      for (int i = index; i < tourInsertionInfo.GetStopCount(); i++) {
    217         CVRPTWInsertionInfo nextStop = tourInsertionInfo.GetStopInsertionInfo(i) as CVRPTWInsertionInfo;
     216        var nextStop = (CVRPTWStopInsertionInfo)tourInsertionInfo.GetStopInsertionInfo(i);
    218217
    219218        if (additionalTime < 0) {
     
    270269      base.SetResultParameters(tourEvaluation);
    271270
    272       TardinessParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).Tardiness;
    273       TravelTimeParameter.ActualValue.Value = (tourEvaluation as CVRPTWEvaluation).TravelTime;
     271      TardinessParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).Tardiness;
     272      TravelTimeParameter.ActualValue.Value = ((CVRPTWEvaluation)tourEvaluation).TravelTime;
    274273    }
    275274
Note: See TracChangeset for help on using the changeset viewer.