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/Encodings/Potvin/PotvinEncoding.cs

    r6710 r6752  
    3939    public List<int> Unrouted { get; set; }
    4040
    41     [Storable]
    42     public double PenaltyFactor { get; set; }
    43 
    4441    public PotvinEncoding(IVRPProblemInstance instance)
    4542      : base(instance) {
    4643      Unrouted = new List<int>();
    47       PenaltyFactor = 1;
    4844    }
    4945
     
    6056      : base(original, cloner) {
    6157        this.Unrouted = new List<int>(original.Unrouted);
    62         this.PenaltyFactor = original.PenaltyFactor;
    6358    }
    6459
     
    8782      double minQuality = -1;
    8883
     84      VRPEvaluation eval = ProblemInstance.Evaluate(tour);
     85
    8986      for (int i = 0; i <= tour.Stops.Count; i++) {
    90         tour.Stops.Insert(i, city);
    91 
    92         VRPEvaluation eval = ProblemInstance.Evaluate(tour);
    93         double quality = eval.Quality + eval.Penalty * (PenaltyFactor - 1.0);
    94 
     87        bool feasible;
     88        double quality = ProblemInstance.GetInsertionCosts(eval, city, 0, i, out feasible);
    9589        if (place < 0 || quality < minQuality) {
    9690          place = i;
    9791          minQuality = quality;
    9892        }
    99 
    100         tour.Stops.RemoveAt(i);
    10193      }
    10294
     
    110102      route = -1;
    111103      place = -1;
    112       bool bestFeasible = false;
    113104      double minDetour = double.MaxValue;
     105
     106      VRPEvaluation eval = ProblemInstance.Evaluate(this);
     107      bool originalFeasible = ProblemInstance.Feasible(eval);
    114108
    115109      for (int tour = 0; tour < Tours.Count; tour++) {
    116110        if (tour != routeToAvoid) {
    117           VRPEvaluation eval = ProblemInstance.Evaluate(Tours[tour]);
    118111          double length = eval.Quality;
    119112
    120113          for (int i = 0; i <= Tours[tour].Stops.Count; i++) {
    121             Tours[tour].Stops.Insert(i, city);
    122 
    123             eval = ProblemInstance.Evaluate(Tours[tour]);
    124             bool feasible = ProblemInstance.Feasible(eval);
    125 
    126             if (feasible || allowInfeasible && !bestFeasible) {
    127               double newLength = eval.Quality;
    128               double detour = newLength - length;
    129 
    130               if (route < 0 || detour < minDetour || feasible && !bestFeasible) {
     114            bool feasible;
     115            double detour = ProblemInstance.GetInsertionCosts(eval, city, tour, i, out feasible);
     116           
     117            if (feasible || allowInfeasible) {
     118              if (route < 0 || detour < minDetour) {
    131119                route = tour;
    132120                place = i;
    133121                minDetour = detour;
    134 
    135                 if (feasible)
    136                   bestFeasible = true;
    137122              }
    138123            }
    139 
    140             Tours[tour].Stops.RemoveAt(i);
    141124          }
    142125        }
Note: See TracChangeset for help on using the changeset viewer.