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
Files:
3 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;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r4376 r4377  
    5656      get { return (ValueParameter<DoubleMatrix>)Parameters["Coordinates"]; }
    5757    }
    58     protected OptionalValueParameter<DoubleMatrix> DistanceMatrixParameter {
    59       get { return (OptionalValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]; }
    60     }
    6158    protected ValueParameter<BoolValue> UseDistanceMatrixParameter {
    6259      get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; }
     
    8077      set { CoordinatesParameter.Value = value; }
    8178    }
    82     public DoubleMatrix DistanceMatrix {
    83       get { return DistanceMatrixParameter.Value; }
    84       set { DistanceMatrixParameter.Value = value; }
    85     }
     79   
     80    [Storable]
     81    public DoubleMatrix DistanceMatrix { get; set; }
     82   
    8683    public BoolValue UseDistanceMatrix {
    8784      get { return UseDistanceMatrixParameter.Value; }
     
    138135      double distance = 0.0;
    139136
    140       if (UseDistanceMatrix.Value) {
    141         if (DistanceMatrixParameter.Value != null) {
    142           distance = DistanceMatrixParameter.Value[start, end];
    143         } else {
    144           if (DistanceMatrixParameter.ActualValue == null) {
    145             DistanceMatrixParameter.ActualValue = CreateDistanceMatrix();
    146           }
    147 
    148           distance = DistanceMatrix[start, end];
    149         }
    150       } else {
     137      if (DistanceMatrix == null && UseDistanceMatrix.Value)
     138        DistanceMatrix = CreateDistanceMatrix();
     139     
     140      if(DistanceMatrix != null)
     141        distance = DistanceMatrix[start, end];
     142      else
    151143        distance = CalculateDistance(start, end);
    152       }
    153144
    154145      return distance;
     
    180171      : base() {
    181172      Parameters.Add(new ValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrix()));
    182       Parameters.Add(new OptionalValueParameter<DoubleMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
    183173      Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if a distance matrix should be calculated and used for evaluation, otherwise false.", new BoolValue(true)));
    184174      Parameters.Add(new ValueParameter<IntValue>("Vehicles", "The number of vehicles.", new IntValue(0)));
Note: See TracChangeset for help on using the changeset viewer.