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/LambdaInterchange
Files:
7 edited

Legend:

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

    r4352 r4690  
    2727using HeuristicLab.Parameters;
    2828using System.Collections.Generic;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    3435    [StorableConstructor]
    3536    private AlbaExhaustiveLambdaInterchangeMoveGenerator(bool deserializing) : base(deserializing) { }
    36 
    37     public AlbaExhaustiveLambdaInterchangeMoveGenerator()
    38       : base() {
     37    private AlbaExhaustiveLambdaInterchangeMoveGenerator(AlbaExhaustiveLambdaInterchangeMoveGenerator original, Cloner cloner) : base(original, cloner) { }
     38    public AlbaExhaustiveLambdaInterchangeMoveGenerator() : base() { }
     39    public override IDeepCloneable Clone(Cloner cloner) {
     40      return new AlbaExhaustiveLambdaInterchangeMoveGenerator(this, cloner);
    3941    }
    4042
     
    5052
    5153          for (int length1 = 0; length1 <= Math.Min(lambda, tour1.Cities.Count); length1++) {
    52             for(int length2 = 0; length2 <= Math.Min(lambda, tour2.Cities.Count); length2++) {
    53               if(length1 != 0 || length2 != 0) {
    54                 for(int index1 = 0; index1 < tour1.Cities.Count - length1 + 1; index1++) {
    55                   for(int index2 = 0; index2 < tour2.Cities.Count - length2 + 1; index2++) {
    56                     moves.Add(new AlbaLambdaInterchangeMove(tour1Index, index1, length1, 
     54            for (int length2 = 0; length2 <= Math.Min(lambda, tour2.Cities.Count); length2++) {
     55              if (length1 != 0 || length2 != 0) {
     56                for (int index1 = 0; index1 < tour1.Cities.Count - length1 + 1; index1++) {
     57                  for (int index2 = 0; index2 < tour2.Cities.Count - length2 + 1; index2++) {
     58                    moves.Add(new AlbaLambdaInterchangeMove(tour1Index, index1, length1,
    5759                      tour2Index, index2, length2, individual));
    5860                  }
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMove.cs

    r4352 r4690  
    5252    [Storable]
    5353    public int Length2 { get; protected set; }
    54    
     54
     55    [StorableConstructor]
     56    protected AlbaLambdaInterchangeMove(bool deserializing) : base(deserializing) { }
     57    protected AlbaLambdaInterchangeMove(AlbaLambdaInterchangeMove original, Cloner cloner)      : base(original, cloner) {
     58      Tour1 = original.Tour1;
     59      Position1 = original.Position1;
     60      Length1 = original.Length1;
     61
     62      Tour2 = original.Tour2;
     63      Position2 = original.Position2;
     64      Length2 = original.Length2;
     65
     66      Individual = cloner.Clone(original.Individual);
     67    }
     68
    5569    public AlbaLambdaInterchangeMove(): base() {
    5670      Tour1 = -1;
     
    7690
    7791        this.Individual = permutation.Clone() as AlbaEncoding;
    78     }
    79 
    80     public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
    81       AlbaLambdaInterchangeMove clone = new AlbaLambdaInterchangeMove();
    82 
    83       clone.Tour1 = Tour1;
    84       clone.Position1 = Position1;
    85       clone.Length1 = Length1;
    86 
    87       clone.Tour2 = Tour2;
    88       clone.Position2 = Position2;
    89       clone.Length2 = Length2;
    90 
    91       if (Individual != null)
    92         clone.Individual = (AlbaEncoding)cloner.Clone(Individual);
    93 
    94       cloner.RegisterClonedObject(this, clone);
    95       return clone;
    9692    }
    9793
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMoveEvaluator.cs

    r4352 r4690  
    2626using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Common;
    2829
    2930namespace HeuristicLab.Problems.VehicleRouting {
     
    3738    [StorableConstructor]
    3839    private AlbaLambdaInterchangeMoveEvaluator(bool deserializing) : base(deserializing) { }
    39 
     40    private AlbaLambdaInterchangeMoveEvaluator(AlbaLambdaInterchangeMoveEvaluator original, Cloner cloner)
     41      : base(original, cloner) {
     42    }
    4043    public AlbaLambdaInterchangeMoveEvaluator()
    4144      : base() {
     
    4346    }
    4447
     48    public override IDeepCloneable Clone(Cloner cloner) {
     49      return new AlbaLambdaInterchangeMoveEvaluator(this, cloner);
     50    }
    4551    public static TourEvaluation GetMoveQuality(AlbaEncoding individual, AlbaLambdaInterchangeMove move,
    4652      IntValue vehicles,
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMoveGenerator.cs

    r4352 r4690  
    2828using System.Collections.Generic;
    2929using HeuristicLab.Data;
     30using HeuristicLab.Common;
    3031
    3132namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    5152    [StorableConstructor]
    5253    protected AlbaLambdaInterchangeMoveGenerator(bool deserializing) : base(deserializing) { }
    53 
     54    protected AlbaLambdaInterchangeMoveGenerator(AlbaLambdaInterchangeMoveGenerator original, Cloner cloner)
     55      : base(original, cloner) {
     56    }
    5457    public AlbaLambdaInterchangeMoveGenerator()
    5558      : base() {
    56         Parameters.Add(new LookupParameter<AlbaLambdaInterchangeMove>("AlbaLambdaInterchangeMove", "The moves that should be generated in subscopes."));
    57         Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
    58         Parameters.Add(new ValueParameter<IntValue>("Lambda", "The lambda value.", new IntValue(1)));
     59      Parameters.Add(new LookupParameter<AlbaLambdaInterchangeMove>("AlbaLambdaInterchangeMove", "The moves that should be generated in subscopes."));
     60      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
     61      Parameters.Add(new ValueParameter<IntValue>("Lambda", "The lambda value.", new IntValue(1)));
    5962    }
    6063
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMoveMaker.cs

    r4352 r4690  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828using System.Collections.Generic;
     29using HeuristicLab.Common;
    2930
    3031namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4748    [StorableConstructor]
    4849    private AlbaLambdaInterchangeMoveMaker(bool deserializing) : base(deserializing) { }
    49 
     50    protected AlbaLambdaInterchangeMoveMaker(AlbaLambdaInterchangeMoveMaker original, Cloner cloner)
     51      : base(original, cloner) {
     52    }
    5053    public AlbaLambdaInterchangeMoveMaker()
    5154      : base() {
     
    5356      Parameters.Add(new LookupParameter<AlbaLambdaInterchangeMove>("AlbaLambdaInterchangeMove", "The move to make."));
    5457      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
     58    }
     59
     60    public override IDeepCloneable Clone(Cloner cloner) {
     61      return new AlbaLambdaInterchangeMoveMaker(this, cloner);
    5562    }
    5663
     
    6471    public override IOperation Apply() {
    6572      IOperation next = base.Apply();
    66      
     73
    6774      AlbaLambdaInterchangeMove move = LambdaInterchangeMoveParameter.ActualValue;
    6875      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
    6976      DoubleValue quality = QualityParameter.ActualValue;
    70      
     77
    7178      //perform move
    7279      VRPToursParameter.ActualValue = move.MakeMove();
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeMutliMoveGenerator.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 AlbaStochasticLambdaInterchangeMultiMoveGenerator(bool deserializing) : base(deserializing) { }
    45 
     46    private AlbaStochasticLambdaInterchangeMultiMoveGenerator(AlbaStochasticLambdaInterchangeMultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
    4647    public AlbaStochasticLambdaInterchangeMultiMoveGenerator()
    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."));
    5051    }
    51 
     52    public override IDeepCloneable Clone(Cloner cloner) {
     53      return new AlbaStochasticLambdaInterchangeMultiMoveGenerator(this, cloner);
     54    }
    5255    protected override AlbaLambdaInterchangeMove[] GenerateMoves(AlbaEncoding individual, int lambda) {
    5356      int sampleSize = SampleSizeParameter.ActualValue.Value;
  • branches/CloningRefactoring/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeSingleMoveGenerator.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 AlbaStochasticLambdaInterchangeSingleMoveGenerator(bool deserializing) : base(deserializing) { }
    50 
     51    private AlbaStochasticLambdaInterchangeSingleMoveGenerator(AlbaStochasticLambdaInterchangeSingleMoveGenerator original, Cloner cloner)
     52      : base(original, cloner) {
     53    }
    5154    public AlbaStochasticLambdaInterchangeSingleMoveGenerator()
    5255      : base() {
    53         Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     56      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     57    }
     58
     59    public override IDeepCloneable Clone(Cloner cloner) {
     60      return new AlbaStochasticLambdaInterchangeSingleMoveGenerator(this, cloner);
    5461    }
    5562
     
    8188
    8289      AlbaLambdaInterchangeMove move = Apply(individual, Cities, lambda, RandomParameter.ActualValue);
    83       if(move != null)
     90      if (move != null)
    8491        moves.Add(move);
    8592
Note: See TracChangeset for help on using the changeset viewer.