Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/08/11 09:47:31 (13 years ago)
Author:
svonolfe
Message:

Added pairwise manipulators, removed relocation manipulator (#1177)

File:
1 edited

Legend:

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

    r6907 r6960  
    165165    }
    166166
     167    public void InsertPair(Tour tour, int source, int target, IVRPProblemInstance problemInstance, int positionToAvoid = -1, int positionToAvoid2 = -1) {
     168      int stops = tour.Stops.Count;
     169      VRPEvaluation eval = problemInstance.EvaluateTour(tour, this);
     170      double minCosts = double.MaxValue;
     171      int sourceLocation = -1;
     172      int targetLocation = -1;
     173
     174      for (int i = 0; i <= stops; i++) {
     175        tour.Stops.Insert(i, source);
     176        VRPEvaluation tourEval = problemInstance.EvaluateTour(tour, this);
     177        double sourceCosts = tourEval.Quality - eval.Quality;
     178
     179        for (int j = i + 1; j <= stops + 1; j++) {
     180          if (positionToAvoid != i || positionToAvoid2 != j || stops == 0) {
     181            bool feasible;
     182            double targetCosts = problemInstance.GetInsertionCosts(tourEval, this, target, 0, j, out feasible);
     183
     184            double costs = sourceCosts + targetCosts;
     185            if (costs < minCosts) {
     186              minCosts = costs;
     187              sourceLocation = i;
     188              targetLocation = j;
     189            }
     190          }
     191        }
     192        tour.Stops.Remove(source);
     193      }
     194
     195      tour.Stops.Insert(sourceLocation, source);
     196      tour.Stops.Insert(targetLocation, target);
     197    }
     198
    167199    public bool FindInsertionPlace(int city, int routeToAvoid, bool allowInfeasible, out int route, out int place) {
    168200      route = -1;
Note: See TracChangeset for help on using the changeset viewer.