Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/01/13 13:55:01 (11 years ago)
Author:
epitzer
Message:

Fix VRP FLA manipulators and adapt to VRP-3.4 (#1703)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape.VRP/Manipulators/OrOptManipulator.cs

    r9750 r9836  
    3030using HeuristicLab.Problems.VehicleRouting;
    3131using System;
     32using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3233
    3334namespace HeuristicLab.Analysis.FitnessLandscape.VRP {
     
    4748    }
    4849
    49     public static void Apply(IRandom random, PotvinEncoding individual) {
     50    public static void Apply(IRandom random, PotvinEncoding individual, IVRPProblemInstance instance, bool allowInfeasible) {
    5051      List<Tour> tours = individual.Tours.FindAll(t => t.Stops.Count >= 2);
     52      if (tours.Count == 0) return;
     53      bool feasible;
     54      int count = 0;
    5155
    52       if (tours.Count > 0) {
     56      do {
     57        feasible = true;
    5358        int tourIdx = random.Next(tours.Count);
    5459        Tour tour = tours[tourIdx];
     
    5863        if (segmentStart == 0) {
    5964          segmentLength = 1 + random.Next(tour.Stops.Count - 1);
    60         } else {
     65        }
     66        else {
    6167          segmentLength = 1 + random.Next(tour.Stops.Count - segmentStart);
    6268        }
     69
     70        bool originalFeasible = instance.TourFeasible(tour, individual);
    6371
    6472        List<int> segment = tour.Stops.GetRange(segmentStart, segmentLength);
     
    7381          newPos++;
    7482        tour.Stops.InsertRange(newPos, segment);
    75       }
     83
     84        if (!allowInfeasible && originalFeasible) {
     85          feasible = instance.TourFeasible(tour, individual);
     86          if (!feasible) {
     87            tour.Stops.RemoveRange(newPos, segment.Count);
     88            tour.Stops.InsertRange(segmentStart, segment);
     89          }
     90        }
     91      } while (!feasible && count++ < 100);
    7692    }
    7793
    7894    protected override void Manipulate(IRandom random, PotvinEncoding individual) {
    79       Apply(random, individual);
     95      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     96      Apply(random, individual, ProblemInstance, allowInfeasible);
    8097    }
    8198  }
Note: See TracChangeset for help on using the changeset viewer.