Changeset 14128 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2
- Timestamp:
- 07/20/16 14:02:36 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/Moves/Swap2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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.