- Timestamp:
- 05/15/13 22:23:36 (12 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings
- Files:
-
- 2 added
- 2 deleted
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMove.cs
r9440 r9495 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Encodings.IntegerVectorEncoding; 24 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.BinPacking.Interfaces; 25 27 26 28 namespace HeuristicLab.Encodings.PackingEncoding.GroupingVector { 27 29 [Item("Single Grouping Move", "A move on a grouping vector that is specified by a single group-assignment-index.")] 28 30 [StorableClass] 29 public class SingleGroupingMove : Item 31 public class SingleGroupingMove : Item, IPackingMove{ 30 32 [Storable] 31 33 public int Index { get; protected set; } … … 53 55 return new SingleGroupingMove(this, cloner); 54 56 } 57 58 public IPackingSolutionEncoding GetSolutionAfterMove() { 59 GroupingVectorEncoding newSolution = new GroupingVectorEncoding(); 60 newSolution.GroupingVector = new IntegerVector(GroupingVector.GroupingVector); 61 newSolution.GroupingVector[Index] = NewGroup; 62 return newSolution; 63 } 55 64 } 56 65 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveGenerator.cs
r9440 r9495 38 38 get { return (ILookupParameter<GroupingVectorEncoding>)Parameters["GroupingVector"]; } 39 39 } 40 public ILookupParameter< SingleGroupingMove> SingleGroupingMoveParameter {41 get { return (LookupParameter< SingleGroupingMove>)Parameters["SingleGroupingMove"]; }40 public ILookupParameter<IPackingMove> PackingMoveParameter { 41 get { return (LookupParameter<IPackingMove>)Parameters["PackingMove"]; } 42 42 } 43 43 protected ScopeParameter CurrentScopeParameter { … … 51 51 : base() { 52 52 Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The grouping vector for which moves should be generated.")); 53 Parameters.Add(new LookupParameter< SingleGroupingMove>("SingleGroupingMove", "The moves that should be generated in subscopes."));53 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The moves that should be generated in subscopes.")); 54 54 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); 55 55 } … … 61 61 for (int i = 0; i < moveScopes.Length; i++) { 62 62 moveScopes[i] = new Scope(i.ToString()); 63 moveScopes[i].Variables.Add(new Variable( SingleGroupingMoveParameter.ActualName, moves[i]));63 moveScopes[i].Variables.Add(new Variable(PackingMoveParameter.ActualName, moves[i])); 64 64 } 65 65 CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes); -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveHardTabuCriterion.cs
r9440 r9495 38 38 get { return false; } 39 39 } 40 public ILookupParameter< SingleGroupingMove> SingleGroupingMoveParameter {41 get { return (ILookupParameter< SingleGroupingMove>)Parameters["SingleGroupingMove"]; }40 public ILookupParameter<IPackingMove> PackingMoveParameter { 41 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 42 42 } 43 43 public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter { … … 65 65 public SingleGroupingMoveHardTabuCriterion() 66 66 : base() { 67 Parameters.Add(new LookupParameter< SingleGroupingMove>("SingleGroupingMove", "The move to evaluate."));67 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 68 68 Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The solution to evaluate.")); 69 69 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); … … 80 80 public override IOperation Apply() { 81 81 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 82 SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;82 SingleGroupingMove move = PackingMoveParameter.ActualValue as SingleGroupingMove; 83 83 GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue; 84 84 int length = groupingVector.GroupingVector.Length; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveMaker.cs
r9440 r9495 42 42 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 43 43 } 44 public ILookupParameter< SingleGroupingMove> SingleGroupingMoveParameter {45 get { return (ILookupParameter< SingleGroupingMove>)Parameters["SingleGroupingMove"]; }44 public ILookupParameter<IPackingMove> PackingMoveParameter { 45 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 46 46 } 47 47 public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter { 48 48 get { return (ILookupParameter<GroupingVectorEncoding>)Parameters["GroupingVector"]; } 49 } 50 public ILookupParameter<IPackingPlan> PackingPlanParameter { 51 get { return (ILookupParameter<IPackingPlan>)Parameters["PackingPlan"]; } 52 } 53 public ILookupParameter<IPackingPlan> PackingPlanAfterMoveParameter { 54 get { return (ILookupParameter<IPackingPlan>)Parameters["PackingPlanAfterMove"]; } 49 55 } 50 56 … … 55 61 : base() { 56 62 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution.")); 57 Parameters.Add(new LookupParameter< SingleGroupingMove>("SingleGroupingMove", "The move to evaluate."));63 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 58 64 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 59 65 Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The solution as grouping vector.")); 66 Parameters.Add(new LookupParameter<IPackingPlan>("PackingPlan", "The currently best performing, decoded bin-packing solution represented as generalized packing-plan.")); 67 Parameters.Add(new LookupParameter<IPackingPlan>("PackingPlanAfterMove", "The moved and decoded bin-packing solution represented as generalized packing-plan.")); 60 68 } 61 69 … … 65 73 66 74 public override IOperation Apply() { 67 SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;75 IPackingMove move = PackingMoveParameter.ActualValue; 68 76 GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue; 69 77 DoubleValue moveQuality = MoveQualityParameter.ActualValue; 70 78 DoubleValue quality = QualityParameter.ActualValue; 71 79 72 groupingVector.GroupingVector[move.Index] = move.NewGroup; 80 groupingVector.GroupingVector = (move.GetSolutionAfterMove() as GroupingVectorEncoding).GroupingVector; 81 PackingPlanParameter.ActualValue = PackingPlanAfterMoveParameter.ActualValue; 73 82 74 83 quality.Value = moveQuality.Value; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveSoftTabuCriterion.cs
r9440 r9495 38 38 get { return false; } 39 39 } 40 public ILookupParameter< SingleGroupingMove> SingleGroupingMoveParameter {41 get { return (ILookupParameter< SingleGroupingMove>)Parameters["SingleGroupingMove"]; }40 public ILookupParameter<IPackingMove> PackingMoveParameter { 41 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 42 42 } 43 43 public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter { … … 65 65 public SingleGroupingMoveSoftTabuCriterion() 66 66 : base() { 67 Parameters.Add(new LookupParameter< SingleGroupingMove>("SingleGroupingMove", "The move to evaluate."));67 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 68 68 Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The solution to evaluate.")); 69 69 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); … … 80 80 public override IOperation Apply() { 81 81 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 82 SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;82 SingleGroupingMove move = PackingMoveParameter.ActualValue as SingleGroupingMove; 83 83 GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue; 84 84 int length = groupingVector.GroupingVector.Length; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingTabuMaker.cs
r9440 r9495 32 32 [StorableClass] 33 33 public class SingleGroupingTabuMaker : TabuMaker, IGroupingVectorMoveOperator{ 34 public ILookupParameter< SingleGroupingMove> SingleGroupingMoveParameter {35 get { return (ILookupParameter< SingleGroupingMove>)Parameters["SingleGroupingMove"]; }34 public ILookupParameter<IPackingMove> PackingMoveParameter { 35 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 36 36 } 37 37 public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter { … … 44 44 public SingleGroupingTabuMaker() 45 45 : base() { 46 Parameters.Add(new LookupParameter<SingleGroupingMove>("SingleGroupingMove", "The move to evaluate."));46 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 47 47 Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The solution to evaluate.")); 48 48 } … … 53 53 54 54 protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) { 55 SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;55 IPackingMove move = PackingMoveParameter.ActualValue; 56 56 GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue; 57 57 double baseQuality = moveQuality; 58 58 if (maximization && quality > moveQuality || !maximization && quality < moveQuality) 59 59 baseQuality = quality; // we make an uphill move, the lower bound is the solution quality 60 61 return new SingleGroupingMoveAttribute (move.Index, move.NewGroup, baseQuality); 60 61 var sgMove = move as SingleGroupingMove; 62 if (sgMove != null) 63 return new SingleGroupingMoveAttribute(sgMove.Index, sgMove.NewGroup, baseQuality); 64 else 65 return move.GetSolutionAfterMove(); 62 66 } 63 67 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/ChangePositionMoveAttribute.cs
r9473 r9495 29 29 public class ChangePositionMoveAttribute : MultiComponentVectorMoveAttribute { 30 30 [Storable] 31 public int Index { get; protected set; } 31 public int AffectedGroup { get; protected set; } 32 [Storable] 33 public int Index { get; protected set; } 34 [Storable] 35 public int ItemID { get; protected set; } 32 36 [Storable] 33 37 public int TargetIndex { get; protected set; } 34 [Storable]35 public int ItemIndex { get; protected set; }36 38 37 39 [StorableConstructor] … … 41 43 this.Index = original.Index; 42 44 this.TargetIndex = original.TargetIndex; 43 this.ItemI ndex = original.ItemIndex;45 this.ItemID = original.ItemID; 44 46 } 45 public ChangePositionMoveAttribute() : this(-1, -1, -1, -1 ) { }46 public ChangePositionMoveAttribute(int index, int targetIndex, int itemIndex, double moveQuality)47 public ChangePositionMoveAttribute() : this(-1, -1, -1, -1, -1) { } 48 public ChangePositionMoveAttribute(int affectedGroup, int index, int itemID, int targetIndex, double moveQuality) 47 49 : base(moveQuality) { 50 AffectedGroup = affectedGroup; 48 51 Index = index; 49 52 TargetIndex = targetIndex; 50 ItemI ndex = itemIndex;53 ItemID = itemID; 51 54 } 52 55 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/MCVTripleMoveAttribute.cs
r9473 r9495 31 31 public int Index { get; protected set; } 32 32 [Storable] 33 public int ItemI ndex{ get; protected set; }33 public int ItemID { get; protected set; } 34 34 [Storable] 35 35 public int TargetIndex { get; protected set; } 36 36 [Storable] 37 public bool RotationBefore { get; protected set; } 38 [Storable] 39 public bool RotationAfter { get; protected set; } 37 public bool Rotation { get; protected set; } 40 38 [Storable] 41 39 public int GroupBefore { get; protected set; } … … 49 47 this.Index = original.Index; 50 48 this.TargetIndex = original.TargetIndex; 51 this.ItemIndex = original.ItemIndex; 52 this.RotationAfter = original.RotationAfter; 53 this.RotationBefore = original.RotationBefore; 49 this.ItemID = original.ItemID; 50 this.Rotation = original.Rotation; 54 51 this.GroupBefore = original.GroupBefore; 55 52 this.GroupAfter = original.GroupAfter; 56 53 } 57 public MCVTripleMoveAttribute() : this(-1, -1, -1, false, false,-1, -1, -1) { }58 public MCVTripleMoveAttribute(int index, int targetIndex, int itemI ndex, bool rotationBefore, bool rotationAfter, int groupBefore, int groupAfter, double moveQuality)54 public MCVTripleMoveAttribute() : this(-1, -1, -1, false, -1, -1, -1) { } 55 public MCVTripleMoveAttribute(int index, int targetIndex, int itemID, bool rotation, int groupBefore, int groupAfter, double moveQuality) 59 56 : base(moveQuality) { 60 57 Index = index; 61 58 TargetIndex = targetIndex; 62 ItemIndex = itemIndex; 63 RotationBefore = rotationBefore; 64 RotationAfter = rotationAfter; 59 ItemID = itemID; 60 Rotation = rotation; 65 61 GroupBefore = groupBefore; 66 62 GroupAfter = groupAfter; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/SingleGroupingMoveAttribute.cs
r9473 r9495 27 27 [Item("SingleGroupingMoveAttribute", "Specifies the tabu attributes for a single grouping move on an multi component vector.")] 28 28 [StorableClass] 29 public class SingleGroupingMoveAttribute : MultiComponentVectorMoveAttribute { 29 public class SingleGroupingMoveAttribute : MultiComponentVectorMoveAttribute { 30 [Storable] 31 public int OldGroup { get; protected set; } 30 32 [Storable] 31 33 public int Index { get; protected set; } 32 34 [Storable] 33 public int AssignedBin { get; protected set; } 35 public int ItemID { get; protected set; } 36 [Storable] 37 public int NewGroup { get; protected set; } 34 38 35 39 [StorableConstructor] 36 40 protected SingleGroupingMoveAttribute(bool deserializing) : base(deserializing) { } 37 41 protected SingleGroupingMoveAttribute(SingleGroupingMoveAttribute original, Cloner cloner) 38 : base(original, cloner) { 42 : base(original, cloner) { 43 this.OldGroup = original.OldGroup; 39 44 this.Index = original.Index; 40 this.AssignedBin = original.AssignedBin; 45 this.ItemID = original.ItemID; 46 this.NewGroup = original.NewGroup; 41 47 } 42 public SingleGroupingMoveAttribute() : this(-1, -1, -1 ) { }43 public SingleGroupingMoveAttribute(int index, int assignedBin, double moveQuality)48 public SingleGroupingMoveAttribute() : this(-1, -1, -1, -1, -1) { } 49 public SingleGroupingMoveAttribute(int oldGroup, int index, int itemID, int newGroup, double moveQuality) 44 50 : base(moveQuality) { 51 OldGroup = oldGroup; 45 52 Index = index; 46 AssignedBin = assignedBin; 53 ItemID = itemID; 54 NewGroup = newGroup; 47 55 } 48 56 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/SingleItemRotationMoveAttribute.cs
r9440 r9495 29 29 public class SingleItemRotationMoveAttribute : MultiComponentVectorMoveAttribute { 30 30 [Storable] 31 public int AffectedGroup { get; protected set; } 32 [Storable] 33 public int Index { get; protected set; } 34 [Storable] 31 35 public int ItemIndex { get; protected set; } 32 36 [Storable] … … 37 41 protected SingleItemRotationMoveAttribute(SingleItemRotationMoveAttribute original, Cloner cloner) 38 42 : base(original, cloner) { 43 this.AffectedGroup = original.AffectedGroup; 44 this.Index = original.Index; 39 45 this.ItemIndex = original.ItemIndex; 40 46 this.ItemRotation = original.ItemRotation; 41 47 } 42 public SingleItemRotationMoveAttribute() : this(-1, false, -1) { }43 public SingleItemRotationMoveAttribute(int itemIndex, bool itemRotation, double moveQuality)48 public SingleItemRotationMoveAttribute() : this(-1, -1, -1, false, -1) { } 49 public SingleItemRotationMoveAttribute(int affectedGroup, int index, int itemIndex, bool itemRotation, double moveQuality) 44 50 : base(moveQuality) { 51 AffectedGroup = affectedGroup; 52 Index = index; 45 53 ItemIndex = itemIndex; 46 54 ItemRotation = itemRotation; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/SwapPositionMoveAttribute.cs
r9473 r9495 29 29 public class SwapPositionMoveAttribute : MultiComponentVectorMoveAttribute { 30 30 [Storable] 31 public int AffectedGroup { get; protected set; } 32 [Storable] 31 33 public int Index1 { get; protected set; } 32 34 [Storable] 33 35 public int Index2 { get; protected set; } 34 36 [Storable] 35 public int ItemI ndex1 { get; protected set; }37 public int ItemID1 { get; protected set; } 36 38 [Storable] 37 public int ItemI ndex2 { get; protected set; }39 public int ItemID2 { get; protected set; } 38 40 39 41 [StorableConstructor] … … 41 43 protected SwapPositionMoveAttribute(SwapPositionMoveAttribute original, Cloner cloner) 42 44 : base(original, cloner) { 45 this.AffectedGroup = original.AffectedGroup; 43 46 this.Index1 = original.Index1; 44 47 this.Index2 = original.Index2; 45 this.ItemI ndex1 = original.ItemIndex1;46 this.ItemI ndex2 = original.ItemIndex2;48 this.ItemID1 = original.ItemID1; 49 this.ItemID2 = original.ItemID2; 47 50 } 48 public SwapPositionMoveAttribute() : this(-1, -1, -1, -1, -1 ) { }49 public SwapPositionMoveAttribute(int index1, int index2, int itemIndex1, int itemIndex2, double moveQuality)51 public SwapPositionMoveAttribute() : this(-1, -1, -1, -1, -1, -1) { } 52 public SwapPositionMoveAttribute(int affectedGroup, int index1, int index2, int itemID1, int itemID2, double moveQuality) 50 53 : base(moveQuality) { 54 AffectedGroup = affectedGroup; 51 55 Index1 = index1; 52 56 Index2 = index2; 53 ItemI ndex1 = itemIndex1;54 ItemI ndex2 = itemIndex2;57 ItemID1 = itemID1; 58 ItemID2 = itemID2; 55 59 } 56 60 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/ExhaustiveMCVTripleMoveGenerator.cs
r9473 r9495 40 40 } 41 41 42 public static IEnumerable<MultiComponentVectorMove> GenerateMCVTripleMoves(MultiComponentVectorEncoding mcv) { 43 int nrOfBins = 0; 44 foreach (var pi in mcv.PackingInformations) { 45 if (pi.AssignedBin > nrOfBins) 46 nrOfBins = pi.AssignedBin; 47 } 48 nrOfBins++; 49 Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>(); 50 for (int i = 0; i < mcv.PackingInformations.Count; i++) { 51 int currentBin = mcv.PackingInformations[i].AssignedBin; 52 if (!indexesPerBin.ContainsKey(currentBin)) 53 indexesPerBin[currentBin] = new List<int>(); 54 indexesPerBin[currentBin].Add(i); 55 } 56 57 for (int index = 0; index < mcv.PackingInformations.Count; index++) { 58 for (int group = 0; group < nrOfBins; group++) { 59 foreach (int targetIndex in indexesPerBin[group]) { 60 yield return new MCVTripleMove(index, false, group, targetIndex, mcv); 61 yield return new MCVTripleMove(index, true, group, targetIndex, mcv); 62 } 63 } 64 } 42 public static IEnumerable<MultiComponentVectorMove> GenerateMCVTripleMoves(MultiComponentVectorEncoding mcv) { 43 foreach (var oldGroup in mcv.PackingInformations) 44 for (int sourceIndex = 0; sourceIndex < oldGroup.Value.Count; sourceIndex++) 45 foreach (var newGroup in mcv.PackingInformations) 46 for (int targetIndex = 0; targetIndex < newGroup.Value.Count; targetIndex++) { 47 yield return new MCVTripleMove(oldGroup.Key, newGroup.Key, sourceIndex, targetIndex, false, mcv); 48 yield return new MCVTripleMove(oldGroup.Key, newGroup.Key, sourceIndex, targetIndex, true, mcv); 49 } 65 50 } 66 51 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/ChangePositionMove.cs
r9473 r9495 24 24 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.BinPacking.Interfaces; 26 27 27 28 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { … … 29 30 [StorableClass] 30 31 public class ChangePositionMove : MultiComponentVectorMove { 32 [Storable] 33 public int AffectedGroup { get; protected set; } 31 34 [Storable] 32 35 public int Index { get; protected set; } … … 38 41 protected ChangePositionMove(ChangePositionMove original, Cloner cloner) 39 42 : base(original, cloner) { 43 this.AffectedGroup = original.AffectedGroup; 40 44 this.Index = original.Index; 41 45 this.TargetIndex = original.TargetIndex; 42 46 } 43 public ChangePositionMove(int index, int targetIndex, MultiComponentVectorEncoding multiComponentVector)47 public ChangePositionMove(int affectedBin, int index, int targetIndex, MultiComponentVectorEncoding multiComponentVector) 44 48 : base(multiComponentVector) { 49 AffectedGroup = affectedBin; 45 50 Index = index; 46 51 TargetIndex = targetIndex; … … 51 56 } 52 57 53 public override MultiComponentVectorEncoding GetVectorAfterMove() {54 return GetVectorAfterMove(MultiComponentVector, Index, TargetIndex);58 public override IPackingSolutionEncoding GetSolutionAfterMove() { 59 return GetVectorAfterMove(MultiComponentVector, AffectedGroup, Index, TargetIndex); 55 60 } 56 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int index, int targetIndex) {61 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedBin, int index, int targetIndex) { 57 62 var result = multiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding; 58 var aux = result.PackingInformations[ index];59 result.PackingInformations .RemoveAt(index);60 result.PackingInformations .Insert(targetIndex, aux);63 var aux = result.PackingInformations[affectedBin][index]; 64 result.PackingInformations[affectedBin].Remove(aux); 65 result.PackingInformations[affectedBin].Insert(targetIndex, aux); 61 66 return result; 62 67 } … … 67 72 68 73 public override string ToString() { 69 return "PM(i=" + Index + ",ti=" + TargetIndex + ")"; 74 return "PM(g=" + AffectedGroup + ",i=" + Index + ",ti=" + TargetIndex + ")"; 75 } 76 77 public override MultiComponentVectorMoveAttribute GetAttribute(double quality) { 78 return new ChangePositionMoveAttribute(AffectedGroup, Index, 79 MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID, 80 TargetIndex, quality); 81 } 82 83 public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) { 84 ChangePositionMoveAttribute actualAttribute = attribute as ChangePositionMoveAttribute; 85 if (actualAttribute != null) { 86 if (hardCriterion) { 87 if (Index == actualAttribute.Index 88 || TargetIndex == actualAttribute.TargetIndex 89 || MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID == actualAttribute.ItemID) 90 return true; 91 } else { 92 if (Index == actualAttribute.Index 93 && TargetIndex == actualAttribute.TargetIndex 94 && MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID == actualAttribute.ItemID) 95 return true; 96 } 97 } 98 99 return false; 70 100 } 71 101 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/MCVTripleMove.cs
r9473 r9495 24 24 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.BinPacking.Interfaces; 26 27 27 28 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { 28 29 [Item("MCVTripleMove", "A move on a multi component vector that is specified by a rotation-value, two indexes and a groupNr.")] 29 30 [StorableClass] 30 public class MCVTripleMove : MultiComponentVectorMove { 31 public class MCVTripleMove : MultiComponentVectorMove { 31 32 [Storable] 32 public int Index { get; protected set; } 33 public int OldGroup { get; protected set; } 34 [Storable] 35 public int NewGroup { get; protected set; } 36 [Storable] 37 public int Index { get; protected set; } 38 [Storable] 39 public int TargetIndex { get; protected set; } 33 40 [Storable] 34 41 public bool Rotation { get; protected set; } 35 [Storable]36 public int Group { get; protected set; }37 [Storable]38 public int TargetIndex { get; protected set; }39 42 40 43 [StorableConstructor] 41 44 protected MCVTripleMove(bool deserializing) : base(deserializing) { } 42 45 protected MCVTripleMove(MCVTripleMove original, Cloner cloner) 43 : base(original, cloner) { 44 this.Index = original.Index; 46 : base(original, cloner) { 47 this.OldGroup = original.OldGroup; 48 this.NewGroup = original.NewGroup; 49 this.Index = original.Index; 50 this.TargetIndex = original.TargetIndex; 45 51 this.Rotation = original.Rotation; 46 this.Group = original.Group;47 this.TargetIndex = original.TargetIndex;48 52 } 49 public MCVTripleMove(int index, bool rotation, int group, int targetIndex, MultiComponentVectorEncoding multiComponentVector) 50 : base(multiComponentVector) { 51 Index = index; 53 public MCVTripleMove(int oldGroup, int newGroup, int index, int targetIndex, bool rotation, MultiComponentVectorEncoding multiComponentVector) 54 : base(multiComponentVector) { 55 OldGroup = oldGroup; 56 NewGroup = newGroup; 57 Index = index; 58 TargetIndex = targetIndex; 52 59 Rotation = rotation; 53 Group = group;54 TargetIndex = targetIndex;55 60 } 56 61 … … 59 64 } 60 65 61 public override MultiComponentVectorEncoding GetVectorAfterMove() {62 var result = MultiComponentVector ;66 public override IPackingSolutionEncoding GetSolutionAfterMove() { 67 var result = MultiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding; 63 68 if (Rotation) 64 result = SingleItemRotationMove.GetVectorAfterMove(MultiComponentVector, Index); 65 if (!MultiComponentVector.PackingInformations[Index].AssignedBin.Equals(Group)) 66 result = SingleGroupingMove.GetVectorAfterMove(result, Index, Group); 67 if (!Index.Equals(TargetIndex)) 68 result = ChangePositionMove.GetVectorAfterMove(result, Index, TargetIndex); 69 result = SingleItemRotationMove.GetVectorAfterMove(result, OldGroup, Index); 70 if (!OldGroup.Equals(NewGroup)) { 71 result = SingleGroupingMove.GetVectorAfterMove(result, OldGroup, Index, NewGroup); 72 int newIndex = result.PackingInformations[NewGroup].Count - 1; 73 if (!newIndex.Equals(TargetIndex)) 74 result = ChangePositionMove.GetVectorAfterMove(result, NewGroup, newIndex, TargetIndex); 75 } else if (!Index.Equals(TargetIndex)) 76 result = ChangePositionMove.GetVectorAfterMove(result, NewGroup, Index, TargetIndex); 69 77 return result; 70 78 } … … 75 83 76 84 public override string ToString() { 77 return "TM(i=" + Index + ",r=" + Rotation + ",g=" + Group + ",ti=" + TargetIndex + ")"; 85 return "TM(og=" + OldGroup + ",ng=" + NewGroup + ",i=" + Index + ",ti=" + TargetIndex + ",r=" + Rotation + ")"; 86 } 87 88 89 public override MultiComponentVectorMoveAttribute GetAttribute(double quality) { 90 return new MCVTripleMoveAttribute(Index, TargetIndex, MultiComponentVector.PackingInformations[OldGroup][Index].ItemID, 91 Rotation, OldGroup, NewGroup, quality); 92 } 93 94 public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) { 95 MCVTripleMoveAttribute actualAttribute = attribute as MCVTripleMoveAttribute; 96 if (actualAttribute != null) { 97 if (hardCriterion) { 98 if ((Index == actualAttribute.Index && TargetIndex == actualAttribute.TargetIndex) 99 || MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID 100 || (OldGroup == actualAttribute.GroupBefore && NewGroup == actualAttribute.GroupAfter)) 101 return true; 102 } else { 103 if ((Index == actualAttribute.Index && TargetIndex == actualAttribute.TargetIndex) 104 && MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID 105 && Rotation == actualAttribute.Rotation 106 && (OldGroup == actualAttribute.GroupBefore && NewGroup == actualAttribute.GroupAfter)) 107 return true; 108 } 109 } 110 return false; 78 111 } 79 112 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/MultiComponentVectorMove.cs
r9440 r9495 25 25 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Problems.BinPacking.Interfaces; 27 28 28 29 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { 29 30 [Item("MultiComponentVectorMove", "An abstract move for a multi component vector encoded solution.")] 30 31 [StorableClass] 31 public abstract class MultiComponentVectorMove : Item {32 public abstract class MultiComponentVectorMove : Item, IPackingMove { 32 33 [Storable] 33 34 public MultiComponentVectorEncoding MultiComponentVector { get; protected set; } … … 45 46 } 46 47 47 public abstract MultiComponentVectorEncoding GetVectorAfterMove();48 public abstract IPackingSolutionEncoding GetSolutionAfterMove(); 48 49 public abstract Type GetMoveAttributeType(); 50 public abstract MultiComponentVectorMoveAttribute GetAttribute(double quality); 51 public abstract bool BelongsToAttribute (MultiComponentVectorMoveAttribute attribute, bool hardCriterion); 49 52 } 50 53 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleGroupingMove.cs
r9473 r9495 24 24 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.BinPacking.Interfaces; 26 27 27 28 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { 28 29 [Item("SingleGroupingMove", "A move on a multi component vector that is specified by a single index and a new grouping-value. The grouping of the item on the specified index is changed to the new value.")] 29 30 [StorableClass] 30 public class SingleGroupingMove : MultiComponentVectorMove { 31 public class SingleGroupingMove : MultiComponentVectorMove { 32 [Storable] 33 public int OldGroup { get; protected set; } 31 34 [Storable] 32 35 public int Index { get; protected set; } … … 38 41 protected SingleGroupingMove(SingleGroupingMove original, Cloner cloner) 39 42 : base(original, cloner) { 43 this.OldGroup = original.OldGroup; 40 44 this.Index = original.Index; 41 45 this.NewGroup = original.NewGroup; 42 46 } 43 public SingleGroupingMove(int index, int newGroup, MultiComponentVectorEncoding multiComponentVector)47 public SingleGroupingMove(int oldGroup, int index, int newGroup, MultiComponentVectorEncoding multiComponentVector) 44 48 : base(multiComponentVector) { 45 Index = index; 46 NewGroup = newGroup; 49 OldGroup = oldGroup; 50 Index = index; 51 NewGroup = newGroup; 47 52 } 48 53 … … 51 56 } 52 57 53 public override MultiComponentVectorEncoding GetVectorAfterMove() {54 return GetVectorAfterMove(MultiComponentVector, Index, NewGroup);58 public override IPackingSolutionEncoding GetSolutionAfterMove() { 59 return GetVectorAfterMove(MultiComponentVector, OldGroup, Index, NewGroup); 55 60 } 56 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding originalSolution, int itemIndex, int binNr) {61 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding originalSolution, int oldBin, int index, int newBin) { 57 62 var solution = originalSolution.Clone (new Cloner()) as MultiComponentVectorEncoding; 58 var itemgene = solution.PackingInformations[itemIndex]; 59 solution.PackingInformations.Remove(itemgene); 60 itemgene.AssignedBin = binNr; 61 int targetIndex = solution.PackingInformations.FindLastIndex(pi => pi.AssignedBin == binNr); 62 solution.PackingInformations.Insert(targetIndex + 1, itemgene); 63 //solution.PackingInformations[itemIndex].AssignedBin = binNr; 63 var itemgene = solution.PackingInformations[oldBin][index]; 64 solution.PackingInformations[oldBin].Remove(itemgene); 65 solution.PackingInformations[newBin].Add(itemgene); 64 66 return solution; 65 67 } … … 70 72 71 73 public override string ToString() { 72 return "GM(i="+Index+",g="+NewGroup+")"; 74 return "GM(og"+OldGroup+",i="+Index+",ng="+NewGroup+")"; 75 } 76 77 public override MultiComponentVectorMoveAttribute GetAttribute(double quality) { 78 return new SingleGroupingMoveAttribute(OldGroup, Index, 79 MultiComponentVector.PackingInformations[OldGroup][Index].ItemID, NewGroup, quality); 80 } 81 82 public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) { 83 SingleGroupingMoveAttribute actualAttribute = attribute as SingleGroupingMoveAttribute; 84 if (actualAttribute != null) { 85 if (hardCriterion) { 86 if (MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID 87 || NewGroup == actualAttribute.NewGroup) 88 return true; 89 } else { 90 if (MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID 91 && NewGroup == actualAttribute.NewGroup) 92 return true; 93 } 94 } 95 return false; 73 96 } 74 97 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleItemRotationMove.cs
r9473 r9495 24 24 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.BinPacking.Interfaces; 26 27 27 28 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { … … 30 31 public class SingleItemRotationMove : MultiComponentVectorMove { 31 32 [Storable] 32 public int ItemIndex { get; protected set; } 33 public int AffectedGroup { get; protected set; } 34 [Storable] 35 public int Index { get; protected set; } 33 36 34 37 [StorableConstructor] … … 36 39 protected SingleItemRotationMove(SingleItemRotationMove original, Cloner cloner) 37 40 : base(original, cloner) { 38 this.ItemIndex = original.ItemIndex; 41 this.AffectedGroup = original.AffectedGroup; 42 this.Index = original.Index; 39 43 } 40 public SingleItemRotationMove(int index, MultiComponentVectorEncoding multiComponentVector)44 public SingleItemRotationMove(int affectedBin, int index, MultiComponentVectorEncoding multiComponentVector) 41 45 : base(multiComponentVector) { 42 ItemIndex = index; 46 AffectedGroup = affectedBin; 47 Index = index; 43 48 } 44 49 … … 47 52 } 48 53 49 public override MultiComponentVectorEncoding GetVectorAfterMove() {50 return GetVectorAfterMove (MultiComponentVector, ItemIndex);54 public override IPackingSolutionEncoding GetSolutionAfterMove() { 55 return GetVectorAfterMove (MultiComponentVector, AffectedGroup, Index); 51 56 } 52 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int itemIndex) {57 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedGroup, int index) { 53 58 var result = multiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding; 54 result.PackingInformations[ itemIndex].Rotated = !result.PackingInformations[itemIndex].Rotated;59 result.PackingInformations[affectedGroup][index].Rotated = !result.PackingInformations[affectedGroup][index].Rotated; 55 60 return result; 56 61 } … … 61 66 62 67 public override string ToString() { 63 return "RM(i=" + ItemIndex+")"; 68 return "RM(g=" + AffectedGroup + ",i=" + Index + ")"; 69 } 70 71 public override MultiComponentVectorMoveAttribute GetAttribute(double quality) { 72 return new SingleItemRotationMoveAttribute(AffectedGroup, Index, 73 MultiComponentVector.PackingInformations[AffectedGroup][Index].ItemID, 74 MultiComponentVector.PackingInformations[AffectedGroup][Index].Rotated, quality); 75 } 76 77 public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) { 78 SingleItemRotationMoveAttribute actualAttribute = attribute as SingleItemRotationMoveAttribute; 79 if (actualAttribute != null) { 80 if (hardCriterion) { 81 if (AffectedGroup == actualAttribute.AffectedGroup || MultiComponentVector.PackingInformations[AffectedGroup][Index].Rotated == actualAttribute.ItemRotation) 82 return true; 83 } else { 84 if (AffectedGroup == actualAttribute.AffectedGroup && MultiComponentVector.PackingInformations[AffectedGroup][Index].Rotated == actualAttribute.ItemRotation) 85 return true; 86 } 87 } 88 return false; 64 89 } 65 90 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SwapPositionMove.cs
r9473 r9495 24 24 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.BinPacking.Interfaces; 26 27 27 28 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { … … 29 30 [StorableClass] 30 31 public class SwapPositionMove : MultiComponentVectorMove { 32 [Storable] 33 public int AffectedGroup { get; protected set; } 31 34 [Storable] 32 35 public int Index1 { get; protected set; } … … 38 41 protected SwapPositionMove(SwapPositionMove original, Cloner cloner) 39 42 : base(original, cloner) { 40 this.Index1 = original.Index1; 41 this.Index2 = original.Index2; 43 this.AffectedGroup = original.AffectedGroup; 44 this.Index1 = original.Index1; 45 this.Index2 = original.Index2; 42 46 } 43 public SwapPositionMove(int index1, int index2, MultiComponentVectorEncoding multiComponentVector)47 public SwapPositionMove(int affectedGroup, int index1, int index2, MultiComponentVectorEncoding multiComponentVector) 44 48 : base(multiComponentVector) { 49 AffectedGroup = affectedGroup; 45 50 Index1 = index1; 46 51 Index2 = index2; … … 51 56 } 52 57 53 public override MultiComponentVectorEncoding GetVectorAfterMove() {54 return GetVectorAfterMove(MultiComponentVector, Index1, Index2);58 public override IPackingSolutionEncoding GetSolutionAfterMove() { 59 return GetVectorAfterMove(MultiComponentVector, AffectedGroup, Index1, Index2); 55 60 } 56 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int index1, int index2) {61 public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedGroup, int index1, int index2) { 57 62 var result = multiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding; 58 var aux = result.PackingInformations[ index1];59 result.PackingInformations[ index1] = result.PackingInformations[index2];60 result.PackingInformations[ index2] = aux;63 var aux = result.PackingInformations[affectedGroup][index1]; 64 result.PackingInformations[affectedGroup][index1] = result.PackingInformations[affectedGroup][index2]; 65 result.PackingInformations[affectedGroup][index2] = aux; 61 66 return result; 62 67 } … … 67 72 68 73 public override string ToString() { 69 return "SM(i1=" + Index1 + ",i2=" + Index2 + ")"; 74 return "SPM(g=" + AffectedGroup + ",i1=" + Index1 + ",i2=" + Index2 + ")"; 75 } 76 77 public override MultiComponentVectorMoveAttribute GetAttribute(double quality) { 78 return new SwapPositionMoveAttribute(AffectedGroup, Index1, Index2, 79 MultiComponentVector.PackingInformations[AffectedGroup][Index1].ItemID, 80 MultiComponentVector.PackingInformations[AffectedGroup][Index2].ItemID, quality); 81 } 82 83 public override bool BelongsToAttribute(MultiComponentVectorMoveAttribute attribute, bool hardCriterion) { 84 SwapPositionMoveAttribute actualAttribute = attribute as SwapPositionMoveAttribute; 85 if (actualAttribute != null) { 86 if (hardCriterion) { 87 if (Index1 == actualAttribute.Index1 88 || Index2 == actualAttribute.Index2 89 || MultiComponentVector.PackingInformations[AffectedGroup][Index1].ItemID == actualAttribute.ItemID1 90 || MultiComponentVector.PackingInformations[AffectedGroup][Index2].ItemID == actualAttribute.ItemID2) 91 return true; 92 } else { 93 if (Index1 == actualAttribute.Index1 94 && Index2 == actualAttribute.Index2 95 && MultiComponentVector.PackingInformations[AffectedGroup][Index1].ItemID == actualAttribute.ItemID1 96 && MultiComponentVector.PackingInformations[AffectedGroup][Index2].ItemID == actualAttribute.ItemID2) 97 return true; 98 } 99 } 100 return false; 70 101 } 71 102 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveGenerator.cs
r9473 r9495 42 42 get { return (ILookupParameter<MultiComponentVectorEncoding>)Parameters["MultiComponentVector"]; } 43 43 } 44 public ILookupParameter< MultiComponentVectorMove> MultiComponentVectorMoveParameter {45 get { return (LookupParameter< MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }44 public ILookupParameter<IPackingMove> PackingMoveParameter { 45 get { return (LookupParameter<IPackingMove>)Parameters["PackingMove"]; } 46 46 } 47 47 protected ScopeParameter CurrentScopeParameter { … … 56 56 : base() { 57 57 Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The multi component vector for which moves should be generated.")); 58 Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The moves that should be generated in subscopes."));58 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The moves that should be generated in subscopes.")); 59 59 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes.")); 60 60 } … … 62 62 63 63 public static int NrOfRotationMoves(MultiComponentVectorEncoding mcv) { 64 return mcv. PackingInformations.Count;64 return mcv.NrOfItems; 65 65 } 66 66 public static IEnumerable<MultiComponentVectorMove> GenerateRotationMoves(MultiComponentVectorEncoding multiComponentVector) { 67 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) 68 yield return new SingleItemRotationMove(i, multiComponentVector); 67 for (int binNr = 0; binNr < multiComponentVector.PackingInformations.Count; binNr++) 68 for (int index = 0; index < multiComponentVector.PackingInformations[binNr].Count; index++) 69 yield return new SingleItemRotationMove(binNr, index, multiComponentVector); 69 70 } 70 71 71 72 public static int NrOfSingleGroupingMoves(MultiComponentVectorEncoding mcv) { 72 int nrOfBins = 0; 73 foreach (var pi in mcv.PackingInformations) { 74 if (pi.AssignedBin > nrOfBins) 75 nrOfBins = pi.AssignedBin; 76 } 77 nrOfBins++; 78 return mcv.PackingInformations.Count * (nrOfBins - 1); 73 return mcv.NrOfItems * (mcv.NrOfBins - 1); 79 74 } 80 75 public static IEnumerable<MultiComponentVectorMove> GenerateSingleGroupingMoves(MultiComponentVectorEncoding multiComponentVector) { 81 int nrOfBins = 0; 82 foreach (var pi in multiComponentVector.PackingInformations) { 83 if (pi.AssignedBin > nrOfBins) 84 nrOfBins = pi.AssignedBin; 85 } 86 nrOfBins++; 87 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) 88 for (int j = 0; j < nrOfBins; j++) { 89 if (j != multiComponentVector.PackingInformations[i].AssignedBin) 90 yield return new SingleGroupingMove(i, j, multiComponentVector); 91 } 76 for (int oldBin = 0; oldBin < multiComponentVector.PackingInformations.Count; oldBin++) 77 for (int index = 0; index < multiComponentVector.PackingInformations[oldBin].Count; index++) 78 for (int newBin = 0; newBin < multiComponentVector.NrOfBins; newBin++) 79 if (newBin != oldBin) 80 yield return new SingleGroupingMove(oldBin, index, newBin, multiComponentVector); 92 81 } 93 82 94 83 public static int NrOfSwapPositionMoves(MultiComponentVectorEncoding mcv) { 95 int nrOfBins = 0;96 foreach (var pi in mcv.PackingInformations) {97 if (pi.AssignedBin > nrOfBins)98 nrOfBins = pi.AssignedBin;99 }100 nrOfBins++;101 int[] itemsPerBin = new int[nrOfBins];102 foreach (var pi in mcv.PackingInformations) {103 itemsPerBin[pi.AssignedBin]++;104 }105 84 int nrOfSwapPositionMoves = 0; 106 foreach ( int items in itemsPerBin) {107 nrOfSwapPositionMoves += ( items * (items- 1)) / 2;85 foreach (var groupInformations in mcv.PackingInformations) { 86 nrOfSwapPositionMoves += (groupInformations.Value.Count * (groupInformations.Value.Count - 1)) / 2; 108 87 } 109 88 return nrOfSwapPositionMoves; 110 89 } 111 90 public static IEnumerable<MultiComponentVectorMove> GenerateSwapPositionMoves(MultiComponentVectorEncoding multiComponentVector) { 112 Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>(); 113 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) { 114 int currentBin = multiComponentVector.PackingInformations[i].AssignedBin; 115 if (!indexesPerBin.ContainsKey(currentBin)) 116 indexesPerBin[currentBin] = new List<int>(); 117 indexesPerBin[currentBin].Add(i); 118 } 119 foreach (var entry in indexesPerBin) { 120 for (int i = 0; i < entry.Value.Count - 1; i++) 121 for (int j = i + 1; j < entry.Value.Count; j++) 122 yield return new SwapPositionMove(entry.Value[i], entry.Value[j], multiComponentVector); 123 } 91 for (int bin = 0; bin < multiComponentVector.PackingInformations.Count; bin++) 92 for (int oldIndex = 0; oldIndex < multiComponentVector.PackingInformations[bin].Count - 1; oldIndex++) 93 for (int newIndex = oldIndex + 1; newIndex < multiComponentVector.PackingInformations[bin].Count; newIndex++) 94 yield return new SwapPositionMove(bin, oldIndex, newIndex, multiComponentVector); 124 95 } 125 96 126 97 public static int NrOfChangePositionMoves(MultiComponentVectorEncoding mcv) { 127 int nrOfBins = 0; 128 foreach (var pi in mcv.PackingInformations) { 129 if (pi.AssignedBin > nrOfBins) 130 nrOfBins = pi.AssignedBin; 98 int nrOfChangePositionMoves = 0; 99 foreach (var groupInformations in mcv.PackingInformations) { 100 nrOfChangePositionMoves += (groupInformations.Value.Count * (groupInformations.Value.Count - 1)) / 2; 131 101 } 132 nrOfBins++; 133 int[] itemsPerBin = new int[nrOfBins]; 134 foreach (var pi in mcv.PackingInformations) { 135 itemsPerBin[pi.AssignedBin]++; 136 } 137 int nrOfSwapPositionMoves = 0; 138 foreach (int items in itemsPerBin) { 139 nrOfSwapPositionMoves += (items * (items - 1)) / 2; 140 } 141 return nrOfSwapPositionMoves; 102 return nrOfChangePositionMoves; 142 103 } 143 104 public static IEnumerable<MultiComponentVectorMove> GenerateChangePositionMoves(MultiComponentVectorEncoding multiComponentVector) { 144 Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>(); 145 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) { 146 int currentBin = multiComponentVector.PackingInformations[i].AssignedBin; 147 if (!indexesPerBin.ContainsKey(currentBin)) 148 indexesPerBin[currentBin] = new List<int>(); 149 indexesPerBin[currentBin].Add(i); 150 } 151 foreach (var entry in indexesPerBin) { 152 for (int i = 0; i < entry.Value.Count - 1; i++) 153 for (int j = i + 1; j < entry.Value.Count; j++) 154 yield return new ChangePositionMove(entry.Value[i], entry.Value[j], multiComponentVector); 155 } 105 for (int bin = 0; bin < multiComponentVector.PackingInformations.Count; bin++) 106 for (int oldIndex = 0; oldIndex < multiComponentVector.PackingInformations[bin].Count - 1; oldIndex++) 107 for (int newIndex = oldIndex + 1; newIndex < multiComponentVector.PackingInformations[bin].Count; newIndex++) 108 yield return new ChangePositionMove(bin, oldIndex, newIndex, multiComponentVector); 156 109 } 157 110 … … 162 115 for (int i = 0; i < moveScopes.Length; i++) { 163 116 moveScopes[i] = new Scope(i.ToString()); 164 moveScopes[i].Variables.Add(new Variable( MultiComponentVectorMoveParameter.ActualName, moves[i]));117 moveScopes[i].Variables.Add(new Variable(PackingMoveParameter.ActualName, moves[i])); 165 118 } 166 119 CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes); -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveHardTabuCriterion.cs
r9473 r9495 38 38 get { return false; } 39 39 } 40 public ILookupParameter< MultiComponentVectorMove> MultiComponentVectorMoveParameter {41 get { return (ILookupParameter< MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }40 public ILookupParameter<IPackingMove> PackingMoveParameter { 41 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 42 42 } 43 43 public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter { … … 65 65 public MultiComponentVectorMoveHardTabuCriterion() 66 66 : base() { 67 Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));67 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 68 68 Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate.")); 69 69 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); … … 80 80 public override IOperation Apply() { 81 81 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 82 MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;82 MultiComponentVectorMove move = PackingMoveParameter.ActualValue as MultiComponentVectorMove; 83 83 MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue; 84 84 int length = multiComponentVector.PackingInformations.Count; … … 94 94 private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) { 95 95 bool isTabu = false; 96 SingleItemRotationMove sirm = move as SingleItemRotationMove;97 SingleGroupingMove sgm = move as SingleGroupingMove;98 SwapPositionMove spm = move as SwapPositionMove;99 ChangePositionMove cpm = move as ChangePositionMove;100 MCVTripleMove tm = move as MCVTripleMove;101 96 var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType())); 102 97 103 if (sirm != null) { 104 foreach (IItem tabuMove in attributes) { 105 SingleItemRotationMoveAttribute sirmAttr = (tabuMove as SingleItemRotationMoveAttribute); 106 if (sirmAttr.MoveQuality.Equals(moveQuality)) 107 return true; 108 if (sirmAttr != null 109 && (!useAspiration 110 || maximization && moveQuality <= sirmAttr.MoveQuality 111 || !maximization && moveQuality >= sirmAttr.MoveQuality)) { 112 if (sirm.ItemIndex == sirmAttr.ItemIndex || multiComponentVector.PackingInformations[sirm.ItemIndex].Rotated == sirmAttr.ItemRotation) 113 isTabu = true; 114 } 115 if (isTabu) break; 98 foreach (IItem attr in attributes) { 99 MultiComponentVectorMoveAttribute mcvAttr = attr as MultiComponentVectorMoveAttribute; 100 if (mcvAttr != null 101 && (!useAspiration 102 || maximization && moveQuality <= mcvAttr.MoveQuality 103 || !maximization && moveQuality >= mcvAttr.MoveQuality)) { 104 105 isTabu = move.BelongsToAttribute(mcvAttr, true); 116 106 } 117 } else if (sgm != null) { 118 foreach (IItem tabuMove in attributes) { 119 SingleGroupingMoveAttribute sgmAttr = (tabuMove as SingleGroupingMoveAttribute); 120 if (sgmAttr.MoveQuality.Equals(moveQuality)) 121 return true; 122 if (sgmAttr != null 123 && (!useAspiration 124 || maximization && moveQuality <= sgmAttr.MoveQuality 125 || !maximization && moveQuality >= sgmAttr.MoveQuality)) { 126 if ( multiComponentVector.PackingInformations[sgm.Index].ItemIndex == multiComponentVector.PackingInformations[sgmAttr.Index].ItemIndex 127 || multiComponentVector.PackingInformations[sgm.Index].AssignedBin == sgmAttr.AssignedBin) 128 isTabu = true; 129 } 130 if (isTabu) break; 131 } 132 } else if (spm != null) { 133 foreach (IItem tabuMove in attributes) { 134 SwapPositionMoveAttribute spmAttr = (tabuMove as SwapPositionMoveAttribute); 135 if (spmAttr.MoveQuality.Equals(moveQuality)) 136 return true; 137 if (spmAttr != null 138 && (!useAspiration 139 || maximization && moveQuality <= spmAttr.MoveQuality 140 || !maximization && moveQuality >= spmAttr.MoveQuality)) { 141 if (spm.Index1 == spmAttr.Index1 142 || spm.Index2 == spmAttr.Index2 143 || multiComponentVector.PackingInformations[spm.Index1].ItemIndex == spmAttr.ItemIndex1 144 || multiComponentVector.PackingInformations[spm.Index2].ItemIndex == spmAttr.ItemIndex2) 145 isTabu = true; 146 } 147 if (isTabu) break; 148 } 149 } else if (cpm != null) { 150 foreach (IItem tabuMove in attributes) { 151 ChangePositionMoveAttribute cpmAttr = (tabuMove as ChangePositionMoveAttribute); 152 if (cpmAttr.MoveQuality.Equals(moveQuality)) 153 return true; 154 if (cpmAttr != null 155 && (!useAspiration 156 || maximization && moveQuality <= cpmAttr.MoveQuality 157 || !maximization && moveQuality >= cpmAttr.MoveQuality)) { 158 if (cpm.Index == cpmAttr.Index 159 || cpm.TargetIndex == cpmAttr.TargetIndex 160 || multiComponentVector.PackingInformations[cpm.Index].ItemIndex == cpmAttr.ItemIndex) 161 isTabu = true; 162 } 163 if (isTabu) break; 164 } 165 } else if (tm != null) { 166 foreach (IItem tabuMove in attributes) { 167 MCVTripleMoveAttribute tmAttr = (tabuMove as MCVTripleMoveAttribute); 168 if (tmAttr.MoveQuality.Equals(moveQuality)) 169 return true; 170 if (tmAttr != null 171 && (!useAspiration 172 || maximization && moveQuality <= tmAttr.MoveQuality 173 || !maximization && moveQuality >= tmAttr.MoveQuality)) { 174 if ((tm.Index == tmAttr.Index && tm.TargetIndex == tmAttr.TargetIndex) 175 || tm.Index == tmAttr.Index 176 || multiComponentVector.PackingInformations[tm.Index].ItemIndex == tmAttr.ItemIndex 177 ) 178 isTabu = true; 179 } 180 if (isTabu) break; 181 } 182 } 183 184 107 if (isTabu) break; 108 } 185 109 186 110 return isTabu; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveMaker.cs
r9473 r9495 42 42 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 43 43 } 44 public ILookupParameter< MultiComponentVectorMove> MultiComponentVectorMoveParameter {45 get { return (ILookupParameter< MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }44 public ILookupParameter<IPackingMove> PackingMoveParameter { 45 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 46 46 } 47 47 public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter { 48 48 get { return (ILookupParameter<MultiComponentVectorEncoding>)Parameters["MultiComponentVector"]; } 49 } 50 public ILookupParameter<IPackingPlan> PackingPlanParameter { 51 get { return (ILookupParameter<IPackingPlan>)Parameters["PackingPlan"]; } 52 } 53 public ILookupParameter<IPackingPlan> PackingPlanAfterMoveParameter { 54 get { return (ILookupParameter<IPackingPlan>)Parameters["PackingPlanAfterMove"]; } 49 55 } 50 56 … … 55 61 : base() { 56 62 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the solution.")); 57 Parameters.Add(new LookupParameter< MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));63 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 58 64 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move.")); 59 65 Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution as grouping vector.")); 66 Parameters.Add(new LookupParameter<IPackingPlan>("PackingPlan", "The currently best performing, decoded bin-packing solution represented as generalized packing-plan.")); 67 Parameters.Add(new LookupParameter<IPackingPlan>("PackingPlanAfterMove", "The moved and decoded bin-packing solution represented as generalized packing-plan.")); 60 68 } 61 69 … … 65 73 66 74 public override IOperation Apply() { 67 MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;75 IPackingMove move = PackingMoveParameter.ActualValue; 68 76 MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue; 69 77 DoubleValue moveQuality = MoveQualityParameter.ActualValue; 70 78 DoubleValue quality = QualityParameter.ActualValue; 71 79 72 multiComponentVector.PackingInformations = move.GetVectorAfterMove().PackingInformations; 80 multiComponentVector.PackingInformations = (move.GetSolutionAfterMove() as MultiComponentVectorEncoding).PackingInformations; 81 PackingPlanParameter.ActualValue = PackingPlanAfterMoveParameter.ActualValue; 73 82 74 83 quality.Value = moveQuality.Value; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveSoftTabuCriterion.cs
r9473 r9495 38 38 get { return false; } 39 39 } 40 public ILookupParameter< MultiComponentVectorMove> MultiComponentVectorMoveParameter {41 get { return (ILookupParameter< MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }40 public ILookupParameter<IPackingMove> PackingMoveParameter { 41 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 42 42 } 43 43 public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter { … … 65 65 public MultiComponentVectorMoveSoftTabuCriterion() 66 66 : base() { 67 Parameters.Add(new LookupParameter< MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));67 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 68 68 Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate.")); 69 69 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); … … 80 80 public override IOperation Apply() { 81 81 ItemList<IItem> tabuList = TabuListParameter.ActualValue; 82 MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;82 MultiComponentVectorMove move = PackingMoveParameter.ActualValue as MultiComponentVectorMove; 83 83 MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue; 84 84 int length = multiComponentVector.PackingInformations.Count; … … 94 94 private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) { 95 95 bool isTabu = false; 96 97 SingleItemRotationMove sirm = move as SingleItemRotationMove;98 SingleGroupingMove sgm = move as SingleGroupingMove;99 SwapPositionMove spm = move as SwapPositionMove;100 ChangePositionMove cpm = move as ChangePositionMove;101 MCVTripleMove tm = move as MCVTripleMove;102 96 var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType())); 103 97 104 if (sirm != null) { 105 foreach (IItem tabuMove in attributes) { 106 SingleItemRotationMoveAttribute sirmAttr = (tabuMove as SingleItemRotationMoveAttribute); 107 if (sirmAttr != null 108 && (!useAspiration 109 || maximization && moveQuality <= sirmAttr.MoveQuality 110 || !maximization && moveQuality >= sirmAttr.MoveQuality)) { 111 if (sirm.ItemIndex == sirmAttr.ItemIndex && multiComponentVector.PackingInformations[sirm.ItemIndex].Rotated == sirmAttr.ItemRotation) 112 isTabu = true; 113 } 114 if (isTabu) break; 98 foreach (IItem attr in attributes) { 99 MultiComponentVectorMoveAttribute mcvAttr = attr as MultiComponentVectorMoveAttribute; 100 if (mcvAttr != null 101 && (!useAspiration 102 || maximization && moveQuality <= mcvAttr.MoveQuality 103 || !maximization && moveQuality >= mcvAttr.MoveQuality)) { 104 105 isTabu = move.BelongsToAttribute(mcvAttr, false); 115 106 } 116 } else if (sgm != null) { 117 foreach (IItem tabuMove in attributes) { 118 SingleGroupingMoveAttribute sgmAttr = (tabuMove as SingleGroupingMoveAttribute); 119 if (sgmAttr != null 120 && (!useAspiration 121 || maximization && moveQuality <= sgmAttr.MoveQuality 122 || !maximization && moveQuality >= sgmAttr.MoveQuality)) { 123 if (multiComponentVector.PackingInformations[sgm.Index].ItemIndex == multiComponentVector.PackingInformations[sgmAttr.Index].ItemIndex 124 && multiComponentVector.PackingInformations[sgm.Index].AssignedBin == sgmAttr.AssignedBin) 125 isTabu = true; 126 } 127 if (isTabu) break; 128 } 129 } else if (spm != null) { 130 foreach (IItem tabuMove in attributes) { 131 SwapPositionMoveAttribute spmAttr = (tabuMove as SwapPositionMoveAttribute); 132 if (spmAttr != null 133 && (!useAspiration 134 || maximization && moveQuality <= spmAttr.MoveQuality 135 || !maximization && moveQuality >= spmAttr.MoveQuality)) { 136 if (spm.Index1 == spmAttr.Index1 137 && spm.Index2 == spmAttr.Index2 138 && multiComponentVector.PackingInformations[spm.Index1].ItemIndex == spmAttr.ItemIndex1 139 && multiComponentVector.PackingInformations[spm.Index2].ItemIndex == spmAttr.ItemIndex2) 140 isTabu = true; 141 } 142 if (isTabu) break; 143 } 144 } else if (cpm != null) { 145 foreach (IItem tabuMove in attributes) { 146 ChangePositionMoveAttribute cpmAttr = (tabuMove as ChangePositionMoveAttribute); 147 if (cpmAttr != null 148 && (!useAspiration 149 || maximization && moveQuality <= cpmAttr.MoveQuality 150 || !maximization && moveQuality >= cpmAttr.MoveQuality)) { 151 if (cpm.Index == cpmAttr.Index 152 && cpm.TargetIndex == cpmAttr.TargetIndex 153 && multiComponentVector.PackingInformations[cpm.Index].ItemIndex == cpmAttr.ItemIndex) 154 isTabu = true; 155 } 156 if (isTabu) break; 157 } 158 } else if (tm != null) { 159 foreach (IItem tabuMove in attributes) { 160 MCVTripleMoveAttribute tmAttr = (tabuMove as MCVTripleMoveAttribute); 161 if (tmAttr != null 162 && (!useAspiration 163 || maximization && moveQuality <= tmAttr.MoveQuality 164 || !maximization && moveQuality >= tmAttr.MoveQuality)) { 165 if ((tm.Index == tmAttr.Index && tm.TargetIndex == tmAttr.TargetIndex) 166 && multiComponentVector.PackingInformations[tm.Index].ItemIndex == tmAttr.ItemIndex 167 && tm.Rotation == !(tmAttr.RotationAfter.Equals(tmAttr.RotationBefore)) 168 && (tm.Group == tmAttr.GroupAfter && multiComponentVector.PackingInformations[tm.Index].AssignedBin == tmAttr.GroupBefore) 169 ) 170 isTabu = true; 171 } 172 if (isTabu) break; 173 } 174 } 175 176 107 if (isTabu) break; 108 } 177 109 178 110 return isTabu; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorTabuMaker.cs
r9473 r9495 32 32 [StorableClass] 33 33 public class MultiComponentVectorTabuMaker : TabuMaker, IMultiComponentVectorMoveOperator{ 34 public ILookupParameter< MultiComponentVectorMove> MultiComponentVectorMoveParameter {35 get { return (ILookupParameter< MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }34 public ILookupParameter<IPackingMove> PackingMoveParameter { 35 get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 36 36 } 37 37 public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter { … … 44 44 public MultiComponentVectorTabuMaker() 45 45 : base() { 46 Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));46 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); 47 47 Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate.")); 48 48 } … … 53 53 54 54 protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) { 55 MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;55 IPackingMove move = PackingMoveParameter.ActualValue; 56 56 MultiComponentVectorEncoding solution = MultiComponentVectorParameter.ActualValue; 57 57 double baseQuality = moveQuality; … … 59 59 baseQuality = quality; // we make an uphill move, the lower bound is the solution quality 60 60 61 SingleItemRotationMove sirm = move as SingleItemRotationMove; 62 if (sirm != null) 63 return new SingleItemRotationMoveAttribute(sirm.ItemIndex, solution.PackingInformations[sirm.ItemIndex].Rotated, baseQuality); 64 SingleGroupingMove sgm = move as SingleGroupingMove; 65 if (sgm != null) 66 return new SingleGroupingMoveAttribute(sgm.Index, solution.PackingInformations[sgm.Index].AssignedBin, baseQuality); 67 SwapPositionMove spm = move as SwapPositionMove; 68 if (spm != null) 69 return new SwapPositionMoveAttribute(spm.Index1, spm.Index2, solution.PackingInformations[spm.Index1].ItemIndex, solution.PackingInformations[spm.Index2].ItemIndex, baseQuality); 70 ChangePositionMove cpm = move as ChangePositionMove; 71 if (cpm != null) 72 return new ChangePositionMoveAttribute(cpm.Index, cpm.TargetIndex, solution.PackingInformations[cpm.Index].ItemIndex, baseQuality); 73 MCVTripleMove tm = move as MCVTripleMove; 74 if (tm != null) 75 return new MCVTripleMoveAttribute( 76 tm.Index, 77 tm.TargetIndex, 78 solution.PackingInformations[tm.Index].ItemIndex, 79 solution.PackingInformations[tm.Index].Rotated, 80 tm.Rotation ^ solution.PackingInformations[tm.Index].Rotated, 81 solution.PackingInformations[tm.Index].AssignedBin, 82 tm.Group, 83 baseQuality); 84 61 MultiComponentVectorMove mcvMove = move as MultiComponentVectorMove; 62 if (mcvMove != null) 63 return mcvMove.GetAttribute(baseQuality); 85 64 else return solution; 86 65 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/StochasticMultiComponentVectorMoveGenerator.cs
r9473 r9495 29 29 30 30 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { 31 [Item("Stochastic MultiComponentVectorMoveGenerator", "Generates all possible multi component moves from a given multiComponentVector.")]31 [Item("Stochastic MultiComponentVector Move Generator", "Generates all possible multi component moves from a given multiComponentVector.")] 32 32 [StorableClass] 33 33 public class StochasticMultiComponentVectorMoveGenerator : MultiComponentVectorMoveGenerator, IMultiMoveGenerator, IStochasticOperator { -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorEncoding.cs
r9473 r9495 37 37 38 38 [Storable] 39 public ItemList<PackingInformation> PackingInformations {get;set;} 39 public ObservableDictionary<int, ItemList<PackingInformation>> PackingInformations {get;set;} 40 41 public int NrOfBins { get { return PackingInformations.Count; } } 42 public int NrOfItems { 43 get { 44 int nrOfItems = 0; 45 foreach (var entry in PackingInformations) { nrOfItems += entry.Value.Count; } 46 return nrOfItems; 47 } 48 } 40 49 41 50 [StorableConstructor] … … 43 52 protected MultiComponentVectorEncoding(MultiComponentVectorEncoding original, Cloner cloner) 44 53 : base(original, cloner) { 45 this.PackingInformations = cloner.Clone(original.PackingInformations); 54 this.PackingInformations = new ObservableDictionary<int,ItemList<PackingInformation>>(); 55 foreach (var entry in original.PackingInformations) { 56 this.PackingInformations[entry.Key] = cloner.Clone(entry.Value); 57 } 46 58 } 47 59 public override IDeepCloneable Clone(Cloner cloner) { … … 51 63 public MultiComponentVectorEncoding() 52 64 : base() { 53 PackingInformations = new ItemList<PackingInformation>();65 PackingInformations = new ObservableDictionary<int, ItemList<PackingInformation>>(); 54 66 } 55 67 … … 57 69 StringBuilder sb = new StringBuilder(); 58 70 sb.Append("[ "); 59 foreach (var pi in PackingInformations) { 60 sb.Append(pi.ToString() + " "); 71 foreach (var gi in PackingInformations) { 72 sb.Append("g#" + gi.Key.ToString() + "{ "); 73 foreach (var pi in gi.Value) { 74 sb.Append(pi.ToString() + " "); 75 } 76 sb.Append("} "); 61 77 } 62 78 sb.Append("]"); … … 85 101 public class PackingInformation : Item { 86 102 [Storable] 87 public int ItemIndex { get; set; } 88 [Storable] 89 public int AssignedBin { get; set; } 103 public int ItemID { get; set; } 90 104 [Storable] 91 105 public bool Rotated { get; set; } 92 106 93 public PackingInformation(int itemIndex, int assignedBin, bool rotated) { 94 this.AssignedBin = assignedBin; 95 this.ItemIndex = itemIndex; 107 public PackingInformation(int itemID, bool rotated) { 108 this.ItemID = itemID; 96 109 this.Rotated = rotated; 97 110 } 98 111 public PackingInformation(PackingInformation original) { 99 this.AssignedBin = original.AssignedBin; 100 this.ItemIndex = original.ItemIndex; 112 this.ItemID = original.ItemID; 101 113 this.Rotated = original.Rotated; 102 114 } … … 106 118 protected PackingInformation(PackingInformation original, Cloner cloner) 107 119 : base(original, cloner) { 108 this.AssignedBin = original.AssignedBin; 109 this.ItemIndex = original.ItemIndex; 120 this.ItemID = original.ItemID; 110 121 this.Rotated = original.Rotated; 111 122 } … … 115 126 116 127 public override string ToString() { 117 return String.Format("({0}, {1}, {2}) ", ItemIndex, AssignedBin, Rotated); 128 return String.Format("{0}", ItemID.ToString()); 129 //return String.Format("({0}, {1}) ", ItemID, Rotated ? "t" : "f"); 118 130 } 119 131 … … 121 133 PackingInformation pi = obj as PackingInformation; 122 134 if (pi != null) 123 return this.ItemI ndex.Equals(pi.ItemIndex) && this.AssignedBin.Equals(pi.AssignedBin) && this.Rotated.Equals(pi.Rotated);135 return this.ItemID.Equals(pi.ItemID) && this.Rotated.Equals(pi.Rotated); 124 136 125 137 return false; … … 130 142 } 131 143 132 public static ItemList<PackingInformation> CreateListRandomly(int items, int lowerBound, IRandom random) { 133 Permutation permutation = new Permutation(PermutationTypes.Absolute, items, random); 134 var result = new ItemList<PackingInformation>(); 135 foreach (int itemIndex in permutation) { 136 result.Add(new PackingInformation(itemIndex, random.Next(0, lowerBound + 1), random.Next(0, 100) > 60 ? true : false)); 144 public static ObservableDictionary<int, ItemList<PackingInformation>> CreateDictionaryRandomly(int items, int nrOfBins, IRandom random) { 145 var result = new ObservableDictionary<int, ItemList<PackingInformation>>(); 146 for (int i = 0; i < nrOfBins; i++) 147 result[i] = new ItemList<PackingInformation>(); 148 149 Permutation randomItemSequence = new Permutation(PermutationTypes.Absolute, items, random); 150 foreach (int i in randomItemSequence) { 151 result[random.Next(nrOfBins)].Add(new PackingInformation(i, random.Next(100) > 60 ? true : false)); 137 152 } 138 153 return result; 139 154 } 140 155 141 public static ItemList<PackingInformation> CreateListRandomlyWithSortedSequence(int items, int lowerBound, IRandom random) { 142 Permutation permutation = new Permutation(PermutationTypes.Absolute, items); 143 var result = new ItemList<PackingInformation>(); 144 foreach (int itemIndex in permutation) { 145 result.Add(new PackingInformation(itemIndex, random.Next(0, lowerBound + 1), false)); 156 public static ObservableDictionary<int, ItemList<PackingInformation>> CreateDictionaryRandomlyWithSortedSequence(int items, int nrOfBins, IRandom random) { 157 var result = new ObservableDictionary<int, ItemList<PackingInformation>>(); 158 for (int i = 0; i < nrOfBins; i++) 159 result[i] = new ItemList<PackingInformation>(); 160 161 for (int i = 0; i < items; i++) { 162 result[random.Next(nrOfBins)].Add(new PackingInformation(i, false)); 146 163 } 147 164 return result; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorRandomCreator.cs
r9473 r9495 70 70 var solution = new MultiComponentVectorEncoding(); 71 71 if (sortedSequence) 72 solution.PackingInformations = PackingInformation.Create ListRandomlyWithSortedSequence(items, lowerBound, random);72 solution.PackingInformations = PackingInformation.CreateDictionaryRandomlyWithSortedSequence(items, lowerBound, random); 73 73 else 74 solution.PackingInformations = PackingInformation.Create ListRandomly(items, lowerBound, random);74 solution.PackingInformations = PackingInformation.CreateDictionaryRandomly(items, lowerBound, random); 75 75 return solution; 76 76 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/ThreeWayMultiComponentVectorManipulator.cs
r9440 r9495 28 28 29 29 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { 30 [Item(" Uniform Multi Component VectorManipulator", "An operator which manipulates a PackingSequence representation.")]30 [Item("ThreeWayMultiComponentVectorManipulator", "An operator which manipulates a PackingSequence representation.")] 31 31 [StorableClass] 32 32 public class ThreeWayMultiComponentVectorManipulator : MultiComponentVectorManipulator { … … 43 43 protected override void Manipulate(IRandom random, MultiComponentVectorEncoding individual) { 44 44 int manipulatorDecision = random.Next(0, 3); 45 int affectedBin = 0; 46 do { 47 affectedBin = random.Next(individual.NrOfBins); 48 } while (individual.PackingInformations[affectedBin].Count <= 0); 49 int affectedIndex = random.Next (individual.PackingInformations[affectedBin].Count); 45 50 46 51 //Randomly rotate one item 47 52 if (manipulatorDecision == 0) { 48 bool r = individual.PackingInformations[random.Next(individual.PackingInformations.Count - 1)].Rotated; 49 individual.PackingInformations[random.Next(individual.PackingInformations.Count - 1)].Rotated = !r; 53 individual.PackingInformations = SingleItemRotationMove.GetVectorAfterMove(individual, affectedBin, affectedIndex).PackingInformations; 50 54 } 51 55 //Randomly change the bin-assignment for one item 52 56 else if (manipulatorDecision == 1) { 53 individual.PackingInformations[random.Next(individual.PackingInformations.Count - 1)].AssignedBin = 0; 57 int targetBin = 0; 58 if (individual.NrOfBins > 1) 59 do { targetBin = random.Next(individual.NrOfBins); } 60 while (targetBin != affectedBin); 61 individual.PackingInformations = SingleGroupingMove.GetVectorAfterMove(individual, affectedBin, affectedIndex, targetBin).PackingInformations; 54 62 } 55 63 //Swap the sequence of two items assigned to the same bin 56 64 else if (manipulatorDecision == 2) { 57 int length = individual.PackingInformations.Count; 58 59 int counter = 0; 60 int swappedIndex1 = random.Next(length); 61 int swappedIndex2 = random.Next(length); 62 while ((swappedIndex1 == swappedIndex2 || individual.PackingInformations[swappedIndex1].AssignedBin != individual.PackingInformations[swappedIndex2].AssignedBin) && counter < 10) 63 { 64 swappedIndex1 = random.Next(length); 65 swappedIndex2 = random.Next(length); 66 counter++; 67 } 68 69 if (swappedIndex1 != swappedIndex2 && individual.PackingInformations[swappedIndex1].AssignedBin == individual.PackingInformations[swappedIndex2].AssignedBin) { 70 int temp = individual.PackingInformations[swappedIndex1].ItemIndex; 71 individual.PackingInformations[swappedIndex1].ItemIndex = individual.PackingInformations[swappedIndex2].ItemIndex; 72 individual.PackingInformations[swappedIndex2].ItemIndex = temp; 73 } 74 65 int targetIndex = 0; 66 int nrOfItems = individual.PackingInformations[affectedBin].Count; 67 if (nrOfItems > 1) 68 do { targetIndex = random.Next(nrOfItems); } 69 while (targetIndex != affectedIndex); 70 individual.PackingInformations = ChangePositionMove.GetVectorAfterMove(individual, affectedBin, affectedIndex, targetIndex).PackingInformations; 75 71 } 76 72 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/PackingPlan.cs
r9440 r9495 60 60 [Storable] 61 61 public ObservableDictionary<int, D> PackingItemPositions { get; set; } 62 [Storable] 63 public ObservableDictionary<int, B> PackingBinMeasures { get; set; } 62 64 63 //[Storable]64 //public ItemList<BoolValue> PackingItemsRotated { get; set; }65 66 [Storable]67 public B PackingBinMeasures {68 get;69 set;70 }71 65 [Storable] 72 66 public ItemList<I> PackingItemMeasures { … … 89 83 #endregion 90 84 91 public PackingPlan(B binMeasures, ItemList<I> itemMeasures) : base() { 85 public PackingPlan(B binMeasures, ItemList<I> itemMeasures) 86 : base() { 87 this.PackingItemMeasures = itemMeasures; 88 this.PackingBinMeasures = new ObservableDictionary<int, B>(); 89 this.PackingBinMeasures[0] = binMeasures; 90 } 91 public PackingPlan(ObservableDictionary<int, B> binMeasures, ItemList<I> itemMeasures) 92 : base() { 93 this.PackingItemMeasures = itemMeasures; 92 94 this.PackingBinMeasures = binMeasures; 93 this.PackingItemMeasures = itemMeasures;94 95 } 95 96 … … 98 99 protected PackingPlan(PackingPlan<D,B,I> original, Cloner cloner) 99 100 : base(original, cloner) { 100 101 PackingBinMeasures = original.PackingBinMeasures;101 PackingItemPositions = new ObservableDictionary<int, D>(original.PackingItemPositions); 102 PackingBinMeasures = new ObservableDictionary<int, B>(original.PackingBinMeasures); 102 103 PackingItemMeasures = original.PackingItemMeasures; 103 //PackingItemsRotated = cloner.Clone(original.PackingItemsRotated); 104 } 105 public override IDeepCloneable Clone(Cloner cloner) { 106 return new PackingPlan<D,B,I>(this, cloner); 104 107 } 105 108 106 public override IDeepCloneable Clone(Cloner cloner) { 107 return new PackingPlan<D,B,I>(this, cloner); 109 public B GetPackingBinMeasuresForBinNr(int binNr) { 110 if (PackingBinMeasures.ContainsKey(binNr)) 111 return PackingBinMeasures[binNr]; 112 else 113 return PackingBinMeasures[0]; 108 114 } 109 115
Note: See TracChangeset
for help on using the changeset viewer.