Changeset 14128 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves
- Timestamp:
- 07/20/16 14:02:36 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/GroupingMoveHardTabuCriterion.cs
r14046 r14128 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.PermutationEncoding; 26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Optimization; … … 37 38 get { return false; } 38 39 } 39 public ILookupParameter<IPackingMove > PackingMoveParameter {40 get { return (ILookupParameter<IPackingMove >)Parameters["PackingMove"]; }40 public ILookupParameter<IPackingMove<Permutation>> PackingMoveParameter { 41 get { return (ILookupParameter<IPackingMove<Permutation>>)Parameters["PackingMove"]; } 41 42 } 42 public ILookupParameter<P ackingSequenceEncoding> PackingSequenceParameter {43 get { return (ILookupParameter<P ackingSequenceEncoding>)Parameters["PackingSequence"]; }43 public ILookupParameter<Permutation> PackingSequenceParameter { 44 get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; } 44 45 } 45 46 public ILookupParameter<ItemList<IItem>> TabuListParameter { … … 64 65 public SequenceMoveHardTabuCriterion() 65 66 : base() { 66 Parameters.Add(new LookupParameter<IPackingMove >("PackingMove", "The move to evaluate."));67 Parameters.Add(new LookupParameter<P ackingSequenceEncoding>("PackingSequence", "The solutionto evaluate."));67 Parameters.Add(new LookupParameter<IPackingMove<Permutation>>("PackingMove", "The move to evaluate.")); 68 Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The solution candidate to evaluate.")); 68 69 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); 69 70 Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list.")); … … 80 81 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 81 82 SequenceMove move = PackingMoveParameter.ActualValue as SequenceMove; 82 PackingSequenceEncoding PackingSequence = PackingSequenceParameter.ActualValue;83 int length = PackingSequence.PackingSequence.Length;84 83 double moveQuality = MoveQualityParameter.ActualValue.Value; 85 84 bool maximization = MaximizationParameter.ActualValue.Value; 86 85 bool useAspiration = UseAspirationCriterionParameter.Value.Value; 87 bool isTabu = IsMoveTabu(tabuList, move, PackingSequence,moveQuality, maximization, useAspiration);86 bool isTabu = IsMoveTabu(tabuList, move, moveQuality, maximization, useAspiration); 88 87 89 88 MoveTabuParameter.ActualValue = new BoolValue(isTabu); … … 91 90 } 92 91 93 private bool IsMoveTabu(ItemList<IItem> tabuList, SequenceMove move, PackingSequenceEncoding PackingSequence,double moveQuality, bool maximization, bool useAspiration) {92 private bool IsMoveTabu(ItemList<IItem> tabuList, SequenceMove move, double moveQuality, bool maximization, bool useAspiration) { 94 93 bool isTabu = false; 95 var attributes = tabuList.FindAll(ta => ta.GetType() .Equals(move.GetMoveAttributeType()));94 var attributes = tabuList.FindAll(ta => ta.GetType() == move.GetMoveAttributeType()); 96 95 97 96 foreach (IItem attr in attributes) { … … 102 101 || !maximization && moveQuality >= gvAttr.MoveQuality)) { 103 102 104 isTabu = move.BelongsToAttribute(gvAttr, true); 103 isTabu = move.BelongsToAttribute(gvAttr, true); // only difference to soft tabu criterion 105 104 } 106 105 if (isTabu) break; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/GroupingMoveMaker.cs
r14046 r14128 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.PermutationEncoding; 26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Optimization; … … 43 44 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 44 45 } 45 public ILookupParameter<IPackingMove > PackingMoveParameter {46 get { return (ILookupParameter<IPackingMove >)Parameters["PackingMove"]; }46 public ILookupParameter<IPackingMove<Permutation>> PackingMoveParameter { 47 get { return (ILookupParameter<IPackingMove<Permutation>>)Parameters["PackingMove"]; } 47 48 } 48 public ILookupParameter<P ackingSequenceEncoding> PackingSequenceParameter {49 get { return (ILookupParameter<P ackingSequenceEncoding>)Parameters["PackingSequence"]; }49 public ILookupParameter<Permutation> PackingSequenceParameter { 50 get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; } 50 51 } 51 52 public ILookupParameter<IPackingPlan> PackingPlanParameter { … … 62 63 : base() { 63 64 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution.")); 64 Parameters.Add(new LookupParameter<IPackingMove >("PackingMove", "The move to evaluate."));65 Parameters.Add(new LookupParameter<IPackingMove<Permutation>>("PackingMove", "The move to evaluate.")); 65 66 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 66 Parameters.Add(new LookupParameter<P ackingSequenceEncoding>("PackingSequence", "The solution as Sequence vector."));67 Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The solution as Sequence vector.")); 67 68 Parameters.Add(new LookupParameter<IPackingPlan>("PackingPlan", "The currently best performing, decoded bin-packing solution represented as generalized packing-plan.")); 68 69 Parameters.Add(new LookupParameter<IPackingPlan>("PackingPlanAfterMove", "The moved and decoded bin-packing solution represented as generalized packing-plan.")); … … 74 75 75 76 public override IOperation Apply() { 76 IPackingMove move = PackingMoveParameter.ActualValue;77 PackingSequenceEncoding PackingSequence = PackingSequenceParameter.ActualValue;78 77 DoubleValue moveQuality = MoveQualityParameter.ActualValue; 79 78 DoubleValue quality = QualityParameter.ActualValue; 80 79 81 PackingSequence.PackingSequence = (move.GetSolutionAfterMove() as PackingSequenceEncoding).PackingSequence;82 80 PackingPlanParameter.ActualValue = PackingPlanAfterMoveParameter.ActualValue; 83 81 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/GroupingMoveSoftTabuCriterion.cs
r14046 r14128 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.PermutationEncoding; 26 27 using HeuristicLab.Operators; 27 28 using HeuristicLab.Optimization; … … 38 39 get { return false; } 39 40 } 40 public ILookupParameter<IPackingMove > PackingMoveParameter {41 get { return (ILookupParameter<IPackingMove >)Parameters["PackingMove"]; }41 public ILookupParameter<IPackingMove<Permutation>> PackingMoveParameter { 42 get { return (ILookupParameter<IPackingMove<Permutation>>)Parameters["PackingMove"]; } 42 43 } 43 public ILookupParameter<P ackingSequenceEncoding> PackingSequenceParameter {44 get { return (ILookupParameter<P ackingSequenceEncoding>)Parameters["PackingSequence"]; }44 public ILookupParameter<Permutation> PackingSequenceParameter { 45 get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; } 45 46 } 46 47 public ILookupParameter<ItemList<IItem>> TabuListParameter { … … 65 66 public SequenceMoveSoftTabuCriterion() 66 67 : base() { 67 Parameters.Add(new LookupParameter<IPackingMove >("PackingMove", "The move to evaluate."));68 Parameters.Add(new LookupParameter<P ackingSequenceEncoding>("PackingSequence", "The solution to evaluate."));68 Parameters.Add(new LookupParameter<IPackingMove<Permutation>>("PackingMove", "The move to evaluate.")); 69 Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The solution to evaluate.")); 69 70 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); 70 71 Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list.")); … … 81 82 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 82 83 SequenceMove move = PackingMoveParameter.ActualValue as SequenceMove; 83 PackingSequenceEncoding PackingSequence = PackingSequenceParameter.ActualValue;84 int length = PackingSequence.PackingSequence.Length;85 84 double moveQuality = MoveQualityParameter.ActualValue.Value; 86 bool maximization = MaximizationParameter.ActualValue.Value; 85 bool maximization = MaximizationParameter.ActualValue.Value; 87 86 bool useAspiration = UseAspirationCriterionParameter.Value.Value; 88 bool isTabu = IsMoveTabu(tabuList, move, PackingSequence,moveQuality, maximization, useAspiration);87 bool isTabu = IsMoveTabu(tabuList, move, moveQuality, maximization, useAspiration); 89 88 90 89 MoveTabuParameter.ActualValue = new BoolValue(isTabu); … … 92 91 } 93 92 94 private bool IsMoveTabu(ItemList<IItem> tabuList, SequenceMove move, PackingSequenceEncoding PackingSequence,double moveQuality, bool maximization, bool useAspiration) {93 private bool IsMoveTabu(ItemList<IItem> tabuList, SequenceMove move, double moveQuality, bool maximization, bool useAspiration) { 95 94 bool isTabu = false; 96 var attributes = tabuList.FindAll(ta => ta.GetType() .Equals(move.GetMoveAttributeType()));95 var attributes = tabuList.FindAll(ta => ta.GetType() == move.GetMoveAttributeType()); 97 96 98 97 foreach (IItem attr in attributes) { … … 103 102 || !maximization && moveQuality >= gvAttr.MoveQuality)) { 104 103 105 isTabu = move.BelongsToAttribute(gvAttr, false); 104 isTabu = move.BelongsToAttribute(gvAttr, false); // only difference to hard tabu criterion 106 105 } 107 106 if (isTabu) break; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Insertion/ExhaustiveInsertionMoveGenerator.cs
r13032 r14128 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.PermutationEncoding; 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 39 40 return new ExhaustiveInsertionMoveGenerator(this, cloner); 40 41 } 41 public static IEnumerable<InsertionMove> Generate(P ackingSequenceEncoding PackingSequence, int nrOfBins) {42 for (int i = 0; i < PackingSequence.PackingSequence.Length - 1; i++)43 for (int j = i + 1; j < PackingSequence.PackingSequence.Length; j++) {42 public static IEnumerable<InsertionMove> Generate(Permutation packingSequence, int nrOfBins) { 43 for (int i = 0; i < packingSequence.Length - 1; i++) 44 for (int j = i + 1; j < packingSequence.Length; j++) { 44 45 if (j != i) 45 yield return new InsertionMove(i, j, PackingSequence);46 yield return new InsertionMove(i, j, packingSequence); 46 47 } 47 48 } 48 49 49 public static InsertionMove[] Apply(P ackingSequenceEncoding PackingSequence) {50 public static InsertionMove[] Apply(Permutation packingSequence) { 50 51 int nrOfBins = 0; 51 foreach (int binNr in PackingSequence.PackingSequence) {52 foreach (int binNr in packingSequence) { 52 53 if (binNr > nrOfBins) 53 54 nrOfBins = binNr; … … 55 56 nrOfBins++; 56 57 57 int totalMoves = ( PackingSequence.PackingSequence.Length * (PackingSequence.PackingSequence.Length - 1)) / 2;58 int totalMoves = (packingSequence.Length * (packingSequence.Length - 1)) / 2; 58 59 InsertionMove[] moves = new InsertionMove[totalMoves]; 59 60 int count = 0; 60 foreach (InsertionMove move in Generate( PackingSequence, nrOfBins)) {61 foreach (InsertionMove move in Generate(packingSequence, nrOfBins)) { 61 62 moves[count++] = move; 62 63 } … … 64 65 } 65 66 66 protected override InsertionMove[] GenerateMoves(P ackingSequenceEncoding PackingSequence) {67 return Apply( PackingSequence);67 protected override InsertionMove[] GenerateMoves(Permutation packingSequence) { 68 return Apply(packingSequence); 68 69 } 69 70 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Insertion/InsertionMove.cs
r14046 r14128 32 32 [Item("Insertion Move", "A move on a Sequence vector that is specified by two group-assignment-indexes.")] 33 33 [StorableClass] 34 public class InsertionMove : SequenceMove , IPackingMove{34 public class InsertionMove : SequenceMove { 35 35 [Storable] 36 36 public int Index1 { get; protected set; } … … 45 45 this.Index2 = original.Index2; 46 46 } 47 public InsertionMove(int index1, int index2, P ackingSequenceEncoding PackingSequence)48 : base( PackingSequence) {47 public InsertionMove(int index1, int index2, Permutation packingSequence) 48 : base(packingSequence) { 49 49 Index1 = index1; 50 50 Index2 = index2; … … 55 55 } 56 56 57 public override IPackingSolutionEncoding GetSolutionAfterMove() { 58 PackingSequenceEncoding newSolution = new PackingSequenceEncoding(); 59 60 Permutation original = PackingSequence.PackingSequence; 61 Permutation resultingPermutation = (Permutation)PackingSequence.PackingSequence.Clone(); 57 public override Permutation GetSolutionAfterMove() { 58 Permutation original = PackingSequence; 59 Permutation resultingPermutation = (Permutation)PackingSequence.Clone(); 62 60 int cutIndex, insertIndex, number; 63 61 … … 68 66 int i = 0; // index in new permutation 69 67 int j = 0; // index in old permutation 70 while (i < PackingSequence. PackingSequence.Length) {68 while (i < PackingSequence.Length) { 71 69 if (j == cutIndex) { 72 70 j++; … … 83 81 } 84 82 85 newSolution.PackingSequence = resultingPermutation; 86 return newSolution; 83 return resultingPermutation; 87 84 } 88 85 … … 92 89 93 90 public override SequenceMoveAttribute GetAttribute(double quality) { 94 return new InsertionMoveAttribute(Index1, Index2, PackingSequence .PackingSequence[Index1], PackingSequence.PackingSequence[Index2], quality);91 return new InsertionMoveAttribute(Index1, Index2, PackingSequence[Index1], PackingSequence[Index2], quality); 95 92 } 96 93 … … 103 100 } else 104 101 if (Index1 == attr.Index1 && Index2 == attr.Index2) 105 return true;102 return true; 106 103 } 107 104 return false; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Insertion/InsertionMoveGenerator.cs
r14046 r14128 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.PermutationEncoding; 25 26 using HeuristicLab.Operators; 26 27 using HeuristicLab.Optimization; … … 37 38 get { return false; } 38 39 } 39 public ILookupParameter<P ackingSequenceEncoding> PackingSequenceParameter {40 get { return (ILookupParameter<P ackingSequenceEncoding>)Parameters["PackingSequence"]; }40 public ILookupParameter<Permutation> PackingSequenceParameter { 41 get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; } 41 42 } 42 public ILookupParameter<IPackingMove > PackingMoveParameter {43 get { return (LookupParameter<IPackingMove >)Parameters["PackingMove"]; }43 public ILookupParameter<IPackingMove<Permutation>> PackingMoveParameter { 44 get { return (LookupParameter<IPackingMove<Permutation>>)Parameters["PackingMove"]; } 44 45 } 45 46 protected ScopeParameter CurrentScopeParameter { … … 52 53 public InsertionMoveGenerator() 53 54 : base() { 54 Parameters.Add(new LookupParameter<P ackingSequenceEncoding>("PackingSequence", "The Sequence vector for which moves should be generated."));55 Parameters.Add(new LookupParameter<IPackingMove >("PackingMove", "The moves that should be generated in subscopes."));55 Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The Sequence vector for which moves should be generated.")); 56 Parameters.Add(new LookupParameter<IPackingMove<Permutation>>("PackingMove", "The moves that should be generated in subscopes.")); 56 57 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); 57 58 } 58 59 59 60 public override IOperation Apply() { 60 P ackingSequenceEncodingps = PackingSequenceParameter.ActualValue;61 Permutation ps = PackingSequenceParameter.ActualValue; 61 62 InsertionMove[] moves = GenerateMoves(ps); 62 63 Scope[] moveScopes = new Scope[moves.Length]; … … 69 70 } 70 71 71 protected abstract InsertionMove[] GenerateMoves(P ackingSequenceEncoding PackingSequence);72 protected abstract InsertionMove[] GenerateMoves(Permutation packingSequence); 72 73 } 73 74 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Insertion/StochasticInsertionMoveGenerator.cs
r13032 r14128 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.PermutationEncoding; 27 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Parameters; … … 58 59 } 59 60 60 public static InsertionMove[] Apply(P ackingSequenceEncoding PackingSequence, IRandom random, int sampleSize) {61 public static InsertionMove[] Apply(Permutation packingSequence, IRandom random, int sampleSize) { 61 62 62 63 int nrOfBins = 0; 63 foreach (int binNr in PackingSequence.PackingSequence) {64 foreach (int binNr in packingSequence) { 64 65 if (binNr > nrOfBins) 65 66 nrOfBins = binNr; … … 67 68 nrOfBins++; 68 69 var generatedMoves = new List<InsertionMove>(); 69 var moves = new List<InsertionMove>(ExhaustiveInsertionMoveGenerator.Generate( PackingSequence, nrOfBins));70 var moves = new List<InsertionMove>(ExhaustiveInsertionMoveGenerator.Generate(packingSequence, nrOfBins)); 70 71 int moveCount = moves.Count; 71 72 for (int i = 0; i < sampleSize; i++) { … … 76 77 } 77 78 78 protected override InsertionMove[] GenerateMoves(P ackingSequenceEncoding SwapSequence) {79 protected override InsertionMove[] GenerateMoves(Permutation packingSequence) { 79 80 IRandom random = RandomParameter.ActualValue; 80 return Apply( SwapSequence, random, SampleSizeParameter.ActualValue.Value);81 return Apply(packingSequence, random, SampleSizeParameter.ActualValue.Value); 81 82 } 82 83 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/SequenceMove.cs
r14046 r14128 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.PermutationEncoding; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 28 using HeuristicLab.Problems.BinPacking; 28 29 29 30 namespace HeuristicLab.Encodings.PackingEncoding.PackingSequence { 30 [Item("SequenceMove", "An abstract move for a packing Sequence encoded solution.")]31 [Item("SequenceMove", "An abstract move for a packing sequence encoded solution.")] 31 32 [StorableClass] 32 public abstract class SequenceMove : Item, IPackingMove {33 public abstract class SequenceMove : Item, IPackingMove<Permutation> { 33 34 [Storable] 34 public P ackingSequenceEncodingPackingSequence { get; protected set; }35 public Permutation PackingSequence { get; protected set; } 35 36 36 37 [StorableConstructor] … … 41 42 this.PackingSequence = cloner.Clone(original.PackingSequence); 42 43 } 43 public SequenceMove(P ackingSequenceEncodingpackingSequence)44 public SequenceMove(Permutation packingSequence) 44 45 : base() { 45 46 PackingSequence = packingSequence; 46 47 } 47 48 48 public abstract IPackingSolutionEncodingGetSolutionAfterMove();49 public abstract Permutation GetSolutionAfterMove(); 49 50 public abstract Type GetMoveAttributeType(); 50 51 public abstract SequenceMoveAttribute GetAttribute(double quality); -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/SequenceTabuMaker.cs
r14046 r14128 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.PermutationEncoding; 25 26 using HeuristicLab.Optimization.Operators; 26 27 using HeuristicLab.Parameters; … … 32 33 [StorableClass] 33 34 public class SequenceTabuMaker : TabuMaker, IPackingSequenceMoveOperator { 34 public ILookupParameter<IPackingMove > PackingMoveParameter {35 get { return (ILookupParameter<IPackingMove >)Parameters["PackingMove"]; }35 public ILookupParameter<IPackingMove<Permutation>> PackingMoveParameter { 36 get { return (ILookupParameter<IPackingMove<Permutation>>)Parameters["PackingMove"]; } 36 37 } 37 public ILookupParameter<P ackingSequenceEncoding> PackingSequenceParameter {38 get { return (ILookupParameter<P ackingSequenceEncoding>)Parameters["PackingSequence"]; }38 public ILookupParameter<Permutation> PackingSequenceParameter { 39 get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; } 39 40 } 40 41 … … 44 45 public SequenceTabuMaker() 45 46 : base() { 46 Parameters.Add(new LookupParameter<IPackingMove >("PackingMove", "The move to evaluate."));47 Parameters.Add(new LookupParameter<P ackingSequenceEncoding>("PackingSequence", "The solution to evaluate."));47 Parameters.Add(new LookupParameter<IPackingMove<Permutation>>("PackingMove", "The move to evaluate.")); 48 Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The solution to evaluate.")); 48 49 } 49 50 … … 53 54 54 55 protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) { 55 IPackingMove move = PackingMoveParameter.ActualValue; 56 PackingSequenceEncoding PackingSequence = PackingSequenceParameter.ActualValue; 56 var move = PackingMoveParameter.ActualValue; 57 57 double baseQuality = moveQuality; 58 58 if (maximization && quality > moveQuality || !maximization && quality < moveQuality) -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/ExhaustiveSwap2MoveGenerator.cs
r13032 r14128 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Encodings.PermutationEncoding; 26 27 using HeuristicLab.Optimization; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 39 40 return new ExhaustiveSwap2MoveGenerator(this, cloner); 40 41 } 41 public static IEnumerable<Swap2Move> Generate(P ackingSequenceEncoding PackingSequence, int nrOfBins) {42 for (int i = 0; i < PackingSequence.PackingSequence.Length - 1; i++)43 for (int j = i + 1; j < PackingSequence.PackingSequence.Length; j++) {42 public static IEnumerable<Swap2Move> Generate(Permutation packingSequence, int nrOfBins) { 43 for (int i = 0; i < packingSequence.Length - 1; i++) 44 for (int j = i + 1; j < packingSequence.Length; j++) { 44 45 if (j != i) 45 yield return new Swap2Move(i, j, PackingSequence);46 yield return new Swap2Move(i, j, packingSequence); 46 47 } 47 48 } 48 49 49 public static Swap2Move[] Apply(P ackingSequenceEncoding PackingSequence) {50 public static Swap2Move[] Apply(Permutation packingSequence) { 50 51 int nrOfBins = 0; 51 foreach (int binNr in PackingSequence.PackingSequence) {52 foreach (int binNr in packingSequence) { 52 53 if (binNr > nrOfBins) 53 54 nrOfBins = binNr; … … 55 56 nrOfBins++; 56 57 57 int totalMoves = ( PackingSequence.PackingSequence.Length * (PackingSequence.PackingSequence.Length - 1)) / 2;58 int totalMoves = (packingSequence.Length * (packingSequence.Length - 1)) / 2; 58 59 Swap2Move[] moves = new Swap2Move[totalMoves]; 59 60 int count = 0; 60 foreach (Swap2Move move in Generate( PackingSequence, nrOfBins)) {61 foreach (Swap2Move move in Generate(packingSequence, nrOfBins)) { 61 62 moves[count++] = move; 62 63 } … … 64 65 } 65 66 66 protected override Swap2Move[] GenerateMoves(P ackingSequenceEncoding PackingSequence) {67 return Apply( PackingSequence);67 protected override Swap2Move[] GenerateMoves(Permutation packingSequence) { 68 return Apply(packingSequence); 68 69 } 69 70 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/StochasticSwap2MoveGenerator.cs
r13032 r14128 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.PermutationEncoding; 27 28 using HeuristicLab.Optimization; 28 29 using HeuristicLab.Parameters; … … 58 59 } 59 60 60 public static Swap2Move[] Apply(P ackingSequenceEncoding PackingSequence, IRandom random, int sampleSize) {61 public static Swap2Move[] Apply(Permutation packingSequence, IRandom random, int sampleSize) { 61 62 62 63 int nrOfBins = 0; 63 foreach (int binNr in PackingSequence.PackingSequence) {64 foreach (int binNr in packingSequence) { 64 65 if (binNr > nrOfBins) 65 66 nrOfBins = binNr; … … 67 68 nrOfBins++; 68 69 var generatedMoves = new List<Swap2Move>(); 69 var moves = new List<Swap2Move>(ExhaustiveSwap2MoveGenerator.Generate( PackingSequence, nrOfBins));70 var moves = new List<Swap2Move>(ExhaustiveSwap2MoveGenerator.Generate(packingSequence, nrOfBins)); 70 71 int moveCount = moves.Count; 71 72 for (int i = 0; i < sampleSize; i++) { … … 76 77 } 77 78 78 protected override Swap2Move[] GenerateMoves(P ackingSequenceEncoding SwapSequence) {79 protected override Swap2Move[] GenerateMoves(Permutation packingSequence) { 79 80 IRandom random = RandomParameter.ActualValue; 80 return Apply( SwapSequence, random, SampleSizeParameter.ActualValue.Value);81 return Apply(packingSequence, random, SampleSizeParameter.ActualValue.Value); 81 82 } 82 83 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/Swap2Move.cs
r14046 r14128 32 32 [Item("Swap2 Move", "A move on a Sequence vector that is specified by two group-assignment-indexes.")] 33 33 [StorableClass] 34 public class Swap2Move : SequenceMove, IPackingMove {34 public class Swap2Move : SequenceMove, IPackingMove<Permutation> { 35 35 [Storable] 36 36 public int Index1 { get; protected set; } … … 45 45 this.Index2 = original.Index2; 46 46 } 47 public Swap2Move(int index1, int index2, P ackingSequenceEncoding PackingSequence)48 : base( PackingSequence) {47 public Swap2Move(int index1, int index2, Permutation packingSequence) 48 : base(packingSequence) { 49 49 Index1 = index1; 50 50 Index2 = index2; … … 55 55 } 56 56 57 public override IPackingSolutionEncoding GetSolutionAfterMove() { 58 PackingSequenceEncoding newSolution = new PackingSequenceEncoding(); 59 newSolution.PackingSequence = (Permutation)PackingSequence.PackingSequence.Clone(new Cloner()); 60 newSolution.PackingSequence[Index1] = PackingSequence.PackingSequence[Index2]; 61 newSolution.PackingSequence[Index2] = PackingSequence.PackingSequence[Index1]; 57 public override Permutation GetSolutionAfterMove() { 58 Permutation newSolution = (Permutation)PackingSequence.Clone(new Cloner()); 59 newSolution[Index1] = PackingSequence[Index2]; 60 newSolution[Index2] = PackingSequence[Index1]; 62 61 return newSolution; 63 62 } … … 68 67 69 68 public override SequenceMoveAttribute GetAttribute(double quality) { 70 return new Swap2MoveAttribute(Index1, Index2, PackingSequence .PackingSequence[Index1], PackingSequence.PackingSequence[Index2], quality);69 return new Swap2MoveAttribute(Index1, Index2, PackingSequence[Index1], PackingSequence[Index2], quality); 71 70 } 72 71 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2/Swap2MoveGenerator.cs
r14046 r14128 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.PermutationEncoding; 25 26 using HeuristicLab.Operators; 26 27 using HeuristicLab.Optimization; … … 36 37 get { return false; } 37 38 } 38 public ILookupParameter<P ackingSequenceEncoding> PackingSequenceParameter {39 get { return (ILookupParameter<P ackingSequenceEncoding>)Parameters["PackingSequence"]; }39 public ILookupParameter<Permutation> PackingSequenceParameter { 40 get { return (ILookupParameter<Permutation>)Parameters["PackingSequence"]; } 40 41 } 41 public ILookupParameter<IPackingMove > PackingMoveParameter {42 get { return (LookupParameter<IPackingMove >)Parameters["PackingMove"]; }42 public ILookupParameter<IPackingMove<Permutation>> PackingMoveParameter { 43 get { return (LookupParameter<IPackingMove<Permutation>>)Parameters["PackingMove"]; } 43 44 } 44 45 protected ScopeParameter CurrentScopeParameter { … … 51 52 public Swap2MoveGenerator() 52 53 : base() { 53 Parameters.Add(new LookupParameter<P ackingSequenceEncoding>("PackingSequence", "The Sequence vector for which moves should be generated."));54 Parameters.Add(new LookupParameter<IPackingMove >("PackingMove", "The moves that should be generated in subscopes."));54 Parameters.Add(new LookupParameter<Permutation>("PackingSequence", "The Sequence vector for which moves should be generated.")); 55 Parameters.Add(new LookupParameter<IPackingMove<Permutation>>("PackingMove", "The moves that should be generated in subscopes.")); 55 56 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); 56 57 } 57 58 58 59 public override IOperation Apply() { 59 P ackingSequenceEncodingps = PackingSequenceParameter.ActualValue;60 Permutation ps = PackingSequenceParameter.ActualValue; 60 61 Swap2Move[] moves = GenerateMoves(ps); 61 62 Scope[] moveScopes = new Scope[moves.Length]; … … 68 69 } 69 70 70 protected abstract Swap2Move[] GenerateMoves(P ackingSequenceEncoding PackingSequence);71 protected abstract Swap2Move[] GenerateMoves(Permutation packingSequence); 71 72 } 72 73 }
Note: See TracChangeset
for help on using the changeset viewer.