Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/11 14:16:21 (13 years ago)
Author:
svonolfe
Message:

Merged changes from trunk (#1561) into branch (#1177)

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

Legend:

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

    r4752 r6607  
    3939    }
    4040
     41    public IValueParameter<BoolValue> AllowInfeasibleSolutions {
     42      get { return (IValueParameter<BoolValue>)Parameters["AllowInfeasibleSolutions"]; }
     43    }
     44
    4145    [StorableConstructor]
    4246    protected PotvinCrossover(bool deserializing) : base(deserializing) { }
     
    4448    public PotvinCrossover() {
    4549      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
     50      Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false)));
    4651    }
    4752
     
    5257    protected abstract PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2);
    5358
    54     protected bool FindInsertionPlace(PotvinEncoding individual, int city, out int route, out int place) {
     59    protected static bool FindInsertionPlace(PotvinEncoding individual, int city, bool allowInfeasible,
     60        out int route, out int place) {
    5561      return individual.FindInsertionPlace(
    56         city, -1, out route, out place);
     62        city, -1, allowInfeasible,
     63        out route, out place);
    5764    }
    5865
     
    7077    }
    7178
    72     protected bool Repair(IRandom random, PotvinEncoding solution, Tour newTour) {
     79    protected static bool RouteUnrouted(PotvinEncoding solution, bool allowInfeasible) {
    7380      bool success = true;
    74      
     81      int index = 0;
     82      while (index < solution.Unrouted.Count && success) {
     83        int unrouted = solution.Unrouted[index];
     84
     85        int route, place;
     86        if (FindInsertionPlace(solution, unrouted, allowInfeasible,
     87          out route, out place)) {
     88          solution.Tours[route].Stops.Insert(place, unrouted);
     89        } else {
     90          success = false;
     91        }
     92
     93        index++;
     94      }
     95
     96      for (int i = 0; i < index; i++)
     97        solution.Unrouted.RemoveAt(0);
     98
     99      return success;
     100    }
     101
     102    protected static bool Repair(IRandom random, PotvinEncoding solution, Tour newTour, IVRPProblemInstance instance, bool allowInfeasible) {
     103      bool success = true;
     104
    75105      //remove duplicates from new tour     
    76106      for (int i = 0; i < newTour.Stops.Count; i++) {
     
    106136      }
    107137
     138      if (!allowInfeasible && !instance.Feasible(newTour))
     139        return false;
     140
    108141      //route unrouted vehicles
    109       int index = 0;
    110       while (index < solution.Unrouted.Count && success) {
    111         int unrouted = solution.Unrouted[index];
    112 
    113         int route, place;
    114         if(FindInsertionPlace(solution, unrouted, out route, out place)) {
    115           solution.Tours[route].Stops.Insert(place, unrouted);
    116         } else {
    117           success = false;
    118         }
    119 
    120         index++;
    121       }
    122 
    123       for (int i = 0; i < index; i++)
    124         solution.Unrouted.RemoveAt(0);
     142      success = RouteUnrouted(solution, allowInfeasible);
    125143
    126144      return success;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs

    r4752 r6607  
    4646     
    4747    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
     48      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     49
    4850      PotvinEncoding child = parent2.Clone() as PotvinEncoding;
    4951
     
    6163          child.Unrouted.Add(city);
    6264
    63       if (Repair(random, child, replacing))
     65      if (Repair(random, child, replacing, ProblemInstance, allowInfeasible) || allowInfeasible)
    6466        return child;
    6567      else {
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs

    r4752 r6607  
    4646       
    4747    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
     48      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     49     
    4850      PotvinEncoding child = parent1.Clone() as PotvinEncoding;
    4951      Tour newTour = new Tour();
     
    7678          child.Unrouted.Add(city);
    7779
    78       if (ProblemInstance.Feasible(newTour) &&
    79           Repair(random, child, newTour)) {
     80      if (Repair(random, child, newTour, ProblemInstance, allowInfeasible) || allowInfeasible) {
    8081        return child;
    8182      } else {
Note: See TracChangeset for help on using the changeset viewer.