Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/11 13:59:25 (13 years ago)
Author:
epitzer
Message:

#1530 integrate changes from trunk

Location:
branches/PersistenceSpeedUp
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/PersistenceSpeedUp

  • branches/PersistenceSpeedUp/HeuristicLab.Problems.VehicleRouting

  • branches/PersistenceSpeedUp/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinCrossover.cs

    r5445 r6760  
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Data;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3334    public ILookupParameter<IRandom> RandomParameter {
    3435      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     36    }
     37
     38    public IValueParameter<BoolValue> AllowInfeasibleSolutions {
     39      get { return (IValueParameter<BoolValue>)Parameters["AllowInfeasibleSolutions"]; }
     40    }
     41
     42    [StorableHook(HookType.AfterDeserialization)]
     43    private void AfterDeserialization() {
     44      // BackwardsCompatibility3.3
     45      #region Backwards compatible code (remove with 3.4)
     46      if (!Parameters.ContainsKey("AllowInfeasibleSolutions")) {
     47        Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false)));
     48      }
     49      #endregion
    3550    }
    3651
     
    4358    public PotvinCrossover() {
    4459      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
     60      Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false)));
    4561    }
    4662
    4763    protected abstract PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2);
    4864
    49     protected bool FindInsertionPlace(PotvinEncoding individual, int city, out int route, out int place) {
     65    protected static bool FindInsertionPlace(PotvinEncoding individual, int city,
     66      DoubleArray dueTime, DoubleArray serviceTime, DoubleArray readyTime, DoubleArray demand,
     67      DoubleValue capacity, DistanceMatrix distMatrix, bool allowInfeasible,
     68      out int route, out int place) {
    5069      return individual.FindInsertionPlace(
    51         DueTimeParameter.ActualValue, ServiceTimeParameter.ActualValue, ReadyTimeParameter.ActualValue,
    52         DemandParameter.ActualValue, CapacityParameter.ActualValue, CoordinatesParameter.ActualValue,
    53         DistanceMatrixParameter, UseDistanceMatrixParameter.ActualValue,
    54         city, -1, out route, out place);
     70        dueTime, serviceTime, readyTime,
     71        demand, capacity, distMatrix,
     72        city, -1, allowInfeasible,
     73        out route, out place);
    5574    }
    5675
     
    6887    }
    6988
    70     protected bool Repair(IRandom random, PotvinEncoding solution, Tour newTour) {
     89    protected static bool RouteUnrouted(PotvinEncoding solution, DistanceMatrix distMatrix,
     90      DoubleArray dueTime, DoubleArray readyTime, DoubleArray serviceTime, DoubleArray demand, DoubleValue capacity, bool allowInfeasible) {
     91      bool success = true;
     92      int index = 0;
     93      while (index < solution.Unrouted.Count && success) {
     94        int unrouted = solution.Unrouted[index];
     95
     96        int route, place;
     97        if (FindInsertionPlace(solution, unrouted,
     98          dueTime, serviceTime, readyTime, demand, capacity,
     99          distMatrix, allowInfeasible,
     100          out route, out place)) {
     101          solution.Tours[route].Cities.Insert(place, unrouted);
     102        } else {
     103          success = false;
     104        }
     105
     106        index++;
     107      }
     108
     109      for (int i = 0; i < index; i++)
     110        solution.Unrouted.RemoveAt(0);
     111
     112      return success;
     113    }
     114
     115    protected static bool Repair(IRandom random, PotvinEncoding solution, Tour newTour, DistanceMatrix distmatrix,
     116      DoubleArray dueTime, DoubleArray readyTime, DoubleArray serviceTime, DoubleArray demand, DoubleValue capacity,
     117      bool allowInfeasible) {
    71118      bool success = true;
    72119
     
    104151      }
    105152
     153      if (!allowInfeasible && !newTour.Feasible(
     154        dueTime, serviceTime, readyTime, demand, capacity, distmatrix))
     155        return false;
     156
    106157      //route unrouted vehicles
    107       int index = 0;
    108       while (index < solution.Unrouted.Count && success) {
    109         int unrouted = solution.Unrouted[index];
    110 
    111         int route, place;
    112         if (FindInsertionPlace(solution, unrouted, out route, out place)) {
    113           solution.Tours[route].Cities.Insert(place, unrouted);
    114         } else {
    115           success = false;
    116         }
    117 
    118         index++;
    119       }
    120 
    121       for (int i = 0; i < index; i++)
    122         solution.Unrouted.RemoveAt(0);
     158      success = RouteUnrouted(solution, distmatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible);
    123159
    124160      return success;
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs

    r5445 r6760  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Data;
    2526
    2627namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    4041
    4142    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;
     51
     52      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     53
    4254      PotvinEncoding child = parent2.Clone() as PotvinEncoding;
    4355
     
    5567          child.Unrouted.Add(city);
    5668
    57       if (Repair(random, child, replacing))
     69      if (Repair(random, child, replacing, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible)
    5870        return child;
    5971      else {
     
    6173          return parent1.Clone() as PotvinEncoding;
    6274        else
    63           return parent2.Clone() as PotvinEncoding;
     75          return parent2.Clone() as PotvinEncoding;   
    6476      }
    6577    }
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs

    r5445 r6760  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Data;
    2526
    2627namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    4142
    4243    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;
     52
     53      bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
     54
    4355      PotvinEncoding child = parent1.Clone() as PotvinEncoding;
    4456      Tour newTour = new Tour();
     
    6981          child.Unrouted.Add(city);
    7082
    71       if (Feasible(newTour) &&
    72           Repair(random, child, newTour)) {
     83      if (Repair(random, child, newTour, distMatrix, dueTime, readyTime, serviceTime, demand, capacity, allowInfeasible) || allowInfeasible) {
    7384        return child;
    7485      } else {
    75         if (random.NextDouble() < 0.5)
     86         if (random.NextDouble() < 0.5)
    7687          return parent1.Clone() as PotvinEncoding;
    7788        else
    78           return parent2.Clone() as PotvinEncoding;
     89          return parent2.Clone() as PotvinEncoding;   
    7990      }
    8091    }
Note: See TracChangeset for help on using the changeset viewer.