Changeset 4204
- Timestamp:
- 08/12/10 14:36:13 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3
- Files:
-
- 27 added
- 1 deleted
- 11 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/AlbaEncoding.cs
r4179 r4204 30 30 [Item("AlbaEncoding", "Represents an Alba encoding of VRP solutions. It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")] 31 31 [StorableClass] 32 class AlbaEncoding : Permutation, IVRPEncoding {32 public class AlbaEncoding : Permutation, IVRPEncoding { 33 33 [Storable] 34 34 private int cities; -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Crossovers/AlbaCrossover.cs
r4179 r4204 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Optimization; 27 28 28 29 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 29 30 [Item("AlbaCrossover", "An operator which crosses two Alba VRP representations.")] 30 31 [StorableClass] 31 public sealed class AlbaCrossover : VRPCrossover {32 public I ValueLookupParameter<IPermutationCrossover> InnerCrossoverParameter {33 get { return ( IValueLookupParameter<IPermutationCrossover>)Parameters["InnerCrossover"]; }32 public abstract class AlbaCrossover : VRPCrossover, IStochasticOperator { 33 public ILookupParameter<IRandom> RandomParameter { 34 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 34 35 } 35 36 36 37 [StorableConstructor] 37 pr ivateAlbaCrossover(bool deserializing) : base(deserializing) { }38 protected AlbaCrossover(bool deserializing) : base(deserializing) { } 38 39 39 40 public AlbaCrossover() 40 41 : base() { 41 Parameters.Add(new ValueLookupParameter<IPermutationCrossover>("InnerCrossover", "The permutation crossover.", new EdgeRecombinationCrossover()));42 42 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 43 43 44 AlbaEncoding.RemoveUnusedParameters(Parameters); 44 45 } 45 46 46 private void Crossover() { 47 //note - the inner crossover is called here and the result is converted to an alba representation 48 //some refactoring should be done here in the future - the crossover operation should be called directly 49 50 InnerCrossoverParameter.ActualValue.ParentsParameter.ActualName = ParentsParameter.ActualName; 51 IAtomicOperation op = this.ExecutionContext.CreateOperation( 52 InnerCrossoverParameter.ActualValue, this.ExecutionContext.Scope); 53 op.Operator.Execute((IExecutionContext)op); 54 55 string childName = InnerCrossoverParameter.ActualValue.ChildParameter.ActualName; 56 if (ExecutionContext.Scope.Variables.ContainsKey(childName)) { 57 Permutation permutation = ExecutionContext.Scope.Variables[childName].Value as Permutation; 58 ExecutionContext.Scope.Variables.Remove(childName); 59 60 ChildParameter.ActualValue = new AlbaEncoding(permutation, Cities); 61 } else 62 ChildParameter.ActualValue = null; 63 } 47 protected abstract AlbaEncoding Crossover(IRandom random, AlbaEncoding parent1, AlbaEncoding parent2); 64 48 65 49 public override IOperation Apply() { … … 76 60 ParentsParameter.ActualValue = parents; 77 61 78 Crossover(); 62 ChildParameter.ActualValue = 63 Crossover(RandomParameter.ActualValue, parents[0] as AlbaEncoding, parents[1] as AlbaEncoding); 79 64 80 65 return base.Apply(); -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Manipulators/AlbaManipulator.cs
r4179 r4204 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Optimization; 27 28 28 29 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 29 [Item("AlbaManipulator", "An operator which manipulates an alba VRP representation.")]30 [Item("AlbaManipulator", "An operator which manipulates an Alba VRP representation.")] 30 31 [StorableClass] 31 public sealed class AlbaManipulator : VRPManipulator {32 public I ValueLookupParameter<IPermutationManipulator> InnerManipulatorParameter {33 get { return ( IValueLookupParameter<IPermutationManipulator>)Parameters["InnerManipulator"]; }32 public abstract class AlbaManipulator : VRPManipulator, IStochasticOperator { 33 public ILookupParameter<IRandom> RandomParameter { 34 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 34 35 } 35 36 36 37 [StorableConstructor] 37 pr ivateAlbaManipulator(bool deserializing) : base(deserializing) { }38 protected AlbaManipulator(bool deserializing) : base(deserializing) { } 38 39 39 40 public AlbaManipulator() 40 41 : base() { 41 Parameters.Add(new ValueLookupParameter<IPermutationManipulator>("InnerManipulator", "The permutation manipulator.", new TranslocationManipulator()));42 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 42 43 43 44 AlbaEncoding.RemoveUnusedParameters(Parameters); 45 } 46 47 protected abstract void Manipulate(IRandom random, AlbaEncoding individual); 48 49 protected int FindCustomerLocation(int customer, AlbaEncoding individual) { 50 int pos = -1; 51 for (int i = 0; i < individual.Length; i++) { 52 if (individual[i] == customer) { 53 pos = i; 54 break; 55 } 56 } 57 58 return pos; 44 59 } 45 60 … … 49 64 VRPToursParameter.ActualValue = AlbaEncoding.ConvertFrom(solution, VehiclesParameter.ActualValue.Value); 50 65 } 51 52 OperationCollection next = new OperationCollection(base.Apply());53 66 54 IPermutationManipulator op = InnerManipulatorParameter.ActualValue; 55 if (op != null) { 56 op.PermutationParameter.ActualName = VRPToursParameter.ActualName; 57 next.Insert(0, ExecutionContext.CreateOperation(op)); 58 } 67 Manipulate(RandomParameter.ActualValue, VRPToursParameter.ActualValue as AlbaEncoding); 59 68 60 return next;69 return base.Apply(); 61 70 } 62 71 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/AlbaMoveOperator.cs
r4179 r4204 30 30 [StorableClass] 31 31 public abstract class AlbaMoveOperator : VRPMoveOperator { 32 [Storable]33 protected abstract IPermutationMoveOperator PermutationMoveOperatorParameter { get; set; }34 35 32 [StorableConstructor] 36 33 protected AlbaMoveOperator(bool deserializing) : base(deserializing) { } … … 47 44 } 48 45 49 PermutationMoveOperatorParameter.PermutationParameter.ActualName = VRPToursParameter.ActualName;50 IAtomicOperation op = this.ExecutionContext.CreateChildOperation(PermutationMoveOperatorParameter);51 op.Operator.Execute((IExecutionContext)op);52 53 46 return base.Apply(); 54 47 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/Interfaces/IAlbaTranslocationMoveOperator.cs
r4188 r4204 25 25 26 26 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 27 public interface IAlbaTranslocationMoveOperator : I MoveOperator {27 public interface IAlbaTranslocationMoveOperator : IVRPMoveOperator { 28 28 ILookupParameter<TranslocationMove> TranslocationMoveParameter { get; } 29 29 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/ThreeOpt/AlbaTranslocationMoveEvaluator.cs
r4179 r4204 29 29 [Item("AlbaTranslocationMoveEvaluator", "Evaluates a translocation or insertion move (3-opt) for the Alba representation.")] 30 30 [StorableClass] 31 public sealed class AlbaTranslocationMoveEvaluator : VRPMoveEvaluator {31 public sealed class AlbaTranslocationMoveEvaluator : VRPMoveEvaluator, IAlbaTranslocationMoveOperator { 32 32 public ILookupParameter<TranslocationMove> TranslocationMoveParameter { 33 33 get { return (ILookupParameter<TranslocationMove>)Parameters["TranslocationMove"]; } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/ThreeOpt/AlbaTranslocationMoveGenerator.cs
r4179 r4204 31 31 [Item("AlbaTranslocationMoveGenerator", "An operator which generates translocation moves for the Alba representation.")] 32 32 [StorableClass] 33 public sealed class AlbaTranslocationMoveGenerator : AlbaMoveOperator, IAlbaTranslocationMoveOperator, IMultiMoveGenerator {33 public sealed class AlbaTranslocationMoveGenerator : PermutationMoveOperator, IAlbaTranslocationMoveOperator, IMultiMoveGenerator { 34 34 public IValueLookupParameter<TranslocationMoveGenerator> TranslocationMoveGeneratorParameter { 35 35 get { return (IValueLookupParameter<TranslocationMoveGenerator>)Parameters["TranslocationMoveGenerator"]; } … … 86 86 string moveName = TranslocationMoveGeneratorParameter.ActualValue.TranslocationMoveParameter.Name; 87 87 88 List<Scope> toBeDeleted = new List<Scope>();89 foreach (Scope scope in this.ExecutionContext.Scope.SubScopes) {90 if (scope.Variables.ContainsKey(moveName)) {91 TranslocationMove move = scope.Variables[moveName].Value as TranslocationMove;92 93 if (move != null) {94 bool criteria1 = true;95 if (move.Index1 - 1 >= 0 &&96 move.Index3 - 1 >= 0)97 criteria1 = (permutation[move.Index1] >= Cities &&98 permutation[move.Index1 - 1] >= Cities &&99 permutation[move.Index3 - 1] >= Cities);100 101 int index3 = move.Index3 + (move.Index2 - move.Index1) + 1;102 bool criteria2 = true;103 if (move.Index2 + 1 < permutation.Length &&104 index3 < permutation.Length)105 criteria2 = (permutation[move.Index2] >= Cities &&106 permutation[move.Index2 + 1] >= Cities &&107 permutation[index3] >= Cities);108 109 if (criteria1 && criteria2)110 toBeDeleted.Add(scope);111 }112 }113 }114 115 foreach (Scope scope in toBeDeleted) {116 this.ExecutionContext.Scope.SubScopes.Remove(scope);117 }118 119 88 return successor; 120 89 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/ThreeOpt/AlbaTranslocationMoveHardTabuCriterion.cs
r4179 r4204 29 29 [Item("AlbaTranslocationMoveHardTabuCriterion", "An operator which checks if translocation moves are tabu using a hard criterion for the Alba representation.")] 30 30 [StorableClass] 31 public sealed class AlbaTranslocationMoveHardTabuCriterion : AlbaMoveOperator, IAlbaTranslocationMoveOperator, ITabuChecker {31 public sealed class AlbaTranslocationMoveHardTabuCriterion : PermutationMoveOperator, IAlbaTranslocationMoveOperator, ITabuChecker { 32 32 private TranslocationMoveHardTabuCriterion tabuChecker; 33 33 protected override IPermutationMoveOperator PermutationMoveOperatorParameter { -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/ThreeOpt/AlbaTranslocationMoveMaker.cs
r4179 r4204 31 31 public sealed class AlbaTranslocationMoveMaker : AlbaMoveMaker, IAlbaTranslocationMoveOperator, IVRPMoveMaker { 32 32 private TranslocationMoveMaker moveMaker; 33 protected override IPermutationMoveOperator PermutationMoveOperatorParameter {34 get { return moveMaker; }35 set { moveMaker = value as TranslocationMoveMaker; }36 }37 33 38 34 public ILookupParameter<TranslocationMove> TranslocationMoveParameter { … … 59 55 moveMaker = new TranslocationMoveMaker(); 60 56 } 57 58 public override IOperation Apply() { 59 IOperation next = base.Apply(); 60 61 IVRPEncoding solution = VRPToursParameter.ActualValue; 62 63 moveMaker.PermutationParameter.ActualName = VRPToursParameter.ActualName; 64 IAtomicOperation op = this.ExecutionContext.CreateChildOperation(moveMaker); 65 op.Operator.Execute((IExecutionContext)op); 66 67 return next; 68 } 61 69 } 62 70 } -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/ThreeOpt/AlbaTranslocationMoveSoftTabuCriterion.cs
r4179 r4204 29 29 [Item("AlbaTranslocationMoveSoftTabuCriterion", "An operator which checks if translocation moves are tabu using a soft criterion for the Alba representation.")] 30 30 [StorableClass] 31 public sealed class AlbaTranslocationMoveSoftTabuCriterion : AlbaMoveOperator, IAlbaTranslocationMoveOperator, ITabuChecker {31 public sealed class AlbaTranslocationMoveSoftTabuCriterion : PermutationMoveOperator, IAlbaTranslocationMoveOperator, ITabuChecker { 32 32 private TranslocationMoveSoftTabuCriterion tabuChecker; 33 33 protected override IPermutationMoveOperator PermutationMoveOperatorParameter { -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/ThreeOpt/AlbaTranslocationMoveTabuMaker.cs
r4179 r4204 29 29 [Item("AlbaTranslocationMoveTabuMaker", "An operator which makes translocation moves tabu for the Alba representation.")] 30 30 [StorableClass] 31 public sealed class AlbaTranslocationMoveTabuMaker : AlbaMoveOperator, IAlbaTranslocationMoveOperator, ITabuMaker {31 public sealed class AlbaTranslocationMoveTabuMaker : PermutationMoveOperator, IAlbaTranslocationMoveOperator, ITabuMaker { 32 32 private TranslocationMoveTabuMaker moveTabuMaker; 33 33 protected override IPermutationMoveOperator PermutationMoveOperatorParameter { -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/HeuristicLab.Problems.VehicleRouting-3.3.csproj
r4186 r4204 107 107 <ItemGroup> 108 108 <Compile Include="Analyzers\BestVRPSolutionAnalyzer.cs" /> 109 <Compile Include="Encodings\Alba\Crossovers\PermutationCrossover.cs" /> 110 <Compile Include="Encodings\Alba\Manipulators\SimpleLocalSearchManipulator.cs" /> 111 <Compile Include="Encodings\Alba\Manipulators\LambdaInterchangeManipulator.cs" /> 112 <Compile Include="Encodings\Alba\Moves\Interfaces\IAlbaLambdaInterchangeMoveOperator.cs" /> 113 <Compile Include="Encodings\Alba\Moves\Interfaces\IAlbaSimpleLocalSearchMoveOperator.cs" /> 114 <Compile Include="Encodings\Alba\Manipulators\CustomerInversionManipulator.cs" /> 115 <Compile Include="Encodings\Alba\Manipulators\CustomerSwapManipulator.cs" /> 116 <Compile Include="Encodings\Alba\Manipulators\CustomerInsertionManipulator.cs" /> 117 <Compile Include="Encodings\Alba\Manipulators\PermutationManipulator.cs" /> 118 <Compile Include="Encodings\Alba\Moves\LambdaInterchange\ExhaustiveLambdaInterchangeMoveGenerator.cs" /> 119 <Compile Include="Encodings\Alba\Moves\LambdaInterchange\LambdaInterchangeMove.cs" /> 120 <Compile Include="Encodings\Alba\Moves\LambdaInterchange\LambdaInterchangeMoveGenerator.cs" /> 121 <Compile Include="Encodings\Alba\Moves\LambdaInterchange\LambdaInterchangeMoveEvaluator.cs" /> 122 <Compile Include="Encodings\Alba\Moves\LambdaInterchange\LambdaInterchangeMoveMaker.cs" /> 123 <Compile Include="Encodings\Alba\Moves\LambdaInterchange\StochasticLambdaInterchangeSingleMoveGenerator.cs" /> 124 <Compile Include="Encodings\Alba\Moves\LambdaInterchange\StochasticLambdaInterchangeMutliMoveGenerator.cs" /> 125 <Compile Include="Encodings\Alba\Moves\PermutationMoveOperator.cs" /> 126 <Compile Include="Encodings\Alba\Moves\SimpleLocalSearch\StochasticSimpleLocalSearchMutliMoveGenerator.cs" /> 127 <Compile Include="Encodings\Alba\Moves\SimpleLocalSearch\StochasticSimpleLocalSearchSingleMoveGenerator.cs" /> 128 <Compile Include="Encodings\Alba\Moves\SimpleLocalSearch\SimpleLocalSearchMoveGenerator.cs" /> 129 <Compile Include="Encodings\Alba\Moves\SimpleLocalSearch\SimpleLocalSearchMoveEvaluator.cs" /> 130 <Compile Include="Encodings\Alba\Moves\SimpleLocalSearch\ExhaustiveSimpleLocalSearchMoveGenerator.cs" /> 131 <Compile Include="Encodings\Alba\Moves\SimpleLocalSearch\SimpleLocalSearchMoveMaker.cs" /> 132 <Compile Include="Encodings\Alba\Moves\SimpleLocalSearch\SimpleLocalSearchMove.cs" /> 109 133 <Compile Include="Encodings\General\Crossovers\MultiVRPManipulator.cs" /> 110 134 <Compile Include="Encodings\General\Crossovers\MultiVRPCrossover.cs" /> … … 124 148 <Compile Include="Encodings\General\Creators\DefaultRepresentationCreator.cs" /> 125 149 <Compile Include="Encodings\Alba\Crossovers\AlbaCrossover.cs" /> 126 <Compile Include="Encodings\Alba\ Interfaces\IAlbaTranslocationMoveOperator.cs" />150 <Compile Include="Encodings\Alba\Moves\Interfaces\IAlbaTranslocationMoveOperator.cs" /> 127 151 <Compile Include="Encodings\Alba\Manipulators\AlbaManipulator.cs" /> 128 152 <Compile Include="Encodings\Alba\Moves\AlbaMoveOperator.cs" />
Note: See TracChangeset
for help on using the changeset viewer.