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)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs

    r6710 r6752  
    156156        return false;
    157157
    158       bool bestFeasible = false;
     158      if (tour.Stops.Count == 0) {
     159        place = 0;
     160        return true;
     161      }
     162
    159163      double minDetour = 0;
    160 
    161164      VRPEvaluation eval = ProblemInstance.Evaluate(tour);
    162       double length = eval.Quality;
     165      bool originalFeasible = ProblemInstance.Feasible(eval);
     166
    163167      for (int i = 0; i <= tour.Stops.Count; i++) {
    164         tour.Stops.Insert(i, city);
    165 
    166         eval = ProblemInstance.Evaluate(tour);
    167         bool feasible = ProblemInstance.Feasible(eval);
    168 
    169         if (feasible || allowInfeasible && !bestFeasible) {
    170           double newLength = eval.Quality;
    171           double detour = newLength - length;
    172 
    173           if (place < 0 || detour < minDetour || feasible && !bestFeasible) {
     168        bool feasible;
     169        double detour = ProblemInstance.GetInsertionCosts(eval, city, 0, i, out feasible);
     170        if (feasible || allowInfeasible) {
     171          if (place < 0 || detour < minDetour) {
    174172            place = i;
    175173            minDetour = detour;
    176 
    177             if (feasible)
    178               bestFeasible = true;
    179174          }
    180175        }
    181 
    182         tour.Stops.RemoveAt(i);
    183176      }
    184177
     
    248241
    249242          int place = -1;
    250           if (FindRouteInsertionPlace(childTour, city, allowInfeasible, out place)) {
     243          bool found = FindRouteInsertionPlace(childTour, city, allowInfeasible, out place);
     244          if (found) {
    251245            childTour.Stops.Insert(place, city);
    252246
  • 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.