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/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.