Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6455


Ignore:
Timestamp:
06/20/11 16:45:49 (11 years ago)
Author:
svonolfe
Message:

Worked on insertion based crossover (#1561)

Location:
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinCrossover.cs

    r6449 r6455  
    115115        newTour.Cities.Remove(0);
    116116
    117       if (!newTour.Feasible(
    118         dueTime, serviceTime, readyTime, demand, capacity, distmatrix))
    119               return false;
    120 
    121117      //remove duplicates from old tours
    122118      for (int i = 0; i < newTour.Cities.Count; i++) {
     
    137133        solution.Tours.Remove(tour);
    138134      }
     135
     136      if (!newTour.Feasible(
     137        dueTime, serviceTime, readyTime, demand, capacity, distmatrix))
     138        return false;
    139139
    140140      //route unrouted vehicles
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinInsertionBasedCrossover.cs

    r6448 r6455  
    2626using HeuristicLab.Data;
    2727using System;
     28using HeuristicLab.Parameters;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
    30   [Item("PotvinInsertionBasedCrossover", "The IBX crossover for VRP representations.")]
     31  [Item("PotvinInsertionBasedCrossover", "The IBX crossover for VRP representations. It is implemented as described in Berger, J and Solois, M and Begin, R (1998). A hybrid genetic algorithm for the vehicle routing problem with time windows. LNCS 1418. Springer, London 114-127.")]
    3132  [StorableClass]
    3233  public sealed class PotvinInsertionBasedCrossover : PotvinCrossover {
     34    public IValueParameter<IntValue> Length {
     35      get { return (IValueParameter<IntValue>)Parameters["Length"]; }
     36    }
     37
    3338    [StorableConstructor]
    3439    private PotvinInsertionBasedCrossover(bool deserializing) : base(deserializing) { }
     
    4045    }
    4146    public PotvinInsertionBasedCrossover()
    42       : base() { }
     47      : base() {
     48        Parameters.Add(new ValueParameter<IntValue>("Length", "The maximum length of the replaced route.", new IntValue(1)));
     49    }
    4350
    4451    protected static int SelectRandomTourBiasedByLength(IRandom random, PotvinEncoding individual) {
     
    199206      PotvinEncoding p1Clone = parent1.Clone() as PotvinEncoding;
    200207
    201       int k = 1;//random.Next(1, Math.Min(10, parent1.Tours.Count + 1));
     208      int length = Math.Min(Length.Value.Value, parent1.Tours.Count) + 1;
     209      int k = random.Next(1, length);
    202210      for (int i = 0; i < k; i++) {
    203211        int index = SelectRandomTourBiasedByLength(random, p1Clone);
     
    254262        child.Tours.Add(childTour);
    255263        if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity)) {
    256           //success = false;
    257           //break;
     264          /*success = false;
     265          break;*/
    258266        }
    259267      }
     
    264272          child.Tours.Add(childTour);
    265273          if (!Repair(random, child, childTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity)) {
    266             //success = false;
    267             //break;
     274            /*success = false;
     275            break;*/
    268276          }
    269277        }
     
    285293        return child;
    286294      else {
    287         /* if (random.NextDouble() < 0.5)
     295        if (random.NextDouble() < 0.5)
    288296          return parent1.Clone() as PotvinEncoding;
    289297        else
    290           return parent2.Clone() as PotvinEncoding;   */
    291         return child;
     298          return parent2.Clone() as PotvinEncoding;   
    292299      }
    293300    }
Note: See TracChangeset for help on using the changeset viewer.