Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/15/12 12:14:47 (13 years ago)
Author:
svonolfe
Message:

Worked on VRP path relinking (#1331)

Location:
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinCrossover.cs

    r7259 r7822  
    7474    }
    7575
    76     protected Tour FindRoute(PotvinEncoding solution, int city) {
     76    protected static Tour FindRoute(PotvinEncoding solution, int city) {
    7777      Tour found = null;
    7878
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs

    r7259 r7822  
    4040      : base() { }
    4141
    42     protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
    43       BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue;
    44       DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
    45       DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, DistanceMatrixParameter, useDistanceMatrix);
    46       DoubleArray dueTime = DueTimeParameter.ActualValue;
    47       DoubleArray readyTime = ReadyTimeParameter.ActualValue;
    48       DoubleArray serviceTime = ServiceTimeParameter.ActualValue;
    49       DoubleArray demand = DemandParameter.ActualValue;
    50       DoubleValue capacity = CapacityParameter.ActualValue;
     42    public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, bool allowInfeasible,
     43      DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity,
     44      DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) {
     45      PotvinEncoding child = parent2.Clone() as PotvinEncoding;
    5146
    52       bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
    53 
    54       PotvinEncoding child = parent2.Clone() as PotvinEncoding;
     47      DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, distanceMatrix, useDistanceMatrix);
    5548
    5649      int tourParent1 = random.Next(parent1.Tours.Count);
     
    6760          child.Unrouted.Add(city);
    6861
    69       if (Repair(random, child, replacing, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible)
     62      if (Repair(random, child, replacing, distMatrix, dueTimeArray, readyTimeArray, serviceTimeArray,
     63        demandArray, capacity, allowInfeasible) || allowInfeasible)
    7064        return child;
    7165      else {
     
    7367          return parent1.Clone() as PotvinEncoding;
    7468        else
    75           return parent2.Clone() as PotvinEncoding;   
     69          return parent2.Clone() as PotvinEncoding;
    7670      }
     71    }
     72
     73    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
     74      BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue;
     75      DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
     76      DoubleArray dueTime = DueTimeParameter.ActualValue;
     77      DoubleArray readyTime = ReadyTimeParameter.ActualValue;
     78      DoubleArray serviceTime = ServiceTimeParameter.ActualValue;
     79      DoubleArray demand = DemandParameter.ActualValue;
     80      DoubleValue capacity = CapacityParameter.ActualValue;
     81
     82      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     83
     84      return Apply(random, parent1, parent2,
     85        allowInfeasible, dueTime, serviceTime, readyTime,
     86        demand, capacity, coordinates, DistanceMatrixParameter, useDistanceMatrix);
    7787    }
    7888  }
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs

    r7259 r7822  
    4141      : base() { }
    4242
    43     protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
    44       BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue;
    45       DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
    46       DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, DistanceMatrixParameter, useDistanceMatrix);
    47       DoubleArray dueTime = DueTimeParameter.ActualValue;
    48       DoubleArray readyTime = ReadyTimeParameter.ActualValue;
    49       DoubleArray serviceTime = ServiceTimeParameter.ActualValue;
    50       DoubleArray demand = DemandParameter.ActualValue;
    51       DoubleValue capacity = CapacityParameter.ActualValue;
     43    public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, bool allowInfeasible,
     44      DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity,
     45      DoubleMatrix coordinates, IParameter distanceMatrix, BoolValue useDistanceMatrix) {
     46      PotvinEncoding child = parent1.Clone() as PotvinEncoding;
    5247
    53       bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     48      DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, distanceMatrix, useDistanceMatrix);
     49      int cities = coordinates.Rows - 1;
    5450
    55       PotvinEncoding child = parent1.Clone() as PotvinEncoding;
    5651      Tour newTour = new Tour();
    5752
    58       int breakPoint1 = random.Next(1, Cities + 1);
     53      int breakPoint1 = random.Next(1, cities + 1);
    5954      Tour tour1 = FindRoute(child, breakPoint1);
    6055      breakPoint1 = tour1.Cities.IndexOf(breakPoint1);
     
    6358        newTour.Cities.Add(tour1.Cities[i]);
    6459
    65       int breakPoint2 = random.Next(1, Cities + 1);
     60      int breakPoint2 = random.Next(1, cities + 1);
    6661      Tour tour2 = FindRoute(parent2, breakPoint2);
    6762      breakPoint2 = tour2.Cities.IndexOf(breakPoint2);
     
    8176          child.Unrouted.Add(city);
    8277
    83       if (Repair(random, child, newTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible) {
     78      if (Repair(random, child, newTour, distMatrix, dueTimeArray, readyTimeArray, serviceTimeArray,
     79        demandArray, capacity, allowInfeasible) || allowInfeasible) {
    8480        return child;
    8581      } else {
    86          if (random.NextDouble() < 0.5)
     82        if (random.NextDouble() < 0.5)
    8783          return parent1.Clone() as PotvinEncoding;
    8884        else
    89           return parent2.Clone() as PotvinEncoding;   
    90       }
     85          return parent2.Clone() as PotvinEncoding;
     86      }
     87    }
     88
     89    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
     90      BoolValue useDistanceMatrix = UseDistanceMatrixParameter.ActualValue;
     91      DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
     92      DistanceMatrix distMatrix = VRPUtilities.GetDistanceMatrix(coordinates, DistanceMatrixParameter, useDistanceMatrix);
     93      DoubleArray dueTime = DueTimeParameter.ActualValue;
     94      DoubleArray readyTime = ReadyTimeParameter.ActualValue;
     95      DoubleArray serviceTime = ServiceTimeParameter.ActualValue;
     96      DoubleArray demand = DemandParameter.ActualValue;
     97      DoubleValue capacity = CapacityParameter.ActualValue;
     98
     99      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     100
     101      return Apply(random, parent1, parent2,
     102        allowInfeasible, dueTime, serviceTime, readyTime,
     103        demand, capacity, coordinates, DistanceMatrixParameter, useDistanceMatrix);
    91104    }
    92105  }
Note: See TracChangeset for help on using the changeset viewer.