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:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Problems.VehicleRouting

  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaExhaustiveLambdaInterchangeMoveGenerator.cs

    r4352 r4722  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using HeuristicLab.Common;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Optimization;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    27 using HeuristicLab.Parameters;
    28 using System.Collections.Generic;
    2928
    3029namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    3433    [StorableConstructor]
    3534    private AlbaExhaustiveLambdaInterchangeMoveGenerator(bool deserializing) : base(deserializing) { }
    36 
    37     public AlbaExhaustiveLambdaInterchangeMoveGenerator()
    38       : base() {
     35    private AlbaExhaustiveLambdaInterchangeMoveGenerator(AlbaExhaustiveLambdaInterchangeMoveGenerator original, Cloner cloner) : base(original, cloner) { }
     36    public AlbaExhaustiveLambdaInterchangeMoveGenerator() : base() { }
     37    public override IDeepCloneable Clone(Cloner cloner) {
     38      return new AlbaExhaustiveLambdaInterchangeMoveGenerator(this, cloner);
    3939    }
    4040
     
    5050
    5151          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, 
     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,
    5757                      tour2Index, index2, length2, individual));
    5858                  }
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMove.cs

    r4352 r4722  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2325using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    24 using HeuristicLab.Encodings.PermutationEncoding;
    25 using HeuristicLab.Common;
    26 using System.Collections.Generic;
    2726using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    28 using HeuristicLab.Data;
    2927
    3028namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
    3129  [Item("InversionMove", "Item that describes a lambda move on a VRP representation.  It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")]
    3230  [StorableClass]
    33   public class AlbaLambdaInterchangeMove: Item, IVRPMove {
     31  public class AlbaLambdaInterchangeMove : Item, IVRPMove {
    3432    [Storable]
    3533    public IVRPEncoding Individual { get; protected set; }
    36    
     34
    3735    [Storable]
    3836    public int Tour1 { get; protected set; }
     
    5250    [Storable]
    5351    public int Length2 { get; protected set; }
    54    
    55     public AlbaLambdaInterchangeMove(): base() {
     52
     53    [StorableConstructor]
     54    protected AlbaLambdaInterchangeMove(bool deserializing) : base(deserializing) { }
     55    protected AlbaLambdaInterchangeMove(AlbaLambdaInterchangeMove original, Cloner cloner)
     56      : base(original, cloner) {
     57      Tour1 = original.Tour1;
     58      Position1 = original.Position1;
     59      Length1 = original.Length1;
     60
     61      Tour2 = original.Tour2;
     62      Position2 = original.Position2;
     63      Length2 = original.Length2;
     64
     65      Individual = cloner.Clone(original.Individual);
     66    }
     67    public override IDeepCloneable Clone(Cloner cloner) {
     68      return new AlbaLambdaInterchangeMove(this, cloner);
     69    }
     70
     71    public AlbaLambdaInterchangeMove()
     72      : base() {
    5673      Tour1 = -1;
    5774      Position1 = -1;
     
    6582    }
    6683
    67     public AlbaLambdaInterchangeMove(int tour1, int position1, int length1, 
     84    public AlbaLambdaInterchangeMove(int tour1, int position1, int length1,
    6885      int tour2, int position2, int length2, AlbaEncoding permutation) {
    69         Tour1 = tour1;
    70         Position1 = position1;
    71         Length1 = length1;
     86      Tour1 = tour1;
     87      Position1 = position1;
     88      Length1 = length1;
    7289
    73         Tour2 = tour2;
    74         Position2 = position2;
    75         Length2 = length2;
     90      Tour2 = tour2;
     91      Position2 = position2;
     92      Length2 = length2;
    7693
    77         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;
     94      this.Individual = permutation.Clone() as AlbaEncoding;
    9695    }
    9796
     
    10099    public TourEvaluation GetMoveQuality(
    101100      IntValue vehicles,
    102       DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray, 
     101      DoubleArray dueTimeArray, DoubleArray serviceTimeArray, DoubleArray readyTimeArray,
    103102      DoubleArray demandArray, DoubleValue capacity, DoubleMatrix coordinates,
    104103      DoubleValue fleetUsageFactor, DoubleValue timeFactor, DoubleValue distanceFactor,
    105104      DoubleValue overloadPenalty, DoubleValue tardinessPenalty,
    106105      ILookupParameter<DoubleMatrix> distanceMatrix, Data.BoolValue useDistanceMatrix) {
    107         return AlbaLambdaInterchangeMoveEvaluator.GetMoveQuality(Individual as AlbaEncoding, this, vehicles,
    108           dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, capacity,
    109           coordinates, fleetUsageFactor, timeFactor, distanceFactor,
    110           overloadPenalty, tardinessPenalty, distanceMatrix, useDistanceMatrix);
     106      return AlbaLambdaInterchangeMoveEvaluator.GetMoveQuality(Individual as AlbaEncoding, this, vehicles,
     107        dueTimeArray, serviceTimeArray, readyTimeArray, demandArray, capacity,
     108        coordinates, fleetUsageFactor, timeFactor, distanceFactor,
     109        overloadPenalty, tardinessPenalty, distanceMatrix, useDistanceMatrix);
    111110    }
    112111
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMoveEvaluator.cs

    r4352 r4722  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    23 using HeuristicLab.Encodings.PermutationEncoding;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    27 using HeuristicLab.Data;
    2828
    2929namespace HeuristicLab.Problems.VehicleRouting {
     
    3737    [StorableConstructor]
    3838    private AlbaLambdaInterchangeMoveEvaluator(bool deserializing) : base(deserializing) { }
    39 
     39    private AlbaLambdaInterchangeMoveEvaluator(AlbaLambdaInterchangeMoveEvaluator original, Cloner cloner)
     40      : base(original, cloner) {
     41    }
    4042    public AlbaLambdaInterchangeMoveEvaluator()
    4143      : base() {
     
    4345    }
    4446
     47    public override IDeepCloneable Clone(Cloner cloner) {
     48      return new AlbaLambdaInterchangeMoveEvaluator(this, cloner);
     49    }
    4550    public static TourEvaluation GetMoveQuality(AlbaEncoding individual, AlbaLambdaInterchangeMove move,
    4651      IntValue vehicles,
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMoveGenerator.cs

    r4352 r4722  
    2020#endregion
    2121
    22 using System;
     22using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Optimization;
     26using HeuristicLab.Parameters;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    27 using HeuristicLab.Parameters;
    28 using System.Collections.Generic;
    29 using HeuristicLab.Data;
    3028
    3129namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    5149    [StorableConstructor]
    5250    protected AlbaLambdaInterchangeMoveGenerator(bool deserializing) : base(deserializing) { }
    53 
     51    protected AlbaLambdaInterchangeMoveGenerator(AlbaLambdaInterchangeMoveGenerator original, Cloner cloner)
     52      : base(original, cloner) {
     53    }
    5454    public AlbaLambdaInterchangeMoveGenerator()
    5555      : 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)));
     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)));
    5959    }
    6060
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMoveMaker.cs

    r4352 r4722  
    2020#endregion
    2121
     22using HeuristicLab.Common;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Data;
    24 using HeuristicLab.Operators;
    2525using HeuristicLab.Optimization;
    2626using HeuristicLab.Parameters;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using System.Collections.Generic;
    2928
    3029namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4645
    4746    [StorableConstructor]
    48     private AlbaLambdaInterchangeMoveMaker(bool deserializing) : base(deserializing) { }
    49 
     47    protected AlbaLambdaInterchangeMoveMaker(bool deserializing) : base(deserializing) { }
     48    protected AlbaLambdaInterchangeMoveMaker(AlbaLambdaInterchangeMoveMaker original, Cloner cloner)
     49      : base(original, cloner) {
     50    }
    5051    public AlbaLambdaInterchangeMoveMaker()
    5152      : base() {
     
    5354      Parameters.Add(new LookupParameter<AlbaLambdaInterchangeMove>("AlbaLambdaInterchangeMove", "The move to make."));
    5455      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
     56    }
     57
     58    public override IDeepCloneable Clone(Cloner cloner) {
     59      return new AlbaLambdaInterchangeMoveMaker(this, cloner);
    5560    }
    5661
     
    6469    public override IOperation Apply() {
    6570      IOperation next = base.Apply();
    66      
     71
    6772      AlbaLambdaInterchangeMove move = LambdaInterchangeMoveParameter.ActualValue;
    6873      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
    6974      DoubleValue quality = QualityParameter.ActualValue;
    70      
     75
    7176      //perform move
    7277      VRPToursParameter.ActualValue = move.MakeMove();
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeMutliMoveGenerator.cs

    r4352 r4722  
    2020#endregion
    2121
    22 using System;
     22using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Optimization;
     26using HeuristicLab.Parameters;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    27 using HeuristicLab.Parameters;
    28 using System.Collections.Generic;
    29 using HeuristicLab.Data;
    3028
    3129namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
     
    4038      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
    4139    }
    42    
     40
    4341    [StorableConstructor]
    4442    private AlbaStochasticLambdaInterchangeMultiMoveGenerator(bool deserializing) : base(deserializing) { }
    45 
     43    private AlbaStochasticLambdaInterchangeMultiMoveGenerator(AlbaStochasticLambdaInterchangeMultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
    4644    public AlbaStochasticLambdaInterchangeMultiMoveGenerator()
    4745      : 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."));
     46      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     47      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
    5048    }
    51 
     49    public override IDeepCloneable Clone(Cloner cloner) {
     50      return new AlbaStochasticLambdaInterchangeMultiMoveGenerator(this, cloner);
     51    }
    5252    protected override AlbaLambdaInterchangeMove[] GenerateMoves(AlbaEncoding individual, int lambda) {
    5353      int sampleSize = SampleSizeParameter.ActualValue.Value;
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeSingleMoveGenerator.cs

    r4352 r4722  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using HeuristicLab.Common;
    2325using HeuristicLab.Core;
    2426using HeuristicLab.Optimization;
     27using HeuristicLab.Parameters;
    2528using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Problems.VehicleRouting.Encodings.Alba;
    27 using HeuristicLab.Parameters;
    28 using System.Collections.Generic;
    2929using HeuristicLab.Problems.VehicleRouting.Encodings.General;
    3030
     
    4141
    4242    #endregion
    43    
     43
    4444    public ILookupParameter<IRandom> RandomParameter {
    4545      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    4646    }
    47    
     47
    4848    [StorableConstructor]
    4949    private AlbaStochasticLambdaInterchangeSingleMoveGenerator(bool deserializing) : base(deserializing) { }
    50 
     50    private AlbaStochasticLambdaInterchangeSingleMoveGenerator(AlbaStochasticLambdaInterchangeSingleMoveGenerator original, Cloner cloner)
     51      : base(original, cloner) {
     52    }
    5153    public AlbaStochasticLambdaInterchangeSingleMoveGenerator()
    5254      : base() {
    53         Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     55      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
     56    }
     57
     58    public override IDeepCloneable Clone(Cloner cloner) {
     59      return new AlbaStochasticLambdaInterchangeSingleMoveGenerator(this, cloner);
    5460    }
    5561
     
    8187
    8288      AlbaLambdaInterchangeMove move = Apply(individual, Cities, lambda, RandomParameter.ActualValue);
    83       if(move != null)
     89      if (move != null)
    8490        moves.Add(move);
    8591
Note: See TracChangeset for help on using the changeset viewer.