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/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
Note: See TracChangeset for help on using the changeset viewer.