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)

File:
1 edited

Legend:

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