Index: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking3D.cs
===================================================================
--- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking3D.cs	(revision 13607)
+++ 	(revision )
@@ -1,382 +1,0 @@
-﻿#region License Information
-/* HeuristicLab
- * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
- *
- * This file is part of HeuristicLab.
- *
- * HeuristicLab is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * HeuristicLab is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
- */
-#endregion
-
-using System.Collections.Generic;
-using System.Linq;
-using HeuristicLab.Problems.BinPacking.PackingItem;
-using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
-using HeuristicLab.Core;
-using HeuristicLab.Common;
-using HeuristicLab.Problems.BinPacking.Dimensions;
-using HeuristicLab.Problems.BinPacking.PackingBin;
-
-namespace HeuristicLab.Encodings.PackingEncoding.PackingPlan {
-  [Item("BinPacking3D", "Represents a single-bin packing for a 3D bin-packing problem.")]
-  [StorableClass]
-  public class BinPacking3D : BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> {
-
-    public BinPacking3D(CuboidPackingBin binMeasures)
-      : base(binMeasures) {
-      //ExtremePoints = new HashSet<ThreeDimensionalPacking>();
-      ExtremePoints = new SortedSet<ThreeDimensionalPacking>(new EPComparer3D());
-      ExtremePoints.Add(binMeasures.Origin);
-    }
-    [StorableConstructor]
-    protected BinPacking3D(bool deserializing) : base(deserializing) { }
-    protected BinPacking3D(BinPacking3D original, Cloner cloner)
-      : base(original, cloner) {
-      this.depthWasDoubled = original.depthWasDoubled;
-      this.ExtremePoints = new SortedSet<ThreeDimensionalPacking>(original.ExtremePoints, new EPComparer3D());
-    }
-    public override IDeepCloneable Clone(Cloner cloner) {
-      return new BinPacking3D(this, cloner);
-    }
-
-    protected override void GenerateNewExtremePointsForNewItem(CuboidPackingItem newItem, ThreeDimensionalPacking position) {
-      int newWidth = position.Rotated ? newItem.Depth : newItem.Width;
-      int newDepth = position.Rotated ? newItem.Width : newItem.Depth;
-
-      //Find ExtremePoints beginning from sourcepointX
-      var sourcePointX = new ThreeDimensionalPacking(0, position.X + newWidth, position.Y, position.Z);
-      if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height && sourcePointX.Z < BinMeasures.Depth) {
-        //Traversing down the y-axis  
-        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
-        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
-          current = ThreeDimensionalPacking.MoveDown(current);
-        }
-        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
-        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
-          current = ThreeDimensionalPacking.MoveLeft(current);
-        }
-        ExtremePoints.Add(current);
-
-        //Traversing down the z-axis
-        current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
-        while (current.Z > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) {
-          current = ThreeDimensionalPacking.MoveBack(current);
-        }
-        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
-        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
-          current = ThreeDimensionalPacking.MoveDown(current);
-        }
-        ExtremePoints.Add(current);
-      }
-
-
-
-
-      //Find ExtremePoints beginning from sourcepointY
-      var sourcePointY = new ThreeDimensionalPacking(0, position.X, position.Y + newItem.Height, position.Z);
-      if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height && sourcePointY.Z < BinMeasures.Depth) {
-        //Traversing down the x-axis          
-        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
-        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
-          current = ThreeDimensionalPacking.MoveLeft(current);
-        }
-        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
-        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
-          current = ThreeDimensionalPacking.MoveDown(current);
-        }
-        ExtremePoints.Add(current);
-
-        //Traversing down the z-axis                                                                   
-        current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
-        while (current.Z > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) {
-          current = ThreeDimensionalPacking.MoveBack(current);
-        }
-        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
-        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
-          current = ThreeDimensionalPacking.MoveDown(current);
-        }
-        ExtremePoints.Add(current);
-      }
-
-
-
-
-
-      //Find ExtremePoints beginning from sourcepointZ
-      var sourcePointZ = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z + newDepth);
-      if (sourcePointZ.X < BinMeasures.Width && sourcePointZ.Y < BinMeasures.Height && sourcePointZ.Z < BinMeasures.Depth) {
-        //Traversing down the x-axis                                                                             
-        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
-        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
-          current = ThreeDimensionalPacking.MoveLeft(current);
-        }
-        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
-        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
-          current = ThreeDimensionalPacking.MoveDown(current);
-        }
-        ExtremePoints.Add(current);
-
-        //Traversing down the y-axis                                                                     
-        current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
-        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
-          current = ThreeDimensionalPacking.MoveDown(current);
-        }
-        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
-        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
-          current = ThreeDimensionalPacking.MoveLeft(current);
-        }
-        ExtremePoints.Add(current);
-      }
-
-      //ExtremePoints.RemoveWhere(ep => IsPointOccupied (ep));
-
-      //ExtremePoints = new HashSet<ThreeDimensionalPacking>(ExtremePoints.
-      //  OrderBy(ep => ep.Z).
-      //  ThenBy(ep => ep.X).
-      //  ThenBy(ep => ep.Y)//.ThenBy(ep => ShortestPossibleSideFromPoint(ep)) 
-      //  );
-    }
-
-    public override ThreeDimensionalPacking FindExtremePointForItem(CuboidPackingItem measures, bool rotated, bool stackingConstraints) {
-
-      CuboidPackingItem item = new CuboidPackingItem(
-        rotated ? measures.Depth : measures.Width,
-        measures.Height,
-        rotated ? measures.Width : measures.Depth,
-        measures.TargetBin);
-
-      int epIndex = 0;
-      while (epIndex < ExtremePoints.Count && (
-        !IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex))
-        || !IsSupportedByAtLeastOnePoint(item, ExtremePoints.ElementAt(epIndex))
-        || (stackingConstraints && !IsStaticStable(item, ExtremePoints.ElementAt(epIndex)))
-        || (stackingConstraints && !IsWeightSupported(item, ExtremePoints.ElementAt(epIndex)))
-      )) { epIndex++; }
-
-      if (epIndex < ExtremePoints.Count) {
-        var result = ExtremePoints.ElementAt(epIndex);
-        result.Rotated = rotated;
-        return result;
-      }
-      return null;
-    }
-
-    public override ThreeDimensionalPacking FindPositionBySliding(CuboidPackingItem measures, bool rotated) {
-      //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height)
-      ThreeDimensionalPacking currentPosition = new ThreeDimensionalPacking(0,
-        BinMeasures.Width - (rotated ? measures.Depth : measures.Width),
-        BinMeasures.Height - measures.Height,
-        BinMeasures.Depth - (rotated ? measures.Width : measures.Depth), rotated);
-      //Slide the item as far as possible to the bottom
-      while (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveDown(currentPosition))
-        || IsPositionFeasible(measures, ThreeDimensionalPacking.MoveLeft(currentPosition))
-        || IsPositionFeasible(measures, ThreeDimensionalPacking.MoveBack(currentPosition))) {
-        //Slide the item as far as possible to the left
-        while (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveLeft(currentPosition))
-      || IsPositionFeasible(measures, ThreeDimensionalPacking.MoveBack(currentPosition))) {
-          //Slide the item as far as possible to the back
-          while (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveBack(currentPosition))) {
-            currentPosition = ThreeDimensionalPacking.MoveBack(currentPosition);
-          }
-          if (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveLeft(currentPosition)))
-            currentPosition = ThreeDimensionalPacking.MoveLeft(currentPosition);
-        }
-        if (IsPositionFeasible(measures, ThreeDimensionalPacking.MoveDown(currentPosition)))
-          currentPosition = ThreeDimensionalPacking.MoveDown(currentPosition);
-      }
-
-      return IsPositionFeasible(measures, currentPosition) ? currentPosition : null;
-    }
-
-    public override void SlidingBasedPacking(ref List<int> sequence, ItemList<CuboidPackingItem> itemMeasures) {
-      var temp = new List<int>(sequence);
-      for (int i = 0; i < temp.Count; i++) {
-        var item = itemMeasures[temp[i]];
-        var position = FindPositionBySliding(item, false);
-        if (position != null) {
-          PackItem(temp[i], item, position);
-          sequence.Remove(temp[i]);
-        }
-      }
-    }
-    public override void SlidingBasedPacking(ref List<int> sequence, ItemList<CuboidPackingItem> itemMeasures, Dictionary<int, bool> rotationArray) {
-      var temp = new List<int>(sequence);
-      for (int i = 0; i < temp.Count; i++) {
-        var item = itemMeasures[temp[i]];
-        var position = FindPositionBySliding(item, rotationArray[i]);
-        if (position != null) {
-          PackItem(temp[i], item, position);
-          sequence.Remove(temp[i]);
-        }
-      }
-    }
-    public override void ExtremePointBasedPacking(ref List<int> sequence, ItemList<CuboidPackingItem> itemMeasures, bool stackingConstraints) {
-      var temp = new List<int>(sequence);
-      foreach (int itemID in temp) {
-        var item = itemMeasures[itemID];
-        var positionFound = FindExtremePointForItem(item, false, stackingConstraints);
-        if (positionFound != null) {
-          PackItem(itemID, item, positionFound);
-          sequence.Remove(itemID);
-        }
-      }
-    }
-    public override void ExtremePointBasedPacking(ref List<int> sequence, ItemList<CuboidPackingItem> itemMeasures, bool stackingConstraints, Dictionary<int, bool> rotationArray) {
-      var temp = new List<int>(sequence);
-      foreach (int itemID in temp) {
-        var item = itemMeasures[itemID];
-        var positionFound = FindExtremePointForItem(item, rotationArray[itemID], stackingConstraints);
-        if (positionFound != null) {
-          PackItem(itemID, item, positionFound);
-          sequence.Remove(itemID);
-        }
-      }
-    }
-
-    public override int ShortestPossibleSideFromPoint(ThreeDimensionalPacking position) {
-
-      int shortestSide = int.MaxValue;
-      int width = BinMeasures.Width;
-      int height = BinMeasures.Height;
-      int depth = BinMeasures.Depth;
-
-      if (position.X >= width || position.Y >= height || position.Z >= depth)
-        return shortestSide;
-
-      ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z);
-      while (current.X < width && IsPointOccupied(current)) { current = ThreeDimensionalPacking.MoveRight(current); }
-      if (current.X - position.X < shortestSide)
-        shortestSide = current.X - position.X;
-
-
-      current = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z);
-      while (current.Y < height && IsPointOccupied(current)) { current = ThreeDimensionalPacking.MoveUp(current); }
-      if (current.Y - position.Y < shortestSide)
-        shortestSide = current.Y - position.Y;
-
-
-      current = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z);
-      while (current.Z < depth && IsPointOccupied(current)) { current = ThreeDimensionalPacking.MoveFront(current); }
-      if (current.Z - position.Z < shortestSide)
-        shortestSide = current.Z - position.Z;
-
-      return shortestSide;
-    }
-    public override bool IsStaticStable(CuboidPackingItem item, ThreeDimensionalPacking position) {
-      //Static stability is given, if item is placed on the ground
-      if (position.Y == 0)
-        return true;
-
-      if (IsPointOccupied(new ThreeDimensionalPacking(0, position.X, position.Y - 1, position.Z))
-        && IsPointOccupied(new ThreeDimensionalPacking(0, position.X + item.Width - 1, position.Y - 1, position.Z))
-        && IsPointOccupied(new ThreeDimensionalPacking(0, position.X, position.Y - 1, position.Z + item.Depth - 1))
-        && IsPointOccupied(new ThreeDimensionalPacking(0, position.X + item.Width - 1, position.Y - 1, position.Z + item.Depth - 1)))
-        return true;
-
-
-      //if (occupiedPoints[position.X, position.Y - 1, position.Z] != -1
-      //  && occupiedPoints[position.X + item.Width - 1, position.Y - 1, position.Z] != -1
-      //  && occupiedPoints[position.X, position.Y - 1, position.Z + item.Depth - 1] != -1
-      //  && occupiedPoints[position.X + item.Width - 1, position.Y - 1, position.Z + item.Depth - 1] != -1)
-      //  return true;
-
-      //int groundCount = 0;
-      //for (int x = ep.X; x < ep.X + item.Width - 1; x++) {
-      //  for (int z = ep.Z; z < ep.Z + item.Depth - 1; z++) {
-      //    if (occupiedPoints[x,ep.Y-1, z] != -1)                                                     
-      //      groundCount++;
-      //  }
-      //}
-      //double stableGround = (double)(groundCount) / (double)(item.Width * item.Depth);
-      //if (stableGround > 0.75)
-      //  return true;
-
-      return false;
-    }
-
-    [Storable]
-    private bool depthWasDoubled = false;
-    public void DoubleDepth() {
-      if (!depthWasDoubled) {
-        var oldDepth = BinMeasures.Depth;
-        BinMeasures.Depth = BinMeasures.Depth * 2;
-        //OccupiedPoints.ChangeBinMeasures(BinMeasures);
-        depthWasDoubled = true;
-      }
-    }
-
-    public bool IsSupportedByAtLeastOnePoint(CuboidPackingItem item, ThreeDimensionalPacking position) {
-      if (position.Y == 0)
-        return true;
-
-      int y = position.Y - 1;
-      for (int x = position.X; x < position.X + item.Width; x++)
-        for (int z = position.Z; z < position.Z + item.Depth; z++)
-          if (IsPointOccupied(new ThreeDimensionalPacking(0, x, y, z)))
-            return true;
-
-      return false;
-    }
-    public bool IsWeightSupported(CuboidPackingItem item, ThreeDimensionalPacking ep) {
-      if (ep.Y == 0)
-        return true;
-
-      if (ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)
-        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z))].SupportsStacking(item)
-        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item)
-        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item))
-        return true;
-
-      return false;
-    }
-
-
-    protected override void InitializeOccupationLayers() {
-      for (int i = 0; i * 10 <= BinMeasures.Depth; i += 1) {
-        OccupationLayers[i] = new List<int>();
-      }
-    }
-    protected override void AddNewItemToOccupationLayers(int itemID, CuboidPackingItem measures, ThreeDimensionalPacking position) {
-      int z1 = position.Z / 10;
-      int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;
-
-      for (int i = z1; i <= z2; i++)
-        OccupationLayers[i].Add(itemID);
-    }
-    protected override List<int> GetLayerItemIDs(ThreeDimensionalPacking position) {
-      return OccupationLayers[position.Z / 10];
-    }
-    protected override List<int> GetLayerItemIDs(CuboidPackingItem measures, ThreeDimensionalPacking position) {
-      List<int> result = new List<int>();
-      int z1 = position.Z / 10;
-      int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;
-
-      for (int i = z1; i <= z2; i++)
-        result.AddRange(OccupationLayers[i]);
-
-      return result;
-    }
-  }
-  public class EPComparer3D : IComparer<ThreeDimensionalPacking> {
-    public int Compare(ThreeDimensionalPacking a, ThreeDimensionalPacking b) {
-      int result = a.Z.CompareTo(b.Z);
-      if (result == 0)
-        result = a.X.CompareTo(b.X);
-      if (result == 0)
-        result = a.Y.CompareTo(b.Y);
-
-      return result;
-    }
-  }
-}
