Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4378 for branches


Ignore:
Timestamp:
09/10/10 13:00:54 (14 years ago)
Author:
svonolfe
Message:

Improved performance of PotvinEncoding(#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Moves/AlbaMoveMaker.cs

    r4369 r4378  
    3939      : base() {
    4040    }
    41 
    42     public override IOperation Apply() {
    43       IVRPEncoding solution = VRPToursParameter.ActualValue;
    44       if (!(solution is AlbaEncoding)) {
    45         //VRPToursParameter.ActualValue = AlbaEncoding.ConvertFrom(solution, VehiclesParameter.ActualValue.Value,
    46         //  DistanceMatrixParameter);
    47       }
    48 
    49       return base.Apply();
    50     }
    5141  }
    5242}
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/PotvinEncoding.cs

    r4376 r4378  
    9999      for (int tour = 0; tour < Tours.Count; tour++) {
    100100        if (tour != routeToAvoid) {
     101          double length = GetTourLength(Tours[tour]);
     102
    101103          for (int i = 0; i <= Tours[tour].Stops.Count; i++) {
    102             double length = GetTourLength(Tours[tour]);
    103 
    104104            Tours[tour].Stops.Insert(i, city);
    105105
    106             if (ProblemInstance.Feasible(Tours[tour])) {
    107               double newLength = GetTourLength(Tours[tour]);
     106            VRPEvaluation eval = ProblemInstance.EvaluatorParameter.Value.Evaluate(
     107              ProblemInstance, Tours[tour]);
     108            if (ProblemInstance.EvaluatorParameter.Value.Feasible(eval)) {
     109              double newLength = eval.Distance;
    108110
    109111              double detour = newLength - length;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Interfaces/IVRPEvaluator.cs

    r4369 r4378  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Optimization;
     28using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting.Interfaces {
     
    3132    ILookupParameter<IVRPEncoding> VRPToursParameter { get; }
    3233   
    33     bool Feasible(IVRPProblemInstance instance, IVRPEncoding solution);
    34     bool Feasible(IVRPProblemInstance instance, Tour tour);
    35     double Evaluate(IVRPProblemInstance instance, IVRPEncoding solution);
    36     double Evaluate(IVRPProblemInstance instance, Tour tour);
     34    VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution);
     35    VRPEvaluation Evaluate(IVRPProblemInstance instance, Tour tour);
     36    bool Feasible(VRPEvaluation evaluation);
    3737  }
    3838}
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPEvaluator.cs

    r4377 r4378  
    7373      eval.Quality += instance.DistanceFactor.Value * distance;
    7474
    75       eval.Distance = distance;
    76       eval.VehicleUtilization = 1;
     75      eval.Distance += distance;
     76      eval.VehicleUtilization += 1;
    7777
    7878      double capacity = cvrpInstance.Capacity.Value;
     
    8181      }
    8282
    83       (eval as CVRPEvaluation).Overload = overweight;
     83      (eval as CVRPEvaluation).Overload += overweight;
    8484      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
    8585      eval.Penalty += penalty;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/CVRP/CVRPTW/CVRPTWEvaluator.cs

    r4377 r4378  
    101101      eval.Quality += instance.FleetUsageFactor.Value;
    102102      eval.Quality += instance.DistanceFactor.Value * distance;
    103       eval.Distance = distance;
    104       eval.VehicleUtilization = 1;
     103      eval.Distance += distance;
     104      eval.VehicleUtilization += 1;
    105105
    106106      double capacity = cvrpInstance.Capacity.Value;
     
    109109      }
    110110
    111       (eval as CVRPEvaluation).Overload = overweight;
     111      (eval as CVRPEvaluation).Overload += overweight;
    112112      double penalty = overweight * cvrpInstance.OverloadPenalty.Value;
    113113      eval.Penalty += penalty;
    114114      eval.Quality += penalty;
    115115
    116       (eval as CVRPTWEvaluation).Tardiness = tardiness;
    117       (eval as CVRPTWEvaluation).TravelTime = time;
     116      (eval as CVRPTWEvaluation).Tardiness += tardiness;
     117      (eval as CVRPTWEvaluation).TravelTime += time;
    118118
    119119      penalty = tardiness * vrptw.TardinessPenalty.Value;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/SingleDepotVRP/SingleDepotVRPEvaluator.cs

    r4363 r4378  
    6262      quality += instance.DistanceFactor.Value * distance;
    6363
    64       eval.Distance = distance;
    65       eval.VehicleUtilization = 1;
     64      eval.Distance += distance;
     65      eval.VehicleUtilization += 1;
    6666
    67       eval.Quality = quality;
     67      eval.Quality += quality;
    6868    }
    6969   
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPEvaluator.cs

    r4376 r4378  
    8484    }
    8585
    86     protected VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour) {
     86    private VRPEvaluation EvaluateTour(IVRPProblemInstance instance, Tour tour) {
    8787      VRPEvaluation evaluation = CreateTourEvaluation();
    8888      EvaluateTour(evaluation, instance, tour);
     
    9292    #region IVRPEvaluator Members
    9393
    94     public bool Feasible(IVRPProblemInstance instance, IVRPEncoding solution) {
    95       bool feasible = true;
     94    public bool Feasible(VRPEvaluation evaluation) {
     95      return evaluation.Penalty < double.Epsilon;
     96    }
     97
     98    public VRPEvaluation Evaluate(IVRPProblemInstance instance, IVRPEncoding solution) {
     99      VRPEvaluation evaluation = CreateTourEvaluation();
    96100
    97101      foreach (Tour tour in solution.GetTours()) {
    98         if (!Feasible(instance, tour)) {
    99           feasible = false;
    100           break;
    101         }
     102        EvaluateTour(evaluation, instance, tour);
    102103      }
    103104
    104       return feasible;
     105      return evaluation;
    105106    }
    106107
    107     public bool Feasible(IVRPProblemInstance instance, Tour tour) {
    108       return EvaluateTour(instance, tour).Penalty < double.Epsilon;
    109     }
    110 
    111     public double Evaluate(IVRPProblemInstance instance, IVRPEncoding solution) {
    112       double quality = 0;
    113 
    114       foreach (Tour tour in solution.GetTours()) {
    115         quality += Evaluate(instance, tour);
    116       }
    117 
    118       return quality;
    119     }
    120 
    121     public double Evaluate(IVRPProblemInstance instance, Tour tour) {
    122       return EvaluateTour(instance, tour).Quality;
     108    public VRPEvaluation Evaluate(IVRPProblemInstance instance, Tour tour) {
     109      return EvaluateTour(instance, tour);
    123110    }
    124111
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/VRPProblemInstance.cs

    r4377 r4378  
    147147
    148148    public bool Feasible(IVRPEncoding solution) {
    149       return EvaluatorParameter.Value.Feasible(this, solution);
     149      return EvaluatorParameter.Value.Feasible(
     150        EvaluatorParameter.Value.Evaluate(
     151          this, solution));
    150152    }
    151153
    152154    public bool Feasible(Tour tour) {
    153       return EvaluatorParameter.Value.Feasible(this, tour);
     155      return EvaluatorParameter.Value.Feasible(
     156        EvaluatorParameter.Value.Evaluate(
     157        this, tour));
    154158    }
    155159
    156160    public double Evaluate(IVRPEncoding solution) {
    157       return EvaluatorParameter.Value.Evaluate(this, solution);
     161      return EvaluatorParameter.Value.Evaluate(this, solution).Quality;
    158162    }
    159163
    160164    public double Evaluate(Tour tour) {
    161       return EvaluatorParameter.Value.Evaluate(this, tour);
     165      return EvaluatorParameter.Value.Evaluate(this, tour).Quality;
    162166    }
    163167
Note: See TracChangeset for help on using the changeset viewer.