Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/29/10 20:30:20 (14 years ago)
Author:
gkronber
Message:

Refactored cloning in HeuristicLab.Problems.VehicleRouting. #922

Location:
branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/AlbaExhaustiveIntraRouteInversionMoveGenerator.cs

    r4352 r4690  
    2727using HeuristicLab.Parameters;
    2828using System.Collections.Generic;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    3435    [StorableConstructor]
    3536    private AlbaExhaustiveIntraRouteInversionGenerator(bool deserializing) : base(deserializing) { }
    36 
     37    private AlbaExhaustiveIntraRouteInversionGenerator(AlbaExhaustiveIntraRouteInversionGenerator original, Cloner cloner) : base(original, cloner) { }
    3738    public AlbaExhaustiveIntraRouteInversionGenerator()
    3839      : base() {
     40    }
     41
     42    public override IDeepCloneable Clone(Cloner cloner) {
     43      return new AlbaExhaustiveIntraRouteInversionGenerator(this, cloner);
    3944    }
    4045
     
    4449      int currentTourStart = 0;
    4550      int currentTourEnd = 0;
    46       while(currentTourEnd != individual.Length) {
     51      while (currentTourEnd != individual.Length) {
    4752        currentTourEnd = currentTourStart;
    48         while (individual[currentTourEnd] < individual.Cities && 
     53        while (individual[currentTourEnd] < individual.Cities &&
    4954          currentTourEnd < individual.Length) {
    5055          currentTourEnd++;
     
    5358        int tourLength = currentTourEnd - currentTourStart;
    5459        if (tourLength >= 4) {
    55           for (int i = 0; i <= tourLength - 4; i++ ) {
     60          for (int i = 0; i <= tourLength - 4; i++) {
    5661            for (int j = i + 2; j <= tourLength - 2; j++) {
    5762              AlbaIntraRouteInversionMove move = new AlbaIntraRouteInversionMove(
    58                 currentTourStart + i, 
    59                 currentTourStart + j, 
     63                currentTourStart + i,
     64                currentTourStart + j,
    6065                individual);
    6166
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/AlbaIntraRouteInversionEvaluator.cs

    r4352 r4690  
    2626using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Common;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting {
     
    3738    [StorableConstructor]
    3839    private AlbaIntraRouteInversionMoveEvaluator(bool deserializing) : base(deserializing) { }
    39 
     40    private AlbaIntraRouteInversionMoveEvaluator(AlbaIntraRouteInversionMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
    4041    public AlbaIntraRouteInversionMoveEvaluator()
    4142      : base() {
    42         Parameters.Add(new LookupParameter<AlbaIntraRouteInversionMove>("AlbaIntraRouteInversionMove", "The move to evaluate."));
     43      Parameters.Add(new LookupParameter<AlbaIntraRouteInversionMove>("AlbaIntraRouteInversionMove", "The move to evaluate."));
     44    }
     45
     46    public override IDeepCloneable Clone(Cloner cloner) {
     47      return new AlbaIntraRouteInversionMoveEvaluator(this, cloner);
    4348    }
    4449
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/AlbaIntraRouteInversionMove.cs

    r4352 r4690  
    3232  public class AlbaIntraRouteInversionMove : TwoIndexMove, IVRPMove {
    3333    public IVRPEncoding Individual { get { return Permutation as AlbaEncoding; } }
    34    
     34
     35    [StorableConstructor]
     36    protected AlbaIntraRouteInversionMove(bool deserializing) : base(deserializing) { }
     37    protected AlbaIntraRouteInversionMove(AlbaIntraRouteInversionMove original, Cloner cloner)
     38      : base(original, cloner) {
     39      Permutation = cloner.Clone(original.Permutation);
     40    }
    3541    public AlbaIntraRouteInversionMove()
    3642      : base() {
     
    4349    public AlbaIntraRouteInversionMove(int index1, int index2, AlbaEncoding permutation)
    4450      : base(index1, index2, permutation) {
    45         this.Permutation = permutation.Clone() as AlbaEncoding;
     51      this.Permutation = permutation.Clone() as AlbaEncoding;
    4652    }
    4753
    48     public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
    49       AlbaIntraRouteInversionMove clone = new AlbaIntraRouteInversionMove(
    50         Index1, Index2);
    51 
    52       if (Permutation != null)
    53         clone.Permutation = (AlbaEncoding)cloner.Clone(Permutation);
    54 
    55       cloner.RegisterClonedObject(this, clone);
    56       return clone;
     54    public override IDeepCloneable Clone(Cloner cloner) {
     55      return new AlbaIntraRouteInversionMove(this, cloner);
    5756    }
    5857
     
    6160    public TourEvaluation GetMoveQuality(
    6261      IntValue vehicles,
    63       DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray, 
     62      DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray,
    6463      DoubleArray demandArray, DoubleValue capacity, DoubleMatrix coordinates,
    6564      DoubleValue fleetUsageFactor, DoubleValue timeFactor, DoubleValue distanceFactor,
    6665      DoubleValue overloadPenalty, DoubleValue tardinessPenalty,
    6766      ILookupParameter<DoubleMatrix> distanceMatrix, Data.BoolValue useDistanceMatrix) {
    68         return AlbaIntraRouteInversionMoveEvaluator.GetMoveQuality(Permutation as AlbaEncoding, this, vehicles,
    69           dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, capacity,
    70           coordinates, fleetUsageFactor, timeFactor, distanceFactor,
    71           overloadPenalty, tardinessPenalty, distanceMatrix, useDistanceMatrix);
     67      return AlbaIntraRouteInversionMoveEvaluator.GetMoveQuality(Permutation as AlbaEncoding, this, vehicles,
     68        dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, capacity,
     69        coordinates, fleetUsageFactor, timeFactor, distanceFactor,
     70        overloadPenalty, tardinessPenalty, distanceMatrix, useDistanceMatrix);
    7271    }
    7372
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/AlbaIntraRouteInversionMoveGenerator.cs

    r4352 r4690  
    2727using HeuristicLab.Parameters;
    2828using System.Collections.Generic;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4243    [StorableConstructor]
    4344    protected AlbaIntraRouteInversionMoveGenerator(bool deserializing) : base(deserializing) { }
    44 
     45    protected AlbaIntraRouteInversionMoveGenerator(AlbaIntraRouteInversionMoveGenerator original, Cloner cloner) : base(original, cloner) { }
    4546    public AlbaIntraRouteInversionMoveGenerator()
    4647      : base() {
    47         Parameters.Add(new LookupParameter<AlbaIntraRouteInversionMove>("AlbaIntraRouteInversionMove", "The moves that should be generated in subscopes."));
    48         Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
     48      Parameters.Add(new LookupParameter<AlbaIntraRouteInversionMove>("AlbaIntraRouteInversionMove", "The moves that should be generated in subscopes."));
     49      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
    4950    }
    5051
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/AlbaIntraRouteInversionMoveMaker.cs

    r4352 r4690  
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Common;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4647    [StorableConstructor]
    4748    private AlbaIntraRouteInversionMoveMaker(bool deserializing) : base(deserializing) { }
    48 
     49    private AlbaIntraRouteInversionMoveMaker(AlbaIntraRouteInversionMoveMaker original, Cloner cloner)
     50      : base(original, cloner) {
     51    }
    4952    public AlbaIntraRouteInversionMoveMaker()
    5053      : base() {
     
    5255      Parameters.Add(new LookupParameter<AlbaIntraRouteInversionMove>("AlbaIntraRouteInversionMove", "The move to make."));
    5356      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
     57    }
     58
     59    public override IDeepCloneable Clone(Cloner cloner) {
     60      return new AlbaIntraRouteInversionMoveMaker(this, cloner);
    5461    }
    5562
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/AlbaStochasticIntraRouteInversionMutliMoveGenerator.cs

    r4352 r4690  
    2828using System.Collections.Generic;
    2929using HeuristicLab.Data;
     30using HeuristicLab.Common;
    3031
    3132namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4041      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
    4142    }
    42    
     43
    4344    [StorableConstructor]
    4445    private AlbaStochasticIntraRouteInversionMultiMoveGenerator(bool deserializing) : base(deserializing) { }
    45 
     46    private AlbaStochasticIntraRouteInversionMultiMoveGenerator(AlbaStochasticIntraRouteInversionMultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
    4647    public AlbaStochasticIntraRouteInversionMultiMoveGenerator()
    4748      : base() {
    48         Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
    49         Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
     49      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     50      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
     51    }
     52
     53    public override IDeepCloneable Clone(Cloner cloner) {
     54      return new AlbaStochasticIntraRouteInversionMultiMoveGenerator(this, cloner);
    5055    }
    5156
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/IntraRouteInversion/AlbaStochasticIntraRouteInversionSingleMoveGenerator.cs

    r4352 r4690  
    2828using System.Collections.Generic;
    2929using HeuristicLab.Problems.VehicleRouting.Encodings.General;
     30using HeuristicLab.Common;
    3031
    3132namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4142
    4243    #endregion
    43    
     44
    4445    public ILookupParameter<IRandom> RandomParameter {
    4546      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    4647    }
    47    
     48
    4849    [StorableConstructor]
    4950    private AlbaStochasticIntraRouteInversionSingleMoveGenerator(bool deserializing) : base(deserializing) { }
    50 
     51    private AlbaStochasticIntraRouteInversionSingleMoveGenerator(AlbaStochasticIntraRouteInversionSingleMoveGenerator original, Cloner cloner) : base(original, cloner) { }
    5152    public AlbaStochasticIntraRouteInversionSingleMoveGenerator()
    5253      : base() {
    53         Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     54      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     55    }
     56
     57    public override IDeepCloneable Clone(Cloner cloner) {
     58      return new AlbaStochasticIntraRouteInversionSingleMoveGenerator(this, cloner);
    5459    }
    5560
     
    7580
    7681        int currentTourEnd = currentTourStart;
    77         while (currentTourEnd < individual.Length && 
     82        while (currentTourEnd < individual.Length &&
    7883          individual[currentTourEnd] < individual.Cities) {
    7984          currentTourEnd++;
     
    9398
    9499      AlbaIntraRouteInversionMove move = Apply(individual, Cities, RandomParameter.ActualValue);
    95       if(move != null)
     100      if (move != null)
    96101        moves.Add(move);
    97102
Note: See TracChangeset for help on using the changeset viewer.