Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/06/10 01:56:04 (14 years ago)
Author:
swagner
Message:

Merged cloning refactoring branch back into trunk (#922)

Location:
trunk/sources
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Problems.VehicleRouting

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

    r4352 r4722  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using HeuristicLab.Common;
    2224using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
     25using HeuristicLab.Optimization;
    2426using HeuristicLab.Parameters;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Optimization;
    28 using System.Collections.Generic;
    2928
    3029namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3837    [StorableConstructor]
    3938    protected PotvinCrossover(bool deserializing) : base(deserializing) { }
     39    protected PotvinCrossover(PotvinCrossover original, Cloner cloner)
     40      : base(original, cloner) {
     41    }
    4042
    4143    public PotvinCrossover() {
     
    6870    protected bool Repair(IRandom random, PotvinEncoding solution, Tour newTour) {
    6971      bool success = true;
    70      
     72
    7173      //remove duplicates from new tour     
    7274      for (int i = 0; i < newTour.Cities.Count; i++) {
     
    8082        }
    8183      }
    82       while(newTour.Cities.Contains(0))
     84      while (newTour.Cities.Contains(0))
    8385        newTour.Cities.Remove(0);
    8486
     
    108110
    109111        int route, place;
    110         if(FindInsertionPlace(solution, unrouted, out route, out place)) {
     112        if (FindInsertionPlace(solution, unrouted, out route, out place)) {
    111113          solution.Tours[route].Cities.Insert(place, unrouted);
    112114        } else {
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs

    r4352 r4722  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
    24 using HeuristicLab.Parameters;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Data;
    2725
    2826namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3230    [StorableConstructor]
    3331    private PotvinRouteBasedCrossover(bool deserializing) : base(deserializing) { }
    34 
     32    private PotvinRouteBasedCrossover(PotvinRouteBasedCrossover original, Cloner cloner)
     33      : base(original, cloner) {
     34    }
     35    public override IDeepCloneable Clone(Cloner cloner) {
     36      return new PotvinRouteBasedCrossover(this, cloner);
     37    }
    3538    public PotvinRouteBasedCrossover()
    3639      : base() { }
    37      
     40
    3841    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
    3942      PotvinEncoding child = parent2.Clone() as PotvinEncoding;
     
    5558        return child;
    5659      else {
    57         if(random.NextDouble() < 0.5)
     60        if (random.NextDouble() < 0.5)
    5861          return parent1.Clone() as PotvinEncoding;
    5962        else
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs

    r4352 r4722  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
    24 using HeuristicLab.Parameters;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Data;
    2725
    2826namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3230    [StorableConstructor]
    3331    private PotvinSequenceBasedCrossover(bool deserializing) : base(deserializing) { }
     32    private PotvinSequenceBasedCrossover(PotvinSequenceBasedCrossover original, Cloner cloner)
     33      : base(original, cloner) {
     34    }
     35    public override IDeepCloneable Clone(Cloner cloner) {
     36      return new PotvinSequenceBasedCrossover(this, cloner);
     37    }
    3438
    3539    public PotvinSequenceBasedCrossover()
    3640      : base() { }
    37        
     41
    3842    protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
    3943      PotvinEncoding child = parent1.Clone() as PotvinEncoding;
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Manipulators/PotvinLocalSearchManipulator.cs

    r4352 r4722  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using HeuristicLab.Common;
    2224using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
     25using HeuristicLab.Data;
    2426using HeuristicLab.Parameters;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Data;
    27 using System.Collections.Generic;
    2828
    2929namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3737    [StorableConstructor]
    3838    private PotvinLocalSearchManipulator(bool deserializing) : base(deserializing) { }
    39 
    40     public PotvinLocalSearchManipulator() : base() {
     39    private PotvinLocalSearchManipulator(PotvinLocalSearchManipulator original, Cloner cloner)
     40      : base(original, cloner) {
     41    }
     42    public override IDeepCloneable Clone(Cloner cloner) {
     43      return new PotvinLocalSearchManipulator(this, cloner);
     44    }
     45    public PotvinLocalSearchManipulator()
     46      : base() {
    4147      Parameters.Add(new ValueParameter<IntValue>("Iterations", "The number of max iterations.", new IntValue(100)));
    4248    }
     
    7177          }
    7278          individual.Tours[currentTour].Cities.RemoveRange(currentCity, length);
    73          
     79
    7480          currentCity++;
    7581        }
     
    106112                  individual.Tours[insertionTour].Cities.InsertRange(
    107113                    insertionPlace,
    108                     toBeInserted); 
     114                    toBeInserted);
    109115                }
    110116                city++;
     
    115121          }
    116122          iterations++;
    117         } while (insertionFound && 
     123        } while (insertionFound &&
    118124          iterations < Iterations.Value.Value);
    119125
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Manipulators/PotvinManipulator.cs

    r4352 r4722  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
     24using HeuristicLab.Optimization;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Data;
    27 using HeuristicLab.Optimization;
    2827
    2928namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3736    [StorableConstructor]
    3837    protected PotvinManipulator(bool deserializing) : base(deserializing) { }
    39 
     38    protected PotvinManipulator(PotvinManipulator original, Cloner cloner)
     39      : base(original, cloner) {
     40    }
    4041    public PotvinManipulator() {
    4142      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
     
    7374    protected bool FindInsertionPlace(PotvinEncoding individual, int city, int routeToAvoid, out int route, out int place) {
    7475      return individual.FindInsertionPlace(
    75         DueTimeParameter.ActualValue, ServiceTimeParameter.ActualValue, ReadyTimeParameter.ActualValue, 
    76         DemandParameter.ActualValue, CapacityParameter.ActualValue, CoordinatesParameter.ActualValue, 
     76        DueTimeParameter.ActualValue, ServiceTimeParameter.ActualValue, ReadyTimeParameter.ActualValue,
     77        DemandParameter.ActualValue, CapacityParameter.ActualValue, CoordinatesParameter.ActualValue,
    7778        DistanceMatrixParameter, UseDistanceMatrixParameter.ActualValue,
    7879        city, routeToAvoid, out route, out place);
    7980    }
    80    
     81
    8182    public override IOperation Apply() {
    8283      IVRPEncoding solution = VRPToursParameter.ActualValue;
     
    8485        VRPToursParameter.ActualValue = PotvinEncoding.ConvertFrom(solution, DistanceMatrixParameter);
    8586      }
    86      
     87
    8788      Manipulate(RandomParameter.ActualValue, VRPToursParameter.ActualValue as PotvinEncoding);
    8889
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Manipulators/PotvinOneLevelExchangeManipulator.cs

    r4352 r4722  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using HeuristicLab.Common;
    2224using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
    24 using HeuristicLab.Parameters;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Data;
    27 using System.Collections.Generic;
    2826
    2927namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3331    [StorableConstructor]
    3432    private PotvinOneLevelExchangeMainpulator(bool deserializing) : base(deserializing) { }
     33    private PotvinOneLevelExchangeMainpulator(PotvinOneLevelExchangeMainpulator original, Cloner cloner)
     34      : base(original, cloner) {
     35    }
     36    public override IDeepCloneable Clone(Cloner cloner) {
     37      return new PotvinOneLevelExchangeMainpulator(this, cloner);
     38    }
     39    public PotvinOneLevelExchangeMainpulator() : base() { }
    3540
    36     public PotvinOneLevelExchangeMainpulator() : base() { }
    37    
    3841    protected override void Manipulate(IRandom random, PotvinEncoding individual) {
    3942      int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
     
    5255
    5356      route1.Cities.RemoveAll(
    54         new System.Predicate<int>( 
     57        new System.Predicate<int>(
    5558          delegate(int val) {
    56             return (replaced.Contains(val)); 
     59            return (replaced.Contains(val));
    5760          }
    5861        )
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs

    r4352 r4722  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
    24 using HeuristicLab.Parameters;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Data;
    27 using System.Collections.Generic;
    2825
    2926namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    3330    [StorableConstructor]
    3431    private PotvinTwoLevelExchangeManipulator(bool deserializing) : base(deserializing) { }
     32    private PotvinTwoLevelExchangeManipulator(PotvinTwoLevelExchangeManipulator original, Cloner cloner) : base(original, cloner) { }
     33    public override IDeepCloneable Clone(Cloner cloner) {
     34      return new PotvinTwoLevelExchangeManipulator(this, cloner);
     35    }
     36    public PotvinTwoLevelExchangeManipulator() : base() { }
    3537
    36     public PotvinTwoLevelExchangeManipulator() : base() { }
    37    
    3838    protected override void Manipulate(IRandom random, PotvinEncoding individual) {
    3939      int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
     
    5454                if (FindInsertionPlace(individual,
    5555                  customer2, selectedIndex, out route, out place)) {
    56                     individual.Tours[route].Cities.Insert(place, customer2);
     56                  individual.Tours[route].Cities.Insert(place, customer2);
    5757                  route1.Cities.RemoveAt(customer1Position);
    5858
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/PotvinEncoding.cs

    r4352 r4722  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Data;
    25 using HeuristicLab.Encodings.PermutationEncoding;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using System.Drawing;
    28 using System.Collections.Generic;
    2927using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    3028
     
    3230  [Item("PotvinEncoding", "Represents a potvin encoding of VRP solutions. It is implemented as described in Potvin, J.-Y. and Bengio, S. (1996). The Vehicle Routing Problem with Time Windows - Part II: Genetic Search. INFORMS Journal of Computing, 8:165–172.")]
    3331  [StorableClass]
    34   public class PotvinEncoding : TourEncoding {   
     32  public class PotvinEncoding : TourEncoding {
    3533    [Storable]
    3634    public List<int> Unrouted { get; set; }
    3735
    38     public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
    39       PotvinEncoding clone = new PotvinEncoding();
    40       cloner.RegisterClonedObject(this, clone);
    41       clone.Tours = (ItemList<Tour>)cloner.Clone(this.Tours);
    42       clone.Unrouted = new List<int>(Unrouted);
    43       return clone;
     36    [StorableConstructor]
     37    protected PotvinEncoding(bool deserializing) : base(deserializing) { }
     38    protected PotvinEncoding(PotvinEncoding original, Cloner cloner)
     39      : base(original, cloner) {
     40      Tours = cloner.Clone(original.Tours);
     41      Unrouted = new List<int>(original.Unrouted);
    4442    }
    45 
    46     public PotvinEncoding(): base() {
     43    public PotvinEncoding()
     44      : base() {
    4745      Unrouted = new List<int>();
    4846    }
    4947
    50     [StorableConstructor]
    51     private PotvinEncoding(bool serializing)
    52       : base() {
     48    public override IDeepCloneable Clone(Cloner cloner) {
     49      return new PotvinEncoding(this, cloner);
    5350    }
    54    
     51
    5552    public static PotvinEncoding ConvertFrom(IVRPEncoding encoding, ILookupParameter<DoubleMatrix> distanceMatrix) {
    5653      PotvinEncoding solution = new PotvinEncoding();
     
    8582            Tours[tour].Cities.Insert(i, city);
    8683
    87             if (Tours[tour].Feasible(dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, 
     84            if (Tours[tour].Feasible(dueTimeArray, serviceTimeArray, readyTimeArray, demandArray,
    8885              capacity, coordinates, distanceMatrix, useDistanceMatrix)) {
    89                 double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
     86              double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
    9087
    9188              double detour = newLength - length;
Note: See TracChangeset for help on using the changeset viewer.