Changeset 9495


Ignore:
Timestamp:
05/15/13 22:23:36 (8 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
Files:
13 added
2 deleted
58 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan2DView.cs

    r9440 r9495  
    1818    public PackingPlan2DView() {
    1919      InitializeComponent();
     20    }       
     21
     22    protected override void DeregisterContentEvents() {
     23      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
     24      base.DeregisterContentEvents();
     25    }
     26    protected override void RegisterContentEvents() {
     27      base.RegisterContentEvents();
     28      Content.QualityChanged += new EventHandler(Content_QualityChanged);
    2029    }
    2130
     
    4655    private void Redraw(PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> plan) {     
    4756      int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
    48       var bin = plan.PackingBinMeasures;
     57      var bin = plan.GetPackingBinMeasuresForBinNr(currentBin);
    4958      packingPlan2D.InitializeContainer(bin.Width, bin.Height);
    5059      int i = 0;
     
    6574    }
    6675
     76
     77
     78    private void Content_QualityChanged(object sender, EventArgs e) {
     79      if (InvokeRequired)
     80        Invoke(new EventHandler(Content_QualityChanged), sender, e);
     81      else {
     82        binSelection.Items.Clear();
     83        if (Content == null) {
     84          Redraw();
     85        } else {
     86          for (int i = 0; i < Content.NrOfBins; i++)
     87            binSelection.Items.Add(i);
     88          Redraw(Content);
     89        }
     90        packingPlan2D.Invalidate();
     91        packingPlan2D.Update();
     92      }
     93    } 
    6794  }
    6895}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan3DView.cs

    r9440 r9495  
    1818    public PackingPlan3DView() {
    1919      InitializeComponent();
    20       this.nameTextBox.Text = "XX";
     20      this.nameTextBox.Text = "Packing Plan";
    2121    }
    2222
     23
     24    protected override void DeregisterContentEvents() {
     25      Content.QualityChanged -= new EventHandler(Content_QualityChanged);
     26      base.DeregisterContentEvents();
     27    }
     28    protected override void RegisterContentEvents() {
     29      base.RegisterContentEvents();
     30      Content.QualityChanged += new EventHandler(Content_QualityChanged);
     31    }
    2332
    2433    public new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content {
     
    3443        packingPlan3D.InitializeContainer(0, 0, 0);
    3544      } else {
    36         Content.Name = "XX";
     45        Content.Name = "Packing Plan";
    3746        for (int i = 0; i < Content.NrOfBins; i++)
    3847          binSelection.Items.Add(i);
     
    4554    private void UpdateModel() {
    4655      int currentBin = (binSelection != null && binSelection.SelectedItem != null) ? (int)(binSelection.SelectedItem) : 0;
    47       var bin = Content.PackingBinMeasures;
     56      var bin = Content.GetPackingBinMeasuresForBinNr(currentBin);
    4857      packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth);
    4958      int i = 0;
     
    5867        i++;
    5968      }
    60 
    61       int selectedItem = -1;
    62       if ((itemSelection != null && itemSelection.SelectedItem != null)) {
    63         if (!Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
    64           //if (itemSelection.SelectedItem.ToString().Equals("enum"))
    65           //  packingPlan3D.StartItemEnumeration();
    66           selectedItem = -1;
    67         } else
    68           packingPlan3D.SelectItem(selectedItem);
    69       }
    7069    }
    7170
     
    8079          itemSelection.Items.Add(i);
    8180      }
    82       //itemSelection.Items.Add("enum");
    8381
    8482      packingPlan3D.Invalidate();
     
    8886    private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) {
    8987      UpdateModel();
     88
     89      int selectedItem = -1;
     90      if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) {
     91        packingPlan3D.SelectItem(selectedItem);
     92      } else     
     93        packingPlan3D.UnselectItem();
     94
    9095      packingPlan3D.Invalidate();
    9196      packingPlan3D.Update();
    9297    }
    9398
     99    private void Content_QualityChanged(object sender, EventArgs e) {
     100      if (InvokeRequired)
     101        Invoke(new EventHandler(Content_QualityChanged), sender, e);
     102      else {
     103        binSelection.Items.Clear();
     104        if (Content == null) {
     105          packingPlan3D.InitializeContainer(0, 0, 0);
     106        } else {
     107          Content.Name = "Packing Plan";
     108          for (int i = 0; i < Content.NrOfBins; i++)
     109            binSelection.Items.Add(i);
     110          binSelection.SelectedIndex = 0;
     111          UpdateModel();
     112          packingPlan3D.StartRendering();
     113        }
     114      }
     115    } 
    94116  }
    95117}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Plugin.cs

    r9473 r9495  
    2626  /// Plugin class for HeuristicLab.Problems.BinPacking.Views plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Problems.BinPacking.Views", "3.3.7.9440")]
     28  [Plugin("HeuristicLab.Problems.BinPacking.Views", "3.3.7.9473")]
    2929  [PluginFile("HeuristicLab.Problems.BinPacking.Views-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Properties/AssemblyInfo.cs

    r9473 r9495  
    5454// by using the '*' as shown below:
    5555[assembly: AssemblyVersion("3.3.0.0")]
    56 [assembly: AssemblyFileVersion("3.3.7.9440")]
     56[assembly: AssemblyFileVersion("3.3.7.9473")]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftFunctions.cs

    r9440 r9495  
    55using HeuristicLab.Collections;
    66using HeuristicLab.Core;
     7using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
     8using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    79using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    810using HeuristicLab.Problems.BinPacking.Dimensions;
     
    1416namespace HeuristicLab.Problems.BinPacking.Decoders {
    1517  public static class BottomLeftFunctions {
    16    
    17 
    18 
    19     public static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) {
     18
     19
     20    public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     21      MultiComponentVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
     22      int nrOfBins = solution.NrOfBins;
     23
     24      //Get all indexes of items for every bin according to grouping-vector
     25      Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>();
     26
     27      for (int i = 0; i < nrOfBins; i++) {
     28        unpackedItemIndexesPerBin[i] = new List<PackingInformation>(solution.PackingInformations[i]);
     29      }
     30
     31      ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     32      var remainingItems = new List<PackingInformation>();
     33
     34      //Iterate over all bin-lists
     35      for (int binNr = 0; binNr < nrOfBins; binNr++) {
     36        //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
     37        var unpackedItems = unpackedItemIndexesPerBin[binNr];
     38        for (int i = 0; i < unpackedItems.Count; i++) {
     39          var itemIndex = unpackedItems[i].ItemID;
     40          var item = itemMeasures[itemIndex];
     41          TwoDimensionalPacking position = null;
     42
     43          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     44
     45          if (position == null) {
     46            position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     47          }
     48          if (position == null) {
     49            remainingItems.Add(unpackedItems[i]);
     50          } else {
     51            packingPositions[itemIndex] = position;
     52            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
     53            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
     54          }
     55        }
     56      }
     57
     58      //Packing of remaining items
     59      //Iterate over all bin-lists
     60      for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
     61        var unpackedItems = new List<PackingInformation>(remainingItems);
     62        for (int i = 0; i < unpackedItems.Count; i++) {
     63          var itemIndex = unpackedItems[i].ItemID;
     64          var item = itemMeasures[itemIndex];
     65          TwoDimensionalPacking position = null;
     66
     67          //Look for space in current bin
     68          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     69
     70          if (position == null) {
     71            position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     72          }
     73          if (position != null) {
     74            packingPositions[itemIndex] = position;
     75            remainingItems.Remove(unpackedItems[i]);
     76            solution.PackingInformations[binNr].Add(unpackedItems[i]);
     77            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
     78          }
     79        }
     80        if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
     81          solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>();
     82          nrOfBins++;
     83        }
     84      }
     85
     86      return packingPositions;
     87    }
     88
     89    public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     90      GroupingVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
     91
     92      int nrOfBins = solution.GroupingVector.Max() + 1;
     93
     94      //Get all indexes of items for every bin according to grouping-vector
     95      //It is assumed, that at this point the item-indexes are sorted according to their item-size!
     96      Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>();
     97
     98      for (int i = 0; i < nrOfBins; i++) {
     99        unpackedItemIndexesPerBin[i] = solution.GroupingVector
     100          .Select((Value, Index) => new { Value, Index })
     101          .Where(temp => temp.Value == i)
     102          .Select(temp => temp.Index).ToList();
     103      }
     104
     105      ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     106      var remainingItems = new List<int>();
     107
     108      //Iterate over all bin-lists
     109      for (int binNr = 0; binNr < nrOfBins; binNr++) {
     110        //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
     111        var unpackedItems = unpackedItemIndexesPerBin[binNr];
     112        for (int i = 0; i < unpackedItems.Count; i++) {
     113          var itemIndex = unpackedItems[i];
     114          var item = itemMeasures[itemIndex];
     115          TwoDimensionalPacking position = null;
     116
     117          //Look for space in current bin
     118          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     119
     120          //Did not find enough space in current bin
     121          if (position == null) {
     122            remainingItems.Add(itemIndex);
     123          } else
     124            packingPositions[itemIndex] = position;
     125        }
     126      }
     127
     128      //Packing of remaining items
     129      //Iterate over all bin-lists
     130      for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
     131        var unpackedItems = new List<int>(remainingItems);
     132        for (int i = 0; i < unpackedItems.Count; i++) {
     133          var itemIndex = unpackedItems[i];
     134          var item = itemMeasures[itemIndex];
     135          TwoDimensionalPacking position = null;
     136
     137          //Look for space in current bin
     138          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     139
     140          if (position != null) {
     141            packingPositions[itemIndex] = position;
     142            remainingItems.Remove(itemIndex);
     143            solution.GroupingVector[itemIndex] = binNr;
     144          }
     145        }
     146        if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
     147          nrOfBins++;
     148        }
     149      }
     150
     151      return packingPositions;
     152    }
     153
     154    public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     155      PackingSequenceEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
     156
     157      ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     158      int nrOfBins = 1;
     159      for (int i = 0; i < solution.PackingSequence.Length; i++) {
     160        var item = itemMeasures[solution.PackingSequence[i]];
     161        TwoDimensionalPacking position = null;
     162        //Look for space in existing bins
     163        for (int binNr = 0; binNr < nrOfBins; binNr++) {
     164          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     165          if (position != null)
     166            break;
     167        }
     168        //Did not find enough space in any of the existing bins => create new bin
     169        if (position == null) {
     170          nrOfBins++;
     171          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, nrOfBins - 1, item, packingPositions, itemMeasures);
     172        }
     173
     174        if (position == null)
     175          position = new TwoDimensionalPacking(-1, 0, 0);
     176
     177        packingPositions[solution.PackingSequence[i]] = position;
     178      }
     179
     180      return packingPositions;
     181    }
     182
     183    private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) {
    20184      return BottomLeftPosition(binMeasures, binNr, currentItem, itemPositions, itemMeasures, false);
    21185    }
    22     public static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) {     
     186    private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) {     
    23187      TwoDimensionalPacking currentPosition = new TwoDimensionalPacking(binNr,
    24188        binMeasures.Width - (rotated ? currentItem.Height : currentItem.Width),
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftGroupingVectorDecoder.cs

    r9440 r9495  
    4141  [Item("Identical bin two dimensional grouping vector decoder", "<Description missing...>")]
    4242  [StorableClass]
    43   public class BottomLeftGroupingVectorDecoder : IdenticalBinPackingSolutionDecoder<
     43  public class BottomLeftGroupingVectorDecoder : PackingSolutionDecoder<
    4444      TwoDimensionalPacking,
    4545      RectangularPackingBin,
    46       RectangularPackingItem,
    47       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     46      RectangularPackingItem> {
    4847
    4948    public BottomLeftGroupingVectorDecoder()
     
    6160
    6261
    63     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     62    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6463
    6564      var solution = encodedSolution as GroupingVectorEncoding;
     
    6968        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    7069
    71       int nrOfBins = solution.GroupingVector.Max() + 1;
    72 
    73       //Get all indexes of items for every bin according to grouping-vector
    74       //It is assumed, that at this point the item-indexes are sorted according to their item-size!
    75       Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>();
    76 
    77       for (int i = 0; i < nrOfBins; i++) {
    78         unpackedItemIndexesPerBin[i] = solution.GroupingVector
    79           .Select((Value, Index) => new { Value, Index })
    80           .Where(temp => temp.Value == i)
    81           .Select(temp => temp.Index).ToList();
    82       }
    83 
    84       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    85       var remainingItems = new List<int>();
    86 
    87       //Iterate over all bin-lists
    88       for (int binNr = 0; binNr < nrOfBins; binNr++ ) {
    89         //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
    90         var unpackedItems = unpackedItemIndexesPerBin [binNr];
    91         for (int i = 0; i < unpackedItems.Count; i++ ) {
    92           var itemIndex = unpackedItems[i];
    93           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    94           TwoDimensionalPacking position = null;
    95 
    96           //Look for space in current bin
    97           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    98 
    99           //Did not find enough space in current bin
    100           if (position == null) {
    101             remainingItems.Add(itemIndex);
    102             //if (binNr + 1 >= nrOfBins) {
    103             //  nrOfBins++;
    104             //  unpackedItemIndexesPerBin[binNr + 1] = new List<int>();
    105             //  unpackedItemIndexesPerBin[binNr + 1].Add(itemIndex);
    106             //  unpackedItemIndexesPerBin[binNr].Remove(itemIndex);
    107             //} else {
    108             //  unpackedItemIndexesPerBin[binNr + 1].Add(itemIndex);
    109             //  unpackedItemIndexesPerBin[binNr + 1].Sort();
    110             //}
    111             //solution.GroupingVector[itemIndex] = binNr + 1;
    112           } else
    113             packingPositions[itemIndex] = position;
    114         }
    115       }
    116 
    117       //Packing of remaining items
    118       //Iterate over all bin-lists
    119       for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
    120         var unpackedItems = new List<int>(remainingItems);
    121         for (int i = 0; i < unpackedItems.Count; i++) {
    122           var itemIndex = unpackedItems[i];
    123           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    124           TwoDimensionalPacking position = null;
    125 
    126           //Look for space in current bin
    127           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    128 
    129           if (position != null) {
    130             packingPositions[itemIndex] = position;
    131             remainingItems.Remove(itemIndex);
    132             solution.GroupingVector[itemIndex] = binNr;
    133           }
    134         }
    135         if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
    136           nrOfBins++;
    137         }
    138       }
    139 
    140       result.PackingItemPositions = packingPositions;
    141 
    142 
     70      result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
    14371      return result;
    14472    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftMultiComponentVectorDecoder.cs

    r9440 r9495  
    4141  [Item("Identical bin two dimensional multi component vector decoder", "<Description missing...>")]
    4242  [StorableClass]
    43   public class BottomLeftMultiComponentVectorDecoder : IdenticalBinPackingSolutionDecoder<
     43  public class BottomLeftMultiComponentVectorDecoder : PackingSolutionDecoder<
    4444      TwoDimensionalPacking,
    4545      RectangularPackingBin,
    46       RectangularPackingItem,
    47       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     46      RectangularPackingItem> {
    4847
    4948    public BottomLeftMultiComponentVectorDecoder()
     
    6160
    6261
    63     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     62    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6463
    6564      var solution = encodedSolution as MultiComponentVectorEncoding;
     
    6867      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    6968        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    70       int nrOfBins = solution.PackingInformations.Max(pi => pi.AssignedBin) + 1;
    71 
    72       //Get all indexes of items for every bin according to grouping-vector
    73       Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>();
    74 
    75       for (int i = 0; i < nrOfBins; i++) {
    76         unpackedItemIndexesPerBin[i] = solution.PackingInformations
    77           .Where(pi => pi.AssignedBin == i)
    78           .ToList();
    79       }
    80 
    81       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    82       var remainingItems = new List<PackingInformation>();
    83 
    84       //Iterate over all bin-lists
    85       for (int binNr = 0; binNr < nrOfBins; binNr++) {
    86         //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
    87         var unpackedItems = unpackedItemIndexesPerBin[binNr];
    88         for (int i = 0; i < unpackedItems.Count; i++) {
    89           var itemIndex = unpackedItems[i].ItemIndex;
    90           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    91           TwoDimensionalPacking position = null;
    92 
    93           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated);
    94 
    95           if (position == null) {
    96             position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated);
    97           }
    98           if (position == null) {
    99             remainingItems.Add(unpackedItems[i]);
    100           } else {
    101             packingPositions[itemIndex] = position;
    102             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated;
    103           }
    104         }
    105       }
    106 
    107       //Packing of remaining items
    108       //Iterate over all bin-lists
    109       for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
    110         var unpackedItems = new List<PackingInformation>(remainingItems);
    111         for (int i = 0; i < unpackedItems.Count; i++) {
    112           var itemIndex = unpackedItems[i].ItemIndex;
    113           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    114           TwoDimensionalPacking position = null;
    115 
    116           //Look for space in current bin
    117           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated);
    118 
    119           if (position == null) {
    120             position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated);
    121           }
    122           if (position != null) {
    123             packingPositions[itemIndex] = position;
    124             remainingItems.Remove(unpackedItems[i]);
    125             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).AssignedBin = binNr;
    126             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated;
    127           }
    128         }
    129         if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
    130           nrOfBins++;
    131         }
    132       }
    133 
    134       result.PackingItemPositions = packingPositions;
     69     
     70      result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
    13571
    13672      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftPackingSequenceDecoder.cs

    r9440 r9495  
    4040  [Item("Identical bin, two dimensional, direct permutation decoder", "<Description missing...>")]
    4141  [StorableClass]
    42   public class BottomLeftPackingSequenceDecoder : IdenticalBinPackingSolutionDecoder<
     42  public class BottomLeftPackingSequenceDecoder : PackingSolutionDecoder<
    4343      TwoDimensionalPacking,
    4444      RectangularPackingBin,
    45       RectangularPackingItem,
    46       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     45      RectangularPackingItem> {
    4746
    4847    public BottomLeftPackingSequenceDecoder()
     
    6059
    6160
    62     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     61    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6362
    6463      var solution = encodedSolution as PackingSequenceEncoding;
     
    6867        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    6968
    70       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    71       int nrOfBins = 1;
    72       for (int i = 0; i < solution.PackingSequence.Length; i++) {
    73         var item = PackingItemMeasuresParameter.ActualValue[solution.PackingSequence[i]];
    74         TwoDimensionalPacking position = null;
    75         //Look for space in existing bins
    76         for (int binNr = 0; binNr < nrOfBins; binNr++) {
    77           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    78           if (position != null)
    79             break;
    80         }
    81         //Did not find enough space in any of the existing bins => create new bin
    82         if (position == null) {
    83           nrOfBins++;
    84           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, nrOfBins - 1, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    85         }
    86 
    87         if (position == null)
    88           position = new TwoDimensionalPacking(-1, 0, 0);
    89 
    90         packingPositions[solution.PackingSequence[i]] = position;
    91       }
    92 
    93       result.PackingItemPositions = packingPositions;
     69      result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking (solution, binMeasures, itemMeasures);
    9470
    9571      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointGroupingVectorDecoder2D.cs

    r9440 r9495  
    4141  [Item("Identical bin, two dimensional, extreme points based decoder for the GroupingVector encoding.", "<Description missing...>")]
    4242  [StorableClass]
    43   public class ExtremePointGroupingVectorDecoder2D : IdenticalBinPackingSolutionDecoder<
     43  public class ExtremePointGroupingVectorDecoder2D : PackingSolutionDecoder<
    4444      TwoDimensionalPacking,
    4545      RectangularPackingBin,
    46       RectangularPackingItem,
    47       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     46      RectangularPackingItem> {
    4847
    4948    public ExtremePointGroupingVectorDecoder2D ()
     
    6867    }
    6968
    70     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     69    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    7170                     
    7271      var solution = encodedSolution as GroupingVectorEncoding;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointMultiComponentVectorDecoder2D.cs

    r9440 r9495  
    4242  [Item("Identical bin, two dimensional, extreme points based decoder for the MultiComponentVector encoding.", "<Description missing...>")]
    4343  [StorableClass]
    44   public class ExtremePointMultiComponentVectorDecoder2D : IdenticalBinPackingSolutionDecoder<
     44  public class ExtremePointMultiComponentVectorDecoder2D : PackingSolutionDecoder<
    4545      TwoDimensionalPacking,
    4646      RectangularPackingBin,
    47       RectangularPackingItem,
    48       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     47      RectangularPackingItem> {
    4948
    5049    public ExtremePointMultiComponentVectorDecoder2D ()
     
    6968    }
    7069
    71     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     70    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    7271
    7372      var solution = encodedSolution as MultiComponentVectorEncoding;
    7473      if (solution == null) throw new InvalidOperationException("Encoding is not of type MultiComponentVector");
    7574
    76       return Decode(solution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     75      return Decode(solution, binMeasures, itemMeasures);
    7776    }
    7877  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointPackingSequenceDecoder2D.cs

    r9440 r9495  
    4040  [Item("Identical bin, two dimensional, extreme points based decoder for the PackingSequence encoding.", "<Description missing...>")]
    4141  [StorableClass]
    42   public class ExtremePointPackingSequenceDecoder2D : IdenticalBinPackingSolutionDecoder<
     42  public class ExtremePointPackingSequenceDecoder2D : PackingSolutionDecoder<
    4343      TwoDimensionalPacking,
    4444      RectangularPackingBin,
    45       RectangularPackingItem,
    46       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     45      RectangularPackingItem> {
    4746
    4847    public ExtremePointPackingSequenceDecoder2D ()
     
    5958
    6059
    61     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     60    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6261
    6362      var solution = encodedSolution as PackingSequenceEncoding;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointsFunctions2D.cs

    r9440 r9495  
    2424
    2525      #region Preperations
    26       int nrOfBins = solution.PackingInformations.Max(x => x.AssignedBin) + 1;
     26          int nrOfBins = solution.NrOfBins;
    2727
    2828      //Get all indexes of items for every bin according to grouping-vector                     
     
    3232
    3333      for (int i = 0; i < nrOfBins; i++) {       
    34         unpackedItemIndexesPerBin[i] = solution.PackingInformations
    35           .Where(pi => pi.AssignedBin == i)
    36           .ToList();
     34        unpackedItemIndexesPerBin[i] = new List<PackingInformation> (solution.PackingInformations[i]);
    3735
    3836        extremePointsForBin[i] = new HashSet<TwoDimensionalPacking>();
     
    5250        var unpackedItems = unpackedItemIndexesPerBin[binNr];
    5351        for (int i = 0; i < unpackedItems.Count; i++) {
    54           var itemIndex = unpackedItems[i].ItemIndex;
     52          var itemIndex = unpackedItems[i].ItemID;
    5553          var item = itemMeasures[itemIndex];
    5654
    57           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     55          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    5856          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, unpackedItems[i].Rotated);
    5957          if (positionFound != null) {
     
    6260            occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);
    6361            extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
    64           } else
     62          } else {
    6563            remainingItems.Add(unpackedItems[i]);
     64            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
     65          }
    6666        }
    6767      }
     
    7474        //Iterate over all the remaining items
    7575        for (int i = 0; i < unpackedItems.Count; i++) {
    76           var itemIndex = unpackedItems[i].ItemIndex;
     76          var itemIndex = unpackedItems[i].ItemID;
    7777          var item = itemMeasures[itemIndex];
    7878
    79           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     79          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    8080          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, unpackedItems[i].Rotated);
    8181          if (positionFound != null) {
     
    8585            extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
    8686            remainingItems.Remove(unpackedItems[i]);
     87            solution.PackingInformations[binNr].Add(unpackedItems[i]);
    8788          }
    8889        }
     
    9192          extremePointsForBin[nrOfBins].Add(new TwoDimensionalPacking(nrOfBins, 0, 0, false));
    9293          occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);
     94          solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>();
    9395          nrOfBins++;
    9496        }
     
    136138          var item = itemMeasures[itemIndex];
    137139
    138           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     140          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    139141          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
    140142          if (positionFound != null) {
     
    159161          var item = itemMeasures[itemIndex];
    160162
    161           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     163          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    162164          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
    163165          if (positionFound != null) {
     
    197199      foreach (int itemIndex in solution.PackingSequence) {
    198200        var item = itemMeasures[itemIndex];
    199         extremePoints = new HashSet<TwoDimensionalPacking>(extremePoints.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     201        extremePoints = OrderExtremePoints(extremePoints, occupiedPoints, binMeasures);
    200202        var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions);
    201203        if (positionFound != null) {
     
    296298      return extremePoints;
    297299    }
     300
     301    public static HashSet<TwoDimensionalPacking> OrderExtremePoints(HashSet<TwoDimensionalPacking> hashSet, List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) {
     302      return new HashSet<TwoDimensionalPacking>(hashSet.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ep.X).ThenBy(ep => ep.Y).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     303    }
    298304    private static int ShortestPossibleSideFromEP(TwoDimensionalPacking ep, List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) {
    299305      int shortestSide = int.MaxValue;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftFunctions.cs

    r9440 r9495  
    66using HeuristicLab.Core;
    77using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
     8using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    89using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    910using HeuristicLab.Problems.BinPacking.Dimensions;
     
    1617  public static class DeepestBottomLeftFunctions {
    1718
     19    public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(MultiComponentVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
     20      int nrOfBins = solution.NrOfBins;
     21
     22      //Get all indexes of items for every bin according to grouping-vector
     23      Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>();
     24
     25      for (int i = 0; i < nrOfBins; i++) {
     26        unpackedItemIndexesPerBin[i] = new List<PackingInformation>(solution.PackingInformations[i]);
     27      }
     28
     29      ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
     30      var remainingItems = new List<PackingInformation>();
     31
     32      //Iterate over all bin-lists
     33      for (int binNr = 0; binNr < nrOfBins; binNr++) {
     34        //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
     35        var unpackedItems = unpackedItemIndexesPerBin[binNr];
     36        for (int i = 0; i < unpackedItems.Count; i++) {
     37          var itemIndex = unpackedItems[i].ItemID;
     38          var item = itemMeasures[itemIndex];
     39          ThreeDimensionalPacking position = null;
     40
     41          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     42
     43          if (position == null) {
     44            position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     45          }
     46          if (position == null) {
     47            remainingItems.Add(unpackedItems[i]);
     48            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
     49          } else {
     50            packingPositions[itemIndex] = position;
     51            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
     52          }
     53        }
     54      }
     55
     56      //Packing of remaining items
     57      //Iterate over all bin-lists
     58      for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
     59        var unpackedItems = new List<PackingInformation>(remainingItems);
     60        for (int i = 0; i < unpackedItems.Count; i++) {
     61          var itemIndex = unpackedItems[i].ItemID;
     62          var item = itemMeasures[itemIndex];
     63          ThreeDimensionalPacking position = null;
     64
     65          //Look for space in current bin
     66          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     67
     68          if (position == null) {
     69            position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     70          }
     71          if (position != null) {
     72            packingPositions[itemIndex] = position;
     73            remainingItems.Remove(unpackedItems[i]);
     74            solution.PackingInformations[binNr].Add(unpackedItems[i]);
     75            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
     76          }
     77        }
     78        if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
     79          solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>();
     80          nrOfBins++;
     81        }
     82      }
     83
     84      return packingPositions;
     85    }
     86
    1887    public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(GroupingVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    1988      int nrOfBins = solution.GroupingVector.Max() + 1;
     
    77146    }
    78147
    79 
     148    public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(PackingSequenceEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
     149      ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
     150      int nrOfBins = 1;
     151      for (int i = 0; i < solution.PackingSequence.Length; i++) {
     152        var item = itemMeasures[solution.PackingSequence[i]];
     153        ThreeDimensionalPacking position = null;
     154        //Look for space in existing bins
     155        for (int binNr = 0; binNr < nrOfBins; binNr++) {
     156          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     157          if (position != null)
     158            break;
     159        }
     160        //Did not find enough space in any of the existing bins => create new bin
     161        if (position == null) {
     162          nrOfBins++;
     163          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, nrOfBins - 1, item, packingPositions, itemMeasures);
     164        }
     165
     166        if (position == null)
     167          position = new ThreeDimensionalPacking(-1, 0, 0, 0);
     168
     169        packingPositions[solution.PackingSequence[i]] = position;
     170      }
     171
     172      return packingPositions;
     173    }
    80174
    81175    public static ThreeDimensionalPacking DeepestLeftBottomPosition(CuboidPackingBin binMeasures, int binNr, CuboidPackingItem currentItem, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, ItemList<CuboidPackingItem> itemMeasures) {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftGroupingVectorDecoder.cs

    r9440 r9495  
    4040  [Item("Identical bin three dimensional direct grouping vector decoder", "<Description missing...>")]
    4141  [StorableClass]
    42   public class DeepestBottomLeftGroupingVectorDecoder : IdenticalBinPackingSolutionDecoder<
     42  public class DeepestBottomLeftGroupingVectorDecoder : PackingSolutionDecoder<
    4343      ThreeDimensionalPacking,
    4444      CuboidPackingBin,
    45       CuboidPackingItem,
    46       PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> {
     45      CuboidPackingItem> {
    4746
    4847    public DeepestBottomLeftGroupingVectorDecoder()
     
    6059
    6160
    62     protected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     61    public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    6362
    6463      var solution = encodedSolution as GroupingVectorEncoding;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftMultiComponentVectorDecoder.cs

    r9440 r9495  
    4141  [Item("Identical bin three dimensional multi component vector decoder", "<Description missing...>")]
    4242  [StorableClass]
    43   public class DeepestBottomLeftMultiComponentVectorDecoder : IdenticalBinPackingSolutionDecoder<
     43  public class DeepestBottomLeftMultiComponentVectorDecoder : PackingSolutionDecoder<
    4444      ThreeDimensionalPacking,
    4545      CuboidPackingBin,
    46       CuboidPackingItem,
    47       PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> {
     46      CuboidPackingItem> {
    4847
    4948    public DeepestBottomLeftMultiComponentVectorDecoder()
     
    6160
    6261
    63     protected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     62    public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    6463
    6564      var solution = encodedSolution as MultiComponentVectorEncoding;
     
    6867      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result =
    6968        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    70       int nrOfBins = solution.PackingInformations.Max(pi => pi.AssignedBin) + 1;
    71 
    72       //Get all indexes of items for every bin according to grouping-vector
    73       Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>();
    74 
    75       for (int i = 0; i < nrOfBins; i++) {
    76         unpackedItemIndexesPerBin[i] = solution.PackingInformations
    77           .Where(pi => pi.AssignedBin == i)
    78           .ToList();
    79       }
    80 
    81       ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
    82       var remainingItems = new List<PackingInformation>();
    83 
    84       //Iterate over all bin-lists
    85       for (int binNr = 0; binNr < nrOfBins; binNr++) {
    86         //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
    87         var unpackedItems = unpackedItemIndexesPerBin[binNr];
    88         for (int i = 0; i < unpackedItems.Count; i++) {
    89           var itemIndex = unpackedItems[i].ItemIndex;
    90           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    91           ThreeDimensionalPacking position = null;
    92 
    93           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated);
    94 
    95           if (position == null) {
    96             position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated);
    97           }
    98           if (position == null) {
    99             remainingItems.Add(unpackedItems[i]);
    100           } else {
    101             packingPositions[itemIndex] = position;
    102             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated;
    103           }
    104         }
    105       }
    106 
    107       //Packing of remaining items
    108       //Iterate over all bin-lists
    109       for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
    110         var unpackedItems = new List<PackingInformation>(remainingItems);
    111         for (int i = 0; i < unpackedItems.Count; i++) {
    112           var itemIndex = unpackedItems[i].ItemIndex;
    113           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    114           ThreeDimensionalPacking position = null;
    115 
    116           //Look for space in current bin
    117           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated);
    118 
    119           if (position == null) {
    120             position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated);
    121           }
    122           if (position != null) {   
    123             packingPositions[itemIndex] = position;
    124             remainingItems.Remove(unpackedItems[i]);
    125             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).AssignedBin = binNr;
    126             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated;
    127           }
    128         } 
    129         if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
    130           nrOfBins++;
    131         }
    132       }
    133 
    134       result.PackingItemPositions = packingPositions;
     69     
     70      result.PackingItemPositions = DeepestBottomLeftFunctions.DeepestLeftBottomPacking (solution, binMeasures, itemMeasures);
    13571
    13672      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftPackingSequenceDecoder.cs

    r9440 r9495  
    4040  [Item("Identical bin, three dimensional, direct permutation decoder", "<Description missing...>")]
    4141  [StorableClass]
    42   public class DeepestBottomLeftPackingSequenceDecoder : IdenticalBinPackingSolutionDecoder<
     42  public class DeepestBottomLeftPackingSequenceDecoder : PackingSolutionDecoder<
    4343      ThreeDimensionalPacking,
    4444      CuboidPackingBin,
    45       CuboidPackingItem,
    46       PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> {
     45      CuboidPackingItem> {
    4746
    4847    public DeepestBottomLeftPackingSequenceDecoder()
     
    6059
    6160
    62     protected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     61    public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    6362
    6463      var solution = encodedSolution as PackingSequenceEncoding;
     
    6867        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    6968
    70       ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
    71       int nrOfBins = 1;
    72       for (int i = 0; i < solution.PackingSequence.Length; i++) {
    73         var item = PackingItemMeasuresParameter.ActualValue[solution.PackingSequence[i]];
    74         ThreeDimensionalPacking position = null;
    75         //Look for space in existing bins
    76         for (int binNr = 0; binNr < nrOfBins; binNr++) {
    77           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    78           if (position != null)
    79             break;
    80         }
    81         //Did not find enough space in any of the existing bins => create new bin
    82         if (position == null) {
    83           nrOfBins++;
    84           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(PackingBinMeasuresParameter.ActualValue, nrOfBins - 1, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    85         }
    86 
    87         if (position == null)
    88           position = new ThreeDimensionalPacking(-1, 0, 0, 0);
    89 
    90         packingPositions[solution.PackingSequence[i]] = position;
    91       }
    92 
    93       result.PackingItemPositions = packingPositions;
     69      result.PackingItemPositions = DeepestBottomLeftFunctions.DeepestLeftBottomPacking (solution, binMeasures, itemMeasures);
    9470
    9571      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointGroupingVectorDecoder3D.cs

    r9440 r9495  
    4141  [Item("Identical bin, three dimensional, extreme points based decoder for the GroupingVector encoding.", "<Description missing...>")]
    4242  [StorableClass]
    43   public class ExtremePointGroupingVectorDecoder3D : IdenticalBinPackingSolutionDecoder<
     43  public class ExtremePointGroupingVectorDecoder3D : PackingSolutionDecoder<
    4444      ThreeDimensionalPacking,
    4545      CuboidPackingBin,
    46       CuboidPackingItem,
    47       PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> {
     46      CuboidPackingItem> {
    4847
    4948    public ExtremePointGroupingVectorDecoder3D ()
     
    6867    }
    6968
    70     protected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     69    public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    7170                     
    7271      var solution = encodedSolution as GroupingVectorEncoding;
    7372      if (solution == null) throw new InvalidOperationException("Encoding is not of type GroupingVector");
    7473
    75       return Decode(solution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     74      return Decode(solution, binMeasures, itemMeasures);
    7675    }
    7776  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointMultiComponentVectorDecoder3D.cs

    r9440 r9495  
    4242  [Item("Identical bin, three dimensional, extreme points based decoder for the MultiComponentVector encoding.", "<Description missing...>")]
    4343  [StorableClass]
    44   public class ExtremePointMultiComponentVectorDecoder3D : IdenticalBinPackingSolutionDecoder<
     44  public class ExtremePointMultiComponentVectorDecoder3D : PackingSolutionDecoder<
    4545      ThreeDimensionalPacking,
    4646      CuboidPackingBin,
    47       CuboidPackingItem,
    48       PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> {
     47      CuboidPackingItem> {
    4948
    5049    public ExtremePointMultiComponentVectorDecoder3D ()
     
    6968    }
    7069
    71     protected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     70    public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    7271
    7372      var solution = encodedSolution as MultiComponentVectorEncoding;
    7473      if (solution == null) throw new InvalidOperationException("Encoding is not of type MultiComponentVector");
    7574
    76       return Decode(solution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     75      return Decode(solution, binMeasures, itemMeasures);
    7776    }
    7877  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointPackingSequenceDecoder3D.cs

    r9440 r9495  
    4040  [Item("Identical bin, three dimensional, extreme points based decoder for the PackingSequence encoding.", "<Description missing...>")]
    4141  [StorableClass]
    42   public class ExtremePointPackingSequenceDecoder3D : IdenticalBinPackingSolutionDecoder<
     42  public class ExtremePointPackingSequenceDecoder3D : PackingSolutionDecoder<
    4343      ThreeDimensionalPacking,
    4444      CuboidPackingBin,
    45       CuboidPackingItem,
    46       PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> {
     45      CuboidPackingItem> {
    4746
    4847    public ExtremePointPackingSequenceDecoder3D ()
     
    5958
    6059
    61     protected override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     60    public override PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    6261
    6362      var solution = encodedSolution as PackingSequenceEncoding;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointsFunctions3D.cs

    r9473 r9495  
    99using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    1010using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    11 using HeuristicLab.Encodings.PackingEncoding.Potvin;
    1211using HeuristicLab.Problems.BinPacking.Dimensions;
    1312using HeuristicLab.Problems.BinPacking.Interfaces;
     
    2019
    2120
    22 
    23     public static ObservableDictionary<int, ThreeDimensionalPacking> ExtremePointBasedPacking(ref PotvinEncoding solution,
    24       ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures) {
    25         if (!solution.DelimiterInitialized) {
    26           #region Preperations
    27           var itemPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
    28           int nrOfBins = 1;
    29 
    30           var occupiedPoints = new List<int[, ,]>();
    31           occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);
    32 
    33           HashSet<ThreeDimensionalPacking> extremePoints = new HashSet<ThreeDimensionalPacking>();
    34           extremePoints.Add(new ThreeDimensionalPacking(0, 0, 0, 0, false));
    35           #endregion
    36 
    37           Dictionary<int, List<int>> itemIndexesForBin = new Dictionary<int, List<int>>();
    38           itemIndexesForBin[0] = new List<int>();
    39 
    40           foreach (int itemIndex in solution.IntVector) {
    41             var item = itemMeasures[itemIndex];
    42             extremePoints = OrderExtremePoints(extremePoints, occupiedPoints, binMeasures);
    43             var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions);
    44             if (positionFound != null) {
    45               extremePoints.Remove(positionFound);
    46             } else {
    47               positionFound = new ThreeDimensionalPacking(nrOfBins, 0, 0, 0);
    48               occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);
    49               itemIndexesForBin[nrOfBins] = new List<int>();
    50               nrOfBins++;
    51             }
    52             itemPositions[itemIndex] = positionFound;
    53             itemIndexesForBin[positionFound.AssignedBin].Add(itemIndex);
    54             occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);
    55             extremePoints = GenerateNewExtremePointsForNewItem(extremePoints, occupiedPoints, item, positionFound, binMeasures);
    56           }
    57           List<int> intVector = new List<int>();
    58           foreach (var indexes in itemIndexesForBin) {
    59             foreach (var index in indexes.Value) {
    60               intVector.Add(index);
    61             }
    62             intVector.Add(-1);
    63           }
    64           intVector.RemoveAt(intVector.Count - 1);
    65           solution.IntVector = new IntegerVector (intVector.ToArray());
    66 
    67           return itemPositions;
    68         } else {
    69           #region Preperations
    70           int nrOfBins = solution.IntVector.Count(i => i.Equals (-1)) + 1;
    71 
    72           //Get all indexes of items for every bin according to int vector
    73           Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>();
    74           Dictionary<int, HashSet<ThreeDimensionalPacking>> extremePointsForBin = new Dictionary<int, HashSet<ThreeDimensionalPacking>>();
    75           var occupiedPoints = new List<int[, ,]>();
    76 
    77           int binCounter = 0;
    78           unpackedItemIndexesPerBin[binCounter] = new List<int>();
    79           for (int i = 0; i < solution.IntVector.Length; i++) {
    80             if (solution.IntVector[i].Equals(-1)) {
    81               unpackedItemIndexesPerBin[binCounter++] = new List<int>();
    82               extremePointsForBin[i] = new HashSet<ThreeDimensionalPacking>();
    83               extremePointsForBin[i].Add(new ThreeDimensionalPacking(i, 0, 0, 0, false));
    84               occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);
    85             } else {
    86               unpackedItemIndexesPerBin[binCounter].Add(solution.IntVector[i]);
    87             }
    88 
    89           }
    90 
    91 
    92           ObservableDictionary<int, ThreeDimensionalPacking> itemPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
    93           var remainingItems = new List<int>();
    94 
    95           #endregion Preperations
    96 
    97 
    98 
    99           //Iterate over all bin-lists
    100           for (int binNr = 0; binNr < nrOfBins; binNr++) {
    101             //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
    102             var unpackedItems = unpackedItemIndexesPerBin[binNr];
    103             for (int i = 0; i < unpackedItems.Count; i++) {
    104               var itemIndex = unpackedItems[i];
    105               var item = itemMeasures[itemIndex];
    106 
    107               extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    108               var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
    109               if (positionFound != null) {
    110                 extremePointsForBin[binNr].Remove(positionFound);
    111                 itemPositions[itemIndex] = positionFound;
    112                 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);
    113                 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
    114               } else
    115                 remainingItems.Add(itemIndex);
    116             }
    117           }
    118 
    119 
    120 
    121           //Packing of remaining items   
    122           //Iterate over all bin-lists
    123           for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
    124             var unpackedItems = new List<int>(remainingItems);
    125             //Iterate over all the remaining items
    126             for (int i = 0; i < unpackedItems.Count; i++) {
    127               var itemIndex = unpackedItems[i];
    128               var item = itemMeasures[itemIndex];
    129 
    130               extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    131               var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
    132               if (positionFound != null) {
    133                 extremePointsForBin[binNr].Remove(positionFound);
    134                 InsertItemgeneAfterLastItemgeneOfUsedBin(ref solution, itemIndex, binNr);
    135                 itemPositions[itemIndex] = positionFound;
    136                 occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);
    137                 extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
    138                 remainingItems.Remove(itemIndex);
    139               }
    140             }
    141             if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
    142               extremePointsForBin[nrOfBins] = new HashSet<ThreeDimensionalPacking>();
    143               extremePointsForBin[nrOfBins].Add(new ThreeDimensionalPacking(nrOfBins, 0, 0, 0, false));
    144               occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);
    145               nrOfBins++;
    146             }
    147           }
    148 
    149           return itemPositions;
    150         }
    151     }
    152     private static void InsertItemgeneAfterLastItemgeneOfUsedBin(ref PotvinEncoding solution, int itemIndex, int binNr) {
    153       List<int> temp = new List<int> (solution.IntVector);
    154       temp.Remove(itemIndex);
    155       var delimiterIndexes = temp.Select((value, index) => value == -1).Select((value, index) => index);
    156       int insertionIndex = temp.Count;
    157       if (binNr < delimiterIndexes.Count()) {
    158         insertionIndex = delimiterIndexes.ElementAt(binNr);
    159       }
    160       temp.Insert(insertionIndex, itemIndex);
    161       solution.IntVector = new IntegerVector (temp.ToArray());
    162     }
    163 
    164 
    16521    public static ObservableDictionary<int, ThreeDimensionalPacking> ExtremePointBasedPacking(ref MultiComponentVectorEncoding solution,
    16622        ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures) {
    16723
    16824      #region Preperations
    169       int lowerBound = solution.PackingInformations.Max(x => x.AssignedBin);
    170       int nrOfBins = lowerBound + 1;
     25      int nrOfBins = solution.NrOfBins;
    17126
    17227      //Get all indexes of items for every bin according to grouping-vector                     
     
    17631
    17732      for (int i = 0; i < nrOfBins; i++) {       
    178         unpackedItemIndexesPerBin[i] = solution.PackingInformations
    179           .Where(pi => pi.AssignedBin == i)
    180           .ToList();
     33        unpackedItemIndexesPerBin[i] = new List<PackingInformation> (solution.PackingInformations[i]);
    18134
    18235        extremePointsForBin[i] = new HashSet<ThreeDimensionalPacking>();
     
    19649        var unpackedItems = unpackedItemIndexesPerBin[binNr];
    19750        for (int i = 0; i < unpackedItems.Count; i++) {
    198           var itemIndex = unpackedItems[i].ItemIndex;
     51          var itemIndex = unpackedItems[i].ItemID;
    19952          var item = itemMeasures[itemIndex];
    20053
     
    20659            occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);
    20760            extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
    208           } else
     61          } else {
    20962            remainingItems.Add(unpackedItems[i]);
     63            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
     64          }
    21065        }
    21166      }
     
    21873        //Iterate over all the remaining items
    21974        for (int i = 0; i < unpackedItems.Count; i++) {
    220           var itemIndex = unpackedItems[i].ItemIndex;
     75          var itemIndex = unpackedItems[i].ItemID;
    22176          var item = itemMeasures[itemIndex];
    22277
     
    22782            itemPositions[itemIndex] = positionFound;
    22883            occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);
    229             extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
     84            extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);     
    23085            remainingItems.Remove(unpackedItems[i]);
    231             if (binNr <= lowerBound) {
    232               InsertItemgeneAfterLastItemgeneOfUsedBin(ref solution, itemIndex, binNr);
    233             }
     86            solution.PackingInformations[binNr].Add(unpackedItems[i]);
    23487          }
    23588        }
     
    23891          extremePointsForBin[nrOfBins].Add(new ThreeDimensionalPacking(nrOfBins, 0, 0, 0, false));
    23992          occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);
     93          solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>();
    24094          nrOfBins++;
    24195        }
     
    24397
    24498      return itemPositions;
    245     }
    246     private static void InsertItemgeneAfterLastItemgeneOfUsedBin(ref MultiComponentVectorEncoding solution, int itemIndex, int binNr) {
    247       var itemgene = solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex);
    248       solution.PackingInformations.Remove (itemgene);
    249       itemgene.AssignedBin = binNr;
    250       int targetIndex = solution.PackingInformations.FindLastIndex(pi => pi.AssignedBin == binNr);
    251       solution.PackingInformations.Insert(targetIndex + 1, itemgene);
    25299    }
    253100
     
    370217
    371218
    372     private static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
     219    public static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
    373220        HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions) {
    374221          return FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions, false);
    375222    }
    376     private static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
     223    public static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
    377224        HashSet<ThreeDimensionalPacking> extremePoints, List<int[,,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, bool rotated) {
    378225
     
    397244      return null;
    398245    }
    399     private static List<int[, ,]> IncreaseBinCountForOccupiedPoints(List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {
     246    public static List<int[, ,]> IncreaseBinCountForOccupiedPoints(List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {
    400247      occupiedPoints.Add(new int[binMeasures.Width, binMeasures.Height, binMeasures.Depth]);
    401248      int lastIndex = occupiedPoints.Count - 1;
     
    409256      return occupiedPoints;
    410257    }
    411     private static bool IsStaticStable(int[, ,] occupiedPoints, CuboidPackingItem item, ThreeDimensionalPacking ep) {
     258    public static bool IsStaticStable(int[, ,] occupiedPoints, CuboidPackingItem item, ThreeDimensionalPacking ep) {
    412259      //Static stability is given, if item is placed on the ground
    413260      if (ep.Y == 0)
     
    433280      return false;
    434281    }
    435     private static List<int[, ,]>  OccupyPointsForNewItem(List<int[, ,]> occupiedPoints, CuboidPackingItem newItem, ThreeDimensionalPacking position, int itemIndex) {
     282    public static List<int[, ,]>  OccupyPointsForNewItem(List<int[, ,]> occupiedPoints, CuboidPackingItem newItem, ThreeDimensionalPacking position, int itemIndex) {
    436283      int width = position.Rotated ? newItem.Depth : newItem.Width;
    437284      int depth = position.Rotated ? newItem.Width : newItem.Depth;
     
    445292      return occupiedPoints;
    446293    }
    447     private static HashSet<ThreeDimensionalPacking> GenerateNewExtremePointsForNewItem(HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints,
     294    public static HashSet<ThreeDimensionalPacking> GenerateNewExtremePointsForNewItem(HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints,
    448295        CuboidPackingItem newItem, ThreeDimensionalPacking position, CuboidPackingBin binMeasures) {
    449296      int currentBin = position.AssignedBin;
     
    518365
    519366
    520     private static HashSet<ThreeDimensionalPacking> OrderExtremePoints(HashSet<ThreeDimensionalPacking> hashSet, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {
     367    public static HashSet<ThreeDimensionalPacking> OrderExtremePoints(HashSet<ThreeDimensionalPacking> hashSet, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {
    521368      return new HashSet<ThreeDimensionalPacking>(hashSet.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ep.Z).ThenBy(ep => ep.X).ThenBy(ep => ep.Y).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
    522369    }
    523     private static int ShortestPossibleSideFromEP(ThreeDimensionalPacking ep, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {
     370    public static int ShortestPossibleSideFromEP(ThreeDimensionalPacking ep, List<int[, ,]> occupiedPoints, CuboidPackingBin binMeasures) {
    524371      int shortestSide = int.MaxValue;
    525372
  • 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
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/Abstract/BinUtilizationRegularIdenticalBinEvaluator.cs

    r9440 r9495  
    6666
    6767      //if (itemPositionsAreValid)
    68       return CalculateBinUtilization(plan as PackingPlan<D, B, I>, binMeasure, itemMeasures);
     68      return CalculateBinUtilization(plan as SingleBinSizePackingPlan<D, B, I>, binMeasure, itemMeasures);
    6969
    7070      //return quality;
    7171    }
    7272
    73     public static DoubleValue CalculateBinUtilization(PackingPlan<D, B, I> plan, B binMeasure, ItemList<I> itemMeasures) {
     73    public static DoubleValue CalculateBinUtilization(SingleBinSizePackingPlan<D, B, I> plan, B binMeasure, ItemList<I> itemMeasures) {
    7474      int nrOfBins = plan.NrOfBins;
    7575      double result = 0;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/Abstract/PackingPlanEvaluator.cs

    r9440 r9495  
    7272
    7373
    74     protected abstract DoubleValue Evaluate();
    75 
     74    protected abstract DoubleValue Evaluate();                                                                       
    7675    public override IOperation Apply() {
    7776      QualityParameter.ActualValue = Evaluate();
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/HeuristicLab.Problems.BinPacking-3.3.csproj

    r9473 r9495  
    176176    <Compile Include="Decoders\3D\DBL\DeepestBottomLeftMultiComponentVectorDecoder.cs" />
    177177    <Compile Include="Decoders\3D\DBL\DeepestBottomLeftFunctions.cs" />
    178     <Compile Include="Decoders\3D\EP\ExtremePointPotvinDecoder3D.cs">
    179       <SubType>Code</SubType>
    180     </Compile>
    181178    <Compile Include="Decoders\3D\EP\ExtremePointsFunctions3D.cs" />
    182179    <Compile Include="Decoders\3D\DBL\DeepestBottomLeftGroupingVectorDecoder.cs" />
     
    184181    <Compile Include="Decoders\3D\DBL\DeepestBottomLeftPackingSequenceDecoder.cs" />
    185182    <Compile Include="Decoders\2D\BL\BottomLeftPackingSequenceDecoder.cs" />
    186     <Compile Include="Decoders\IdenticalBinPackingSolutionDecoder.cs" />
     183    <Compile Include="Decoders\PackingSolutionDecoder.cs" />
    187184    <Compile Include="Encodings\GroupingVector\Moves\SingleGrouping\SingleGroupingMoveSoftTabuCriterion.cs" />
    188     <Compile Include="Encodings\GroupingVector\Moves\SingleGrouping\ExhaustiveTargetBinSingleGroupingMoveGenerator.cs" />
    189185    <Compile Include="Encodings\GroupingVector\Moves\SingleGrouping\ExhaustiveSingleGroupingMoveGenerator.cs" />
    190186    <Compile Include="Encodings\GroupingVector\Moves\SingleGrouping\SingleGroupingMove.cs" />
     
    194190    <Compile Include="Encodings\GroupingVector\Moves\SingleGrouping\SingleGroupingTabuMaker.cs" />
    195191    <Compile Include="Encodings\GroupingVector\Moves\SingleGrouping\SingleGroupingMoveHardTabuCriterion.cs" />
     192    <Compile Include="Encodings\GroupingVector\Moves\SingleGrouping\StochasticSingleGroupingMoveGenerator.cs" />
    196193    <Compile Include="Encodings\GroupingVector\UniformGroupingVectorManipulator.cs" />
    197194    <Compile Include="Encodings\GroupingVector\GroupingVectorCrossover.cs" />
     
    199196    <Compile Include="Encodings\GroupingVector\GroupingVectorManipulator.cs" />
    200197    <Compile Include="Encodings\GroupingVector\GroupingVectorRandomCreator.cs" />
     198    <Compile Include="Encodings\MultiComponentVector\SequencePreservingMultiComponentVectorCrossover.cs" />
    201199    <Compile Include="Encodings\MultiComponentVector\Moves\ThreeWay\Attributes\ChangePositionMoveAttribute.cs" />
    202200    <Compile Include="Encodings\MultiComponentVector\Moves\ThreeWay\Attributes\MCVTripleMoveAttribute.cs" />
     
    223221      <SubType>Code</SubType>
    224222    </Compile>
    225     <Compile Include="Encodings\MultiComponentVector\PartiallyMatchedMultiComponentVectorCrossover.cs" />
    226223    <Compile Include="Encodings\MultiComponentVector\MultiComponentVectorCrossover.cs" />
    227224    <Compile Include="Encodings\MultiComponentVector\MultiComponentVectorManipulator.cs" />
     
    236233    <Compile Include="Encodings\PackingSolutionCrossover.cs" />
    237234    <Compile Include="Encodings\PackingSolutionManipulator.cs" />
    238     <Compile Include="Encodings\Potvin\PotvinEncoding.cs">
    239       <SubType>Code</SubType>
    240     </Compile>
    241     <Compile Include="Encodings\Potvin\PotvinRandomCreator.cs">
    242       <SubType>Code</SubType>
    243     </Compile>
    244     <Compile Include="Evaluators\2D\BinUtilizationRectangularIdenticalBinEvaluator.cs" />
    245235    <Compile Include="Evaluators\2D\PackingRatioRectangularIdenticalBinEvaluator.cs" />
    246     <Compile Include="Evaluators\3D\BinUtilizationCuboiddenticalBinEvaluator.cs" />
    247236    <Compile Include="Evaluators\3D\PackingRatioCuboidIdenticalBinEvaluator.cs" />
    248     <Compile Include="Evaluators\Abstract\BinUtilizationRegularIdenticalBinEvaluator.cs" />
    249237    <Compile Include="Evaluators\Abstract\PackingRatioRegularIdenticalBinEvaluator.cs" />
    250238    <Compile Include="Evaluators\Abstract\RegularSimpleRotationIdenticalBinPackingPlanEvaluator.cs" />
     
    257245    <Compile Include="Instances\BPPORLIBParser.cs" />
    258246    <Compile Include="Instances\BPPORLIBDataDescriptor.cs" />
     247    <Compile Include="Interfaces\I3DOperator.cs" />
     248    <Compile Include="Interfaces\I2DOperator.cs" />
     249    <Compile Include="Interfaces\IPackingMove.cs" />
    259250    <Compile Include="Interfaces\IPotvinOperator.cs" />
    260251    <Compile Include="Interfaces\IMultiComponentVectorMoveOperator.cs" />
     
    274265    <Compile Include="Interfaces\IPackingShape.cs" />
    275266    <Compile Include="Interfaces\IPackingDimensions.cs" />
    276     <Compile Include="MoveEvaluators\MultiComponentVectorMoveEvaluator.cs" />
    277267    <Compile Include="MoveEvaluators\PackingMoveEvaluator.cs" />
    278     <Compile Include="MoveEvaluators\GroupingVectorMoveEvaluator.cs" />
     268    <Compile Include="MoveEvaluators\PackingMoveEvaluator2DGV.cs">
     269      <SubType>Code</SubType>
     270    </Compile>
     271    <Compile Include="MoveEvaluators\PackingMoveEvaluator2DMCV.cs">
     272      <SubType>Code</SubType>
     273    </Compile>
     274    <Compile Include="MoveEvaluators\PackingMoveEvaluator3DGV.cs">
     275      <SubType>Code</SubType>
     276    </Compile>
     277    <Compile Include="MoveEvaluators\PackingMoveEvaluator3DMCV.cs">
     278      <SubType>Code</SubType>
     279    </Compile>
    279280    <Compile Include="Problem\BinPackingProblem.cs" />
     281    <Compile Include="Problem\ISOContainerBinPackingProblem.cs" />
    280282    <Compile Include="Problem\CuboidIdenticalBinPackingProblem.cs" />
    281283    <Compile Include="Problem\RegularIdenticalBinPackingProblem.cs" />
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/MoveEvaluators/GroupingVectorMoveEvaluator.cs

    r9440 r9495  
    6868
    6969      var packingPlan = ExtremePointGroupingVectorDecoder3D.Decode(newSolution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     70      CurrentScopeParameter.ActualValue.Variables.Add(new Variable("PackingPlanAfterMove", packingPlan));
     71
    7072      DoubleValue quality = PackingRatioRegularIdenticalBinEvaluator<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.CalculatePackingRatio(
    7173        packingPlan, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/MoveEvaluators/MultiComponentVectorMoveEvaluator.cs

    r9440 r9495  
    3939  [StorableClass]
    4040  public class MultiComponentVectorMoveEvaluator : PackingMoveEvaluator<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>, ISingleObjectiveMoveEvaluator, IMultiComponentVectorMoveOperator{
    41     public ILookupParameter<MultiComponentVectorMove> MultiComponentVectorMoveParameter {
    42       get { return (ILookupParameter<MultiComponentVectorMove>)Parameters["MultiComponentVectorMove"]; } 
     41    public ILookupParameter<IPackingMove> MultiComponentVectorMoveParameter {
     42      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; } 
    4343    }               
    4444    public ILookupParameter<MultiComponentVectorEncoding> MultiComponentVectorParameter {
     
    5151    public MultiComponentVectorMoveEvaluator()
    5252      : base() {
    53       Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));
     53        //Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
    5454      Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate."));
    5555    }
     
    6060
    6161    public override IOperation Apply() {
    62       MultiComponentVectorEncoding MultiComponentVector = MultiComponentVectorParameter.ActualValue;
    63       MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;
     62      //MultiComponentVectorEncoding MultiComponentVector = MultiComponentVectorParameter.ActualValue;
     63      //MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue as MultiComponentVectorMove;
    6464
    65       MultiComponentVectorEncoding newSolution = new MultiComponentVectorEncoding();
    66       newSolution = move.GetVectorAfterMove();
     65      //MultiComponentVectorEncoding newSolution = new MultiComponentVectorEncoding();
     66      //newSolution = move.GetSolutionAfterMove() as MultiComponentVectorEncoding;
     67      //CurrentScopeParameter.ActualValue.Variables.Add(new Variable("MovedSolution", newSolution));
    6768
    68       var packingPlan = ExtremePointMultiComponentVectorDecoder3D.Decode(newSolution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    69       DoubleValue quality = PackingRatioRegularIdenticalBinEvaluator<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.CalculatePackingRatio(
    70         packingPlan, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     69      //var packingPlan = ExtremePointMultiComponentVectorDecoder3D.Decode(newSolution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     70      //CurrentScopeParameter.ActualValue.Variables.Add(new Variable("PackingPlanAfterMove", packingPlan));
    7171
    72       double moveQuality = quality.Value;
     72      //DoubleValue quality = PackingRatioRegularIdenticalBinEvaluator<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.CalculatePackingRatio(
     73      //  packingPlan, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    7374
    74       if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
    75       else MoveQualityParameter.ActualValue.Value = moveQuality;
     75      //double moveQuality = quality.Value;
     76
     77      //if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
     78      //else MoveQualityParameter.ActualValue.Value = moveQuality;
    7679      return base.Apply();
    7780    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/MoveEvaluators/PackingMoveEvaluator.cs

    r9440 r9495  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
    2627using HeuristicLab.Operators;
    2728using HeuristicLab.Optimization;
    2829using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Problems.BinPacking.Decoders;
     32using HeuristicLab.Problems.BinPacking.Evaluators;
    3033using HeuristicLab.Problems.BinPacking.Interfaces;
    3134using HeuristicLab.Problems.BinPacking.Shapes;
     
    3639  public abstract class PackingMoveEvaluator<D, B, I> : SingleSuccessorOperator, IPackingMoveEvaluator, IMoveOperator
    3740    where D : class, IPackingDimensions
    38     where B : PackingShape<D>, IPackingBin
    39     where I : PackingShape<D>, IPackingItem {     
     41    where B : PackingShape<D>, IPackingBin, IRegularPackingShape
     42    where I : PackingShape<D>, IPackingItem, IRegularPackingShape {     
    4043    public override bool CanChangeName {
    4144      get { return false; }
     
    6063      get { return (IValueLookupParameter<IPackingPlanEvaluator>)Parameters["PackingPlanEvaluator"]; }
    6164    }
     65    protected ScopeParameter CurrentScopeParameter {
     66      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     67    }
     68    public ILookupParameter<IPackingMove> PackingMoveParameter {
     69      get { return (ILookupParameter<IPackingMove>)Parameters["PackingMove"]; }
     70    } 
    6271   
    6372    [StorableConstructor]
     
    7281      Parameters.Add(new ValueLookupParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
    7382      Parameters.Add(new ValueLookupParameter<IPackingPlanEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator."));
     83      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the decoded solution should be added to."));
     84      Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate."));
     85    }
     86
     87
     88
     89    public override IOperation Apply() {
     90      IPackingMove move = PackingMoveParameter.ActualValue;
     91      IPackingSolutionEncoding newSolution = move.GetSolutionAfterMove();
     92      CurrentScopeParameter.ActualValue.Variables.Add(new Variable("MovedSolution", newSolution));
     93
     94      PackingPlan<D, B, I> packingPlan = (PackingSolutionDecoderParameter.ActualValue as PackingSolutionDecoder<D, B, I>).
     95        CreatePackingPlanFromEncoding(newSolution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     96
     97
     98      CurrentScopeParameter.ActualValue.Variables.Add(new Variable("PackingPlanAfterMove", packingPlan));
     99
     100      DoubleValue quality = PackingRatioRegularIdenticalBinEvaluator<D, B, I>.CalculatePackingRatio(
     101        packingPlan, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     102
     103      double moveQuality = quality.Value;
     104
     105      if (MoveQualityParameter.ActualValue == null) MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
     106      else MoveQualityParameter.ActualValue.Value = moveQuality;
     107      return base.Apply();
    74108    }
    75109  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Plugin.cs

    r9473 r9495  
    2626  /// Plugin class for HeuristicLab.Problems.BinPacking plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Problems.BinPacking", "3.3.7.9440")]
     28  [Plugin("HeuristicLab.Problems.BinPacking", "3.3.7.9473")]
    2929  [PluginFile("HeuristicLab.Problems.BinPacking-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Problem/CuboidIdenticalBinPackingProblem.cs

    r9473 r9495  
    4444using HeuristicLab.Problems.Instances;
    4545using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    46 using HeuristicLab.Encodings.PackingEncoding.Potvin;
    4746
    4847namespace HeuristicLab.Problems.BinPacking.Problem {
     
    120119    #region Helpers
    121120    protected override void InitializeDecoder() {
     121      Operators.RemoveAll(op => typeof(I2DOperator).IsAssignableFrom(op.GetType()));
     122
    122123      if (SolutionCreator is PackingSequenceRandomCreator) {
    123124        PackingSolutionDecoder = new ExtremePointPackingSequenceDecoder3D();
     
    126127      } else if (SolutionCreator is MultiComponentVectorRandomCreator) {
    127128        PackingSolutionDecoder = new ExtremePointMultiComponentVectorDecoder3D();
    128       } else if (SolutionCreator is PotvinRandomCreator) {
    129         PackingSolutionDecoder = new ExtremePointPotvinDecoder3D();
    130129      } else {
    131130        string error = "The given problem does not support the selected solution-creator.";
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Problem/RectangularIdenticalBinPackingProblem.cs

    r9440 r9495  
    114114    #region Helpers
    115115    protected override void InitializeDecoder() {
     116      Operators.RemoveAll(op => typeof(I3DOperator).IsAssignableFrom(op.GetType()));
     117
    116118      if (SolutionCreator is PackingSequenceRandomCreator) {
    117119        PackingSolutionDecoder = new ExtremePointPackingSequenceDecoder2D();
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Problem/RegularIdenticalBinPackingProblem.cs

    r9473 r9495  
    4343using HeuristicLab.Problems.Instances;
    4444using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    45 using HeuristicLab.Encodings.PackingEncoding.Potvin;
    4645
    4746namespace HeuristicLab.Problems.BinPacking.Problem {
     
    6766      set { PackingBinMeasuresParameter.Value = value; }
    6867    }
    69     public IdenticalBinPackingSolutionDecoder<D,B,I, PackingPlan<D,B,I>> PackingSolutionDecoder {
    70       get { return PackingSolutionDecoderParameter.Value as IdenticalBinPackingSolutionDecoder<D, B, I, PackingPlan<D, B, I>>; }
     68    public PackingSolutionDecoder<D,B,I> PackingSolutionDecoder {
     69      get { return PackingSolutionDecoderParameter.Value as PackingSolutionDecoder<D, B, I>; }
    7170      set { PackingSolutionDecoderParameter.Value = value; }
    7271    }
     
    139138        Operators.AddRange(ApplicationManager.Manager.GetInstances<IMultiComponentVectorOperator>());
    140139        InitializeDecoder();
    141       } else if (SolutionCreator.GetType() == typeof(PotvinRandomCreator)) {
    142         Operators.AddRange(ApplicationManager.Manager.GetInstances<IPotvinOperator>());
    143         InitializeDecoder();
    144140      }
    145141    }
Note: See TracChangeset for help on using the changeset viewer.