Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/15/13 22:23:36 (12 years ago)
Author:
jhelm
Message:

#1966: Did some major refactoring in Decoder-classes; Added MoveEvaluator classes for different encodings and dimensions; Added new crossover-class for MCV encoding;

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  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Encodings.IntegerVectorEncoding;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.BinPacking.Interfaces;
    2527
    2628namespace HeuristicLab.Encodings.PackingEncoding.GroupingVector {
    2729  [Item("Single Grouping Move", "A move on a grouping vector that is specified by a single group-assignment-index.")]
    2830  [StorableClass]
    29   public class SingleGroupingMove : Item {
     31  public class SingleGroupingMove : Item, IPackingMove{
    3032    [Storable]
    3133    public int Index { get; protected set; }
     
    5355      return new SingleGroupingMove(this, cloner);
    5456    }
     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    }
    5564  }
    5665}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveGenerator.cs

    r9440 r9495  
    3838      get { return (ILookupParameter<GroupingVectorEncoding>)Parameters["GroupingVector"]; }
    3939    }
    40     public ILookupParameter<SingleGroupingMove> SingleGroupingMoveParameter {
    41       get { return (LookupParameter<SingleGroupingMove>)Parameters["SingleGroupingMove"]; }
     40    public ILookupParameter<IPackingMove> PackingMoveParameter {
     41      get { return (LookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4242    }
    4343    protected ScopeParameter CurrentScopeParameter {
     
    5151      : base() {
    5252      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."));
    5454      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
    5555    }
     
    6161      for (int i = 0; i < moveScopes.Length; i++) {
    6262        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]));
    6464      }
    6565      CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes);
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveHardTabuCriterion.cs

    r9440 r9495  
    3838      get { return false; }
    3939    }
    40     public ILookupParameter<SingleGroupingMove> SingleGroupingMoveParameter {
    41       get { return (ILookupParameter<SingleGroupingMove>)Parameters["SingleGroupingMove"]; }
     40    public ILookupParameter<IPackingMove> PackingMoveParameter {
     41      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4242    }
    4343    public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter {
     
    6565    public SingleGroupingMoveHardTabuCriterion()
    6666      : base() {
    67       Parameters.Add(new LookupParameter<SingleGroupingMove>("SingleGroupingMove", "The move to evaluate."));
     67      Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
    6868      Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The solution to evaluate."));
    6969      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
     
    8080    public override IOperation Apply() {
    8181      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
    82       SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;
     82      SingleGroupingMove move = PackingMoveParameter.ActualValue as SingleGroupingMove;
    8383      GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue;
    8484      int length = groupingVector.GroupingVector.Length;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveMaker.cs

    r9440 r9495  
    4242      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    4343    }
    44     public ILookupParameter<SingleGroupingMove> SingleGroupingMoveParameter {
    45       get { return (ILookupParameter<SingleGroupingMove>)Parameters["SingleGroupingMove"]; }
     44    public ILookupParameter<IPackingMove> PackingMoveParameter {
     45      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4646    }
    4747    public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter {
    4848      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"]; }
    4955    }
    5056
     
    5561      : base() {
    5662      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."));
    5864      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
    5965      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."));
    6068    }
    6169
     
    6573
    6674    public override IOperation Apply() {
    67       SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;
     75      IPackingMove move = PackingMoveParameter.ActualValue;
    6876      GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue;
    6977      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
    7078      DoubleValue quality = QualityParameter.ActualValue;
    7179
    72       groupingVector.GroupingVector[move.Index] = move.NewGroup;
     80      groupingVector.GroupingVector = (move.GetSolutionAfterMove() as GroupingVectorEncoding).GroupingVector;
     81      PackingPlanParameter.ActualValue = PackingPlanAfterMoveParameter.ActualValue;
    7382
    7483      quality.Value = moveQuality.Value;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingMoveSoftTabuCriterion.cs

    r9440 r9495  
    3838      get { return false; }
    3939    }
    40     public ILookupParameter<SingleGroupingMove> SingleGroupingMoveParameter {
    41       get { return (ILookupParameter<SingleGroupingMove>)Parameters["SingleGroupingMove"]; }
     40    public ILookupParameter<IPackingMove> PackingMoveParameter {
     41      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4242    }
    4343    public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter {
     
    6565    public SingleGroupingMoveSoftTabuCriterion()
    6666      : base() {
    67       Parameters.Add(new LookupParameter<SingleGroupingMove>("SingleGroupingMove", "The move to evaluate."));
     67      Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
    6868      Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The solution to evaluate."));
    6969      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
     
    8080    public override IOperation Apply() {
    8181      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
    82       SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;
     82      SingleGroupingMove move = PackingMoveParameter.ActualValue as SingleGroupingMove;
    8383      GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue;
    8484      int length = groupingVector.GroupingVector.Length;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/Moves/SingleGrouping/SingleGroupingTabuMaker.cs

    r9440 r9495  
    3232  [StorableClass]
    3333  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"]; }
    3636    }
    3737    public ILookupParameter<GroupingVectorEncoding> GroupingVectorParameter {
     
    4444    public SingleGroupingTabuMaker()
    4545      : base() {
    46       Parameters.Add(new LookupParameter<SingleGroupingMove>("SingleGroupingMove", "The move to evaluate."));
     46        Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
    4747      Parameters.Add(new LookupParameter<GroupingVectorEncoding>("GroupingVector", "The solution to evaluate."));
    4848    }
     
    5353
    5454    protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) {
    55       SingleGroupingMove move = SingleGroupingMoveParameter.ActualValue;
     55      IPackingMove move = PackingMoveParameter.ActualValue;
    5656      GroupingVectorEncoding groupingVector = GroupingVectorParameter.ActualValue;   
    5757      double baseQuality = moveQuality;
    5858      if (maximization && quality > moveQuality || !maximization && quality < moveQuality)
    5959        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();
    6266    }
    6367  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/ChangePositionMoveAttribute.cs

    r9473 r9495  
    2929  public class ChangePositionMoveAttribute : MultiComponentVectorMoveAttribute {
    3030    [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; }
    3236    [Storable]
    3337    public int TargetIndex { get; protected set; }
    34     [Storable]
    35     public int ItemIndex { get; protected set; }
    3638
    3739    [StorableConstructor]
     
    4143        this.Index = original.Index;
    4244        this.TargetIndex = original.TargetIndex;     
    43       this.ItemIndex = original.ItemIndex;
     45      this.ItemID = original.ItemID;
    4446    }
    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)
    4749      : base(moveQuality) {
     50        AffectedGroup = affectedGroup;
    4851        Index = index;
    4952        TargetIndex = targetIndex;
    50         ItemIndex = itemIndex;
     53        ItemID = itemID;
    5154    }
    5255
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/MCVTripleMoveAttribute.cs

    r9473 r9495  
    3131    public int Index { get; protected set; }
    3232    [Storable]
    33     public int ItemIndex { get; protected set; } 
     33    public int ItemID { get; protected set; } 
    3434    [Storable]
    3535    public int TargetIndex { get; protected set; }
    3636    [Storable]
    37     public bool RotationBefore { get; protected set; }
    38     [Storable]
    39     public bool RotationAfter { get; protected set; }
     37    public bool Rotation { get; protected set; }
    4038    [Storable]
    4139    public int GroupBefore { get; protected set; }
     
    4947        this.Index = original.Index;
    5048        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;
    5451      this.GroupBefore = original.GroupBefore;
    5552      this.GroupAfter = original.GroupAfter;
    5653    }
    57     public MCVTripleMoveAttribute() : this(-1, -1, -1, false, false, -1, -1, -1) { }
    58     public MCVTripleMoveAttribute(int index, int targetIndex, int itemIndex, 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)
    5956      : base(moveQuality) {
    6057        Index = index;
    6158        TargetIndex = targetIndex;
    62         ItemIndex = itemIndex;
    63         RotationBefore = rotationBefore;
    64         RotationAfter = rotationAfter;
     59        ItemID = itemID;
     60        Rotation = rotation;
    6561        GroupBefore = groupBefore;
    6662        GroupAfter = groupAfter;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/SingleGroupingMoveAttribute.cs

    r9473 r9495  
    2727  [Item("SingleGroupingMoveAttribute", "Specifies the tabu attributes for a single grouping move on an multi component vector.")]
    2828  [StorableClass]
    29   public class SingleGroupingMoveAttribute : MultiComponentVectorMoveAttribute {
     29  public class SingleGroupingMoveAttribute : MultiComponentVectorMoveAttribute {
     30    [Storable]
     31    public int OldGroup { get; protected set; }
    3032    [Storable]
    3133    public int Index { get; protected set; }
    3234    [Storable]
    33     public int AssignedBin { get; protected set; }
     35    public int ItemID { get; protected set; }
     36    [Storable]
     37    public int NewGroup { get; protected set; }
    3438
    3539    [StorableConstructor]
    3640    protected SingleGroupingMoveAttribute(bool deserializing) : base(deserializing) { }
    3741    protected SingleGroupingMoveAttribute(SingleGroupingMoveAttribute original, Cloner cloner)
    38       : base(original, cloner) {
     42      : base(original, cloner) {   
     43      this.OldGroup = original.OldGroup;
    3944      this.Index = original.Index;
    40       this.AssignedBin = original.AssignedBin;
     45      this.ItemID = original.ItemID;
     46      this.NewGroup = original.NewGroup;
    4147    }
    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)
    4450      : base(moveQuality) {
     51        OldGroup = oldGroup;
    4552      Index = index;
    46       AssignedBin = assignedBin;
     53      ItemID = itemID;
     54      NewGroup = newGroup;
    4755    }
    4856
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/SingleItemRotationMoveAttribute.cs

    r9440 r9495  
    2929  public class SingleItemRotationMoveAttribute : MultiComponentVectorMoveAttribute {
    3030    [Storable]
     31    public int AffectedGroup { get; protected set; }
     32    [Storable]
     33    public int Index { get; protected set; }
     34    [Storable]
    3135    public int ItemIndex { get; protected set; }
    3236    [Storable]
     
    3741    protected SingleItemRotationMoveAttribute(SingleItemRotationMoveAttribute original, Cloner cloner)
    3842      : base(original, cloner) {
     43      this.AffectedGroup = original.AffectedGroup;
     44      this.Index = original.Index;
    3945      this.ItemIndex = original.ItemIndex;
    4046      this.ItemRotation = original.ItemRotation;
    4147    }
    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)
    4450      : base(moveQuality) {
     51        AffectedGroup = affectedGroup;
     52        Index = index;
    4553      ItemIndex = itemIndex;
    4654      ItemRotation = itemRotation;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/SwapPositionMoveAttribute.cs

    r9473 r9495  
    2929  public class SwapPositionMoveAttribute : MultiComponentVectorMoveAttribute {
    3030    [Storable]
     31    public int AffectedGroup { get; protected set; }
     32    [Storable]
    3133    public int Index1 { get; protected set; }
    3234    [Storable]
    3335    public int Index2 { get; protected set; }
    3436    [Storable]
    35     public int ItemIndex1 { get; protected set; }
     37    public int ItemID1 { get; protected set; }
    3638    [Storable]
    37     public int ItemIndex2 { get; protected set; }
     39    public int ItemID2 { get; protected set; }
    3840
    3941    [StorableConstructor]
     
    4143    protected SwapPositionMoveAttribute(SwapPositionMoveAttribute original, Cloner cloner)
    4244      : base(original, cloner) {
     45        this.AffectedGroup = original.AffectedGroup;
    4346        this.Index1 = original.Index1;
    4447        this.Index2 = original.Index2;
    45       this.ItemIndex1 = original.ItemIndex1;
    46       this.ItemIndex2 = original.ItemIndex2;
     48      this.ItemID1 = original.ItemID1;
     49      this.ItemID2 = original.ItemID2;
    4750    }
    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)
    5053      : base(moveQuality) {
     54        AffectedGroup = affectedGroup;
    5155        Index1 = index1;
    5256        Index2 = index2;
    53         ItemIndex1 = itemIndex1;
    54         ItemIndex2 = itemIndex2;
     57        ItemID1 = itemID1;
     58        ItemID2 = itemID2;
    5559    }
    5660
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/ExhaustiveMCVTripleMoveGenerator.cs

    r9473 r9495  
    4040    }
    4141
    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            }
    6550    }
    6651
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/ChangePositionMove.cs

    r9473 r9495  
    2424using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.BinPacking.Interfaces;
    2627
    2728namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
     
    2930  [StorableClass]
    3031  public class ChangePositionMove : MultiComponentVectorMove {
     32    [Storable]
     33    public int AffectedGroup { get; protected set; }
    3134    [Storable]
    3235    public int Index { get; protected set; }
     
    3841    protected ChangePositionMove(ChangePositionMove original, Cloner cloner)
    3942      : base(original, cloner) {
     43      this.AffectedGroup = original.AffectedGroup;
    4044      this.Index = original.Index;
    4145      this.TargetIndex = original.TargetIndex;
    4246    }
    43     public ChangePositionMove(int index, int targetIndex, MultiComponentVectorEncoding multiComponentVector)
     47    public ChangePositionMove(int affectedBin, int index, int targetIndex, MultiComponentVectorEncoding multiComponentVector)
    4448      : base(multiComponentVector) {
     49        AffectedGroup = affectedBin;
    4550        Index = index;
    4651        TargetIndex = targetIndex;
     
    5156    }
    5257
    53     public override MultiComponentVectorEncoding GetVectorAfterMove() {
    54       return GetVectorAfterMove(MultiComponentVector, Index, TargetIndex);
     58    public override IPackingSolutionEncoding GetSolutionAfterMove() {
     59      return GetVectorAfterMove(MultiComponentVector, AffectedGroup, Index, TargetIndex);
    5560    }
    56     public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int index, int targetIndex) {
     61    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedBin, int index, int targetIndex) {
    5762      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);
    6166      return result;
    6267    }
     
    6772
    6873    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;
    70100    }
    71101  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/MCVTripleMove.cs

    r9473 r9495  
    2424using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.BinPacking.Interfaces;
    2627
    2728namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
    2829  [Item("MCVTripleMove", "A move on a multi component vector that is specified by a rotation-value, two indexes and a groupNr.")]
    2930  [StorableClass]
    30   public class MCVTripleMove : MultiComponentVectorMove {
     31  public class MCVTripleMove : MultiComponentVectorMove {   
    3132    [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; }
    3340    [Storable]
    3441    public bool Rotation { get; protected set; }
    35     [Storable]
    36     public int Group { get; protected set; }
    37     [Storable]
    38     public int TargetIndex { get; protected set; }
    3942
    4043    [StorableConstructor]
    4144    protected MCVTripleMove(bool deserializing) : base(deserializing) { }
    4245    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;
    4551      this.Rotation = original.Rotation;
    46       this.Group = original.Group;
    47       this.TargetIndex = original.TargetIndex;
    4852    }
    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;
    5259        Rotation = rotation;
    53         Group = group;
    54         TargetIndex = targetIndex;
    5560    }
    5661
     
    5964    }
    6065
    61     public override MultiComponentVectorEncoding GetVectorAfterMove() {
    62       var result = MultiComponentVector;
     66    public override IPackingSolutionEncoding GetSolutionAfterMove() {
     67      var result = MultiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding;
    6368      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);
    6977      return result;
    7078    }
     
    7583
    7684    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;
    78111    }
    79112  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/MultiComponentVectorMove.cs

    r9440 r9495  
    2525using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Problems.BinPacking.Interfaces;
    2728
    2829namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
    2930  [Item("MultiComponentVectorMove", "An abstract move for a multi component vector encoded solution.")]
    3031  [StorableClass]
    31   public abstract class MultiComponentVectorMove : Item {
     32  public abstract class MultiComponentVectorMove : Item, IPackingMove {
    3233    [Storable]
    3334    public MultiComponentVectorEncoding MultiComponentVector { get; protected set; }
     
    4546    }
    4647
    47     public abstract MultiComponentVectorEncoding GetVectorAfterMove();
     48    public abstract IPackingSolutionEncoding GetSolutionAfterMove();
    4849    public abstract Type GetMoveAttributeType();
     50    public abstract MultiComponentVectorMoveAttribute GetAttribute(double quality);
     51    public abstract bool BelongsToAttribute (MultiComponentVectorMoveAttribute attribute, bool hardCriterion);
    4952  }
    5053}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleGroupingMove.cs

    r9473 r9495  
    2424using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.BinPacking.Interfaces;
    2627
    2728namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
    2829  [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.")]
    2930  [StorableClass]
    30   public class SingleGroupingMove : MultiComponentVectorMove {
     31  public class SingleGroupingMove : MultiComponentVectorMove {       
     32    [Storable]
     33    public int OldGroup { get; protected set; }
    3134    [Storable]
    3235    public int Index { get; protected set; }
     
    3841    protected SingleGroupingMove(SingleGroupingMove original, Cloner cloner)
    3942      : base(original, cloner) {
     43      this.OldGroup = original.OldGroup;
    4044      this.Index = original.Index;
    4145      this.NewGroup = original.NewGroup;
    4246    }
    43     public SingleGroupingMove(int index, int newGroup, MultiComponentVectorEncoding multiComponentVector)
     47    public SingleGroupingMove(int oldGroup, int index, int newGroup, MultiComponentVectorEncoding multiComponentVector)
    4448      : base(multiComponentVector) {
    45       Index = index;
    46       NewGroup = newGroup;
     49        OldGroup = oldGroup;
     50        Index = index;
     51        NewGroup = newGroup;
    4752    }
    4853
     
    5156    }
    5257
    53     public override MultiComponentVectorEncoding GetVectorAfterMove() {
    54       return GetVectorAfterMove(MultiComponentVector, Index, NewGroup);
     58    public override IPackingSolutionEncoding GetSolutionAfterMove() {
     59      return GetVectorAfterMove(MultiComponentVector, OldGroup, Index, NewGroup);
    5560    }
    56     public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding originalSolution, int itemIndex, int binNr) {
     61    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding originalSolution, int oldBin, int index, int newBin) {
    5762      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);
    6466      return solution;
    6567    }
     
    7072
    7173    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;
    7396    }
    7497  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleItemRotationMove.cs

    r9473 r9495  
    2424using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.BinPacking.Interfaces;
    2627
    2728namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
     
    3031  public class SingleItemRotationMove : MultiComponentVectorMove {
    3132    [Storable]
    32     public int ItemIndex { get; protected set; }
     33    public int AffectedGroup { get; protected set; }
     34    [Storable]
     35    public int Index { get; protected set; }
    3336
    3437    [StorableConstructor]
     
    3639    protected SingleItemRotationMove(SingleItemRotationMove original, Cloner cloner)
    3740      : base(original, cloner) {
    38         this.ItemIndex = original.ItemIndex;
     41        this.AffectedGroup = original.AffectedGroup;
     42        this.Index = original.Index;
    3943    }
    40     public SingleItemRotationMove(int index, MultiComponentVectorEncoding multiComponentVector)
     44    public SingleItemRotationMove(int affectedBin, int index, MultiComponentVectorEncoding multiComponentVector)
    4145      : base(multiComponentVector) {
    42         ItemIndex = index;
     46        AffectedGroup = affectedBin;
     47        Index = index;
    4348    }
    4449
     
    4752    }
    4853
    49     public override MultiComponentVectorEncoding GetVectorAfterMove() {
    50       return GetVectorAfterMove (MultiComponentVector, ItemIndex);
     54    public override IPackingSolutionEncoding GetSolutionAfterMove() {
     55      return GetVectorAfterMove (MultiComponentVector, AffectedGroup, Index);
    5156    }
    52     public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int itemIndex) {
     57    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedGroup, int index) {
    5358      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;
    5560      return result;
    5661    }
     
    6166
    6267    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;
    6489    }
    6590  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SwapPositionMove.cs

    r9473 r9495  
    2424using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     26using HeuristicLab.Problems.BinPacking.Interfaces;
    2627
    2728namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
     
    2930  [StorableClass]
    3031  public class SwapPositionMove : MultiComponentVectorMove {
     32    [Storable]
     33    public int AffectedGroup { get; protected set; }
    3134    [Storable]
    3235    public int Index1 { get; protected set; }
     
    3841    protected SwapPositionMove(SwapPositionMove original, Cloner cloner)
    3942      : 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;
    4246    }
    43     public SwapPositionMove(int index1, int index2, MultiComponentVectorEncoding multiComponentVector)
     47    public SwapPositionMove(int affectedGroup, int index1, int index2, MultiComponentVectorEncoding multiComponentVector)
    4448      : base(multiComponentVector) {
     49        AffectedGroup = affectedGroup;
    4550        Index1 = index1;
    4651        Index2 = index2;
     
    5156    }
    5257
    53     public override MultiComponentVectorEncoding GetVectorAfterMove() {
    54       return GetVectorAfterMove(MultiComponentVector, Index1, Index2);
     58    public override IPackingSolutionEncoding GetSolutionAfterMove() {
     59      return GetVectorAfterMove(MultiComponentVector, AffectedGroup, Index1, Index2);
    5560    }
    56     public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int index1, int index2) {
     61    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int affectedGroup, int index1, int index2) {
    5762      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;
    6166      return result;
    6267    }
     
    6772
    6873    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;
    70101    }
    71102  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveGenerator.cs

    r9473 r9495  
    4242      get { return (ILookupParameter<MultiComponentVectorEncoding>)Parameters["MultiComponentVector"]; }
    4343    }
    44     public ILookupParameter<MultiComponentVectorMove> MultiComponentVectorMoveParameter {
    45       get { return (LookupParameter<MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }
     44    public ILookupParameter<IPackingMove> PackingMoveParameter {
     45      get { return (LookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4646    }
    4747    protected ScopeParameter CurrentScopeParameter {
     
    5656      : base() {
    5757        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."));
    5959      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
    6060    }
     
    6262
    6363    public static int NrOfRotationMoves(MultiComponentVectorEncoding mcv) {
    64       return mcv.PackingInformations.Count;
     64      return mcv.NrOfItems;
    6565    }
    6666    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);
    6970    }
    7071
    7172    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);
    7974    }
    8075    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);
    9281    }
    9382
    9483    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       }
    10584      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;
    10887      }
    10988      return nrOfSwapPositionMoves;
    11089    }
    11190    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);
    12495    }
    12596
    12697    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;
    131101      }
    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;
    142103    }
    143104    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);
    156109    }
    157110
     
    162115      for (int i = 0; i < moveScopes.Length; i++) {
    163116        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]));
    165118      }
    166119      CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes);
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveHardTabuCriterion.cs

    r9473 r9495  
    3838      get { return false; }
    3939    }
    40     public ILookupParameter<MultiComponentVectorMove> MultiComponentVectorMoveParameter {
    41       get { return (ILookupParameter<MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }
     40    public ILookupParameter<IPackingMove> PackingMoveParameter {
     41      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4242    }
    4343    public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter {
     
    6565    public MultiComponentVectorMoveHardTabuCriterion()
    6666      : base() {
    67         Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));
     67      Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
    6868      Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate."));
    6969      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
     
    8080    public override IOperation Apply() {
    8181      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
    82       MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;
     82      MultiComponentVectorMove move = PackingMoveParameter.ActualValue as MultiComponentVectorMove;
    8383      MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue;
    8484      int length = multiComponentVector.PackingInformations.Count;
     
    9494    private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) {
    9595      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;
    10196      var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType()));
    10297
    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);
    116106        }
    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      }
    185109
    186110      return isTabu;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveMaker.cs

    r9473 r9495  
    4242      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
    4343    }
    44     public ILookupParameter<MultiComponentVectorMove> MultiComponentVectorMoveParameter {
    45       get { return (ILookupParameter<MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }
     44    public ILookupParameter<IPackingMove> PackingMoveParameter {
     45      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4646    }
    4747    public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter {
    4848      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"]; }
    4955    }
    5056
     
    5561      : base() {
    5662      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."));
    5864      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The relative quality of the move."));
    5965      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."));
    6068    }
    6169
     
    6573
    6674    public override IOperation Apply() {
    67       MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;
     75      IPackingMove move = PackingMoveParameter.ActualValue;
    6876      MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue;
    6977      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
    7078      DoubleValue quality = QualityParameter.ActualValue;
    7179
    72       multiComponentVector.PackingInformations = move.GetVectorAfterMove().PackingInformations;
     80      multiComponentVector.PackingInformations = (move.GetSolutionAfterMove() as MultiComponentVectorEncoding).PackingInformations;
     81      PackingPlanParameter.ActualValue = PackingPlanAfterMoveParameter.ActualValue;
    7382
    7483      quality.Value = moveQuality.Value;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveSoftTabuCriterion.cs

    r9473 r9495  
    3838      get { return false; }
    3939    }
    40     public ILookupParameter<MultiComponentVectorMove> MultiComponentVectorMoveParameter {
    41       get { return (ILookupParameter<MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; }
     40    public ILookupParameter<IPackingMove> PackingMoveParameter {
     41      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
    4242    }
    4343    public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter {
     
    6565    public MultiComponentVectorMoveSoftTabuCriterion()
    6666      : base() {
    67       Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));
     67      Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
    6868      Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate."));
    6969      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
     
    8080    public override IOperation Apply() {
    8181      ItemList<IItem> tabuList = TabuListParameter.ActualValue;
    82       MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;
     82      MultiComponentVectorMove move = PackingMoveParameter.ActualValue as MultiComponentVectorMove;
    8383      MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue;
    8484      int length = multiComponentVector.PackingInformations.Count;
     
    9494    private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) {
    9595      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;
    10296      var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType()));
    10397
    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);
    115106        }
    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      }
    177109
    178110      return isTabu;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorTabuMaker.cs

    r9473 r9495  
    3232  [StorableClass]
    3333  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"]; }
    3636    }
    3737    public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter {
     
    4444    public MultiComponentVectorTabuMaker()
    4545      : base() {
    46       Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));
     46        Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
    4747      Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate."));
    4848    }
     
    5353
    5454    protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) {
    55       MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;
     55      IPackingMove move = PackingMoveParameter.ActualValue;
    5656      MultiComponentVectorEncoding solution = MultiComponentVectorParameter.ActualValue;
    5757      double baseQuality = moveQuality;
     
    5959        baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
    6060                             
    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);
    8564      else return solution;
    8665    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/StochasticMultiComponentVectorMoveGenerator.cs

    r9473 r9495  
    2929
    3030namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
    31   [Item("StochasticMultiComponentVectorMoveGenerator", "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.")]
    3232  [StorableClass]
    3333  public class StochasticMultiComponentVectorMoveGenerator : MultiComponentVectorMoveGenerator, IMultiMoveGenerator, IStochasticOperator {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorEncoding.cs

    r9473 r9495  
    3737
    3838    [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    }
    4049
    4150    [StorableConstructor]
     
    4352    protected MultiComponentVectorEncoding(MultiComponentVectorEncoding original, Cloner cloner)
    4453      : 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      }
    4658    }
    4759    public override IDeepCloneable Clone(Cloner cloner) {
     
    5163    public MultiComponentVectorEncoding()
    5264      : base() {
    53         PackingInformations = new ItemList<PackingInformation>();
     65        PackingInformations = new ObservableDictionary<int, ItemList<PackingInformation>>();
    5466    }
    5567
     
    5769      StringBuilder sb = new StringBuilder();
    5870      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("} ");
    6177      }
    6278      sb.Append("]");
     
    85101  public class PackingInformation : Item {
    86102    [Storable]
    87     public int ItemIndex { get; set; }
    88     [Storable]
    89     public int AssignedBin { get; set; }
     103    public int ItemID { get; set; }
    90104    [Storable]
    91105    public bool Rotated { get; set; }
    92106
    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;
    96109      this.Rotated      = rotated;
    97110    }     
    98111    public PackingInformation(PackingInformation original) {
    99       this.AssignedBin = original.AssignedBin;
    100       this.ItemIndex = original.ItemIndex;
     112      this.ItemID = original.ItemID;
    101113      this.Rotated = original.Rotated;
    102114    }
     
    106118    protected PackingInformation(PackingInformation original, Cloner cloner)
    107119      : base(original, cloner) {
    108         this.AssignedBin  = original.AssignedBin;
    109         this.ItemIndex   = original.ItemIndex;
     120        this.ItemID   = original.ItemID;
    110121        this.Rotated      = original.Rotated;
    111122    }
     
    115126
    116127    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");
    118130    }
    119131
     
    121133      PackingInformation pi = obj as PackingInformation;
    122134      if (pi != null)
    123         return this.ItemIndex.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);
    124136
    125137      return false;
     
    130142    }
    131143
    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));
    137152      }
    138153      return result;
    139154    }
    140155
    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));
    146163      }
    147164      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorRandomCreator.cs

    r9473 r9495  
    7070      var solution = new MultiComponentVectorEncoding();
    7171      if (sortedSequence)
    72         solution.PackingInformations = PackingInformation.CreateListRandomlyWithSortedSequence(items, lowerBound, random);
     72        solution.PackingInformations = PackingInformation.CreateDictionaryRandomlyWithSortedSequence(items, lowerBound, random);
    7373      else
    74         solution.PackingInformations = PackingInformation.CreateListRandomly(items, lowerBound, random);
     74        solution.PackingInformations = PackingInformation.CreateDictionaryRandomly(items, lowerBound, random);
    7575      return solution;
    7676    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/ThreeWayMultiComponentVectorManipulator.cs

    r9440 r9495  
    2828
    2929namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
    30   [Item("Uniform Multi Component Vector Manipulator", "An operator which manipulates a PackingSequence representation.")]
     30  [Item("ThreeWayMultiComponentVectorManipulator", "An operator which manipulates a PackingSequence representation.")]
    3131  [StorableClass]
    3232  public class ThreeWayMultiComponentVectorManipulator :  MultiComponentVectorManipulator {
     
    4343    protected override void Manipulate(IRandom random, MultiComponentVectorEncoding individual) {
    4444      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);
    4550
    4651      //Randomly rotate one item
    4752      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;
    5054      }
    5155      //Randomly change the bin-assignment for one item
    5256      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;
    5462      }
    5563      //Swap the sequence of two items assigned to the same bin
    5664      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;
    7571      }
    7672
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/PackingPlan.cs

    r9440 r9495  
    6060    [Storable]
    6161    public ObservableDictionary<int, D> PackingItemPositions { get; set; }
     62    [Storable]
     63    public ObservableDictionary<int, B> PackingBinMeasures { get; set; }
    6264
    63     //[Storable]
    64     //public ItemList<BoolValue> PackingItemsRotated { get; set; }
    65 
    66     [Storable]
    67     public B PackingBinMeasures {
    68       get;
    69       set;
    70     }
    7165    [Storable]
    7266    public ItemList<I> PackingItemMeasures {
     
    8983    #endregion
    9084
    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;
    9294      this.PackingBinMeasures = binMeasures;
    93       this.PackingItemMeasures = itemMeasures;
    9495    }
    9596
     
    9899    protected PackingPlan(PackingPlan<D,B,I> original, Cloner cloner)
    99100      : base(original, cloner) {
    100         PackingItemPositions = new ObservableDictionary<int, D>(original.PackingItemPositions);
    101       PackingBinMeasures = original.PackingBinMeasures;
     101      PackingItemPositions = new ObservableDictionary<int, D>(original.PackingItemPositions);
     102      PackingBinMeasures = new ObservableDictionary<int, B>(original.PackingBinMeasures);
    102103      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);
    104107    }
    105108
    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];
    108114    }
    109115
Note: See TracChangeset for help on using the changeset viewer.