Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/10/10 11:26:30 (14 years ago)
Author:
svonolfe
Message:

Fixed performance issue in Evaluator (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs

    r4376 r4377  
    4747
    4848    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
    49       base.EvaluateTour(eval, instance, tour);
    50 
    5149      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
     50      DoubleArray demand = instance.Demand;
    5251
    5352      double delivered = 0.0;
    5453      double overweight = 0.0;
     54      double distance = 0.0;
    5555
    56       for (int i = 0; i < tour.Stops.Count; i++) {
    57         delivered += instance.Demand[tour.Stops[i]];
     56      //simulate a tour, start and end at depot
     57      for (int i = 0; i <= tour.Stops.Count; i++) {
     58        int start = 0;
     59        if (i > 0)
     60          start = tour.Stops[i - 1];
     61        int end = 0;
     62        if (i < tour.Stops.Count)
     63          end = tour.Stops[i];
     64
     65        //drive there
     66        double currentDistace = instance.GetDistance(start, end);
     67        distance += currentDistace;
     68
     69        delivered += demand[end];
    5870      }
     71
     72      eval.Quality += instance.FleetUsageFactor.Value;
     73      eval.Quality += instance.DistanceFactor.Value * distance;
     74
     75      eval.Distance = distance;
     76      eval.VehicleUtilization = 1;
    5977
    6078      double capacity = cvrpInstance.Capacity.Value;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs

    r4374 r4377  
    5151
    5252    protected override void EvaluateTour(VRPEvaluation eval, IVRPProblemInstance instance, Tour tour) {
    53       base.EvaluateTour(eval, instance, tour);
     53      IHomogenousCapacitatedProblemInstance cvrpInstance = instance as IHomogenousCapacitatedProblemInstance;
     54      DoubleArray demand = instance.Demand;
    5455
    5556      ITimeWindowedProblemInstance vrptw = instance as ITimeWindowedProblemInstance;
     57      DoubleArray dueTime = vrptw.DueTime;
     58      DoubleArray readyTime = vrptw.ReadyTime;
     59      DoubleArray serviceTimes = vrptw.ServiceTime;
    5660
    5761      double time = 0.0;
     
    5963      double serviceTime = 0.0;
    6064      double tardiness = 0.0;
     65      double delivered = 0.0;
     66      double overweight = 0.0;
     67      double distance = 0.0;
    6168
    6269      //simulate a tour, start and end at depot
     
    7279        double currentDistace = vrptw.GetDistance(start, end);
    7380        time += currentDistace;
     81        distance += currentDistace;
    7482
    7583        //check if it was serviced on time
    76         if (time > vrptw.DueTime[end])
    77           tardiness += time - vrptw.DueTime[end];
     84        if (time > dueTime[end])
     85          tardiness += time - dueTime[end];
    7886
    7987        //wait
    8088        double currentWaitingTime = 0.0;
    81         if (time < vrptw.ReadyTime[end])
    82           currentWaitingTime = vrptw.ReadyTime[end] - time;
     89        if (time < readyTime[end])
     90          currentWaitingTime = readyTime[end] - time;
    8391        waitingTime += currentWaitingTime;
    8492        time += currentWaitingTime;
    8593
    8694        //service
    87         double currentServiceTime = vrptw.ServiceTime[end];
     95        double currentServiceTime = serviceTimes[end];
    8896        serviceTime += currentServiceTime;
    8997        time += currentServiceTime;
     98        delivered += demand[end];
    9099      }
     100
     101      eval.Quality += instance.FleetUsageFactor.Value;
     102      eval.Quality += instance.DistanceFactor.Value * distance;
     103      eval.Distance = distance;
     104      eval.VehicleUtilization = 1;
     105
     106      double capacity = cvrpInstance.Capacity.Value;
     107      if (delivered > capacity) {
     108        overweight = delivered - capacity;
     109      }
     110
     111      (eval as CVRPEvaluation).Overload = overweight;
     112      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
     113      eval.Penalty += penalty;
     114      eval.Quality += penalty;
    91115
    92116      (eval as CVRPTWEvaluation).Tardiness = tardiness;
    93117      (eval as CVRPTWEvaluation).TravelTime = time;
    94118
    95       double penalty = tardiness * vrptw.TardinessPenalty.Value;
     119      penalty = tardiness * vrptw.TardinessPenalty.Value;
    96120      eval.Penalty += penalty;
    97121      eval.Quality += penalty;
Note: See TracChangeset for help on using the changeset viewer.