Changeset 15241


Ignore:
Timestamp:
07/14/17 00:04:58 (8 days ago)
Author:
abeham
Message:

#2762:

  • Moved initialization / cloning of extreme points list to base class
  • Removed residual space from base class and put it into derived class for 3d bin packing
  • Updated sample
Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.BinPacking/3.3/2D/BinPacking2D.cs

    r15230 r15241  
    3434    public BinPacking2D(PackingShape binShape)
    3535      : base(binShape) {
    36       ExtremePoints = new SortedSet<PackingPosition>();
    3736      ExtremePoints.Add(binShape.Origin);
    3837      InitializeOccupationLayers();
     
    4140    [StorableConstructor]
    4241    protected BinPacking2D(bool deserializing) : base(deserializing) { }
    43     protected BinPacking2D(BinPacking2D original, Cloner cloner)
    44       : base(original, cloner) {
    45       this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)));
    46     }
     42    protected BinPacking2D(BinPacking2D original, Cloner cloner) : base(original, cloner) { }
    4743    public override IDeepCloneable Clone(Cloner cloner) {
    4844      return new BinPacking2D(this, cloner);
  • trunk/sources/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs

    r15230 r15241  
    3333  public class BinPacking3D : BinPacking<PackingPosition, PackingShape, PackingItem> {
    3434
     35    [Storable]
     36    public Dictionary<PackingPosition, Tuple<int, int, int>> ResidualSpace { get; protected set; }
     37
    3538    public BinPacking3D(PackingShape binShape)
    3639      : base(binShape) {
    37       ExtremePoints = new SortedSet<PackingPosition>();
    3840      ResidualSpace = new Dictionary<PackingPosition, Tuple<int,int,int>>();
    3941      AddExtremePoint(binShape.Origin);
     
    4446    protected BinPacking3D(BinPacking3D original, Cloner cloner)
    4547      : base(original, cloner) {
    46       this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)));
    4748      this.ResidualSpace = new Dictionary<PackingPosition, Tuple<int, int, int>>();
    4849      foreach (var o in original.ResidualSpace)
     
    5152    public override IDeepCloneable Clone(Cloner cloner) {
    5253      return new BinPacking3D(this, cloner);
     54    }
     55
     56
     57    [StorableHook(HookType.AfterDeserialization)]
     58    private void AfterDeserialization() {
     59      // BackwardsCompatibility3.3
     60      #region Backwards compatible code, remove with 3.4
     61      if (ResidualSpace == null)
     62        ResidualSpace = new Dictionary<PackingPosition, Tuple<int, int, int>>();
     63      #endregion
     64    }
     65
     66    public override void PackItem(int itemID, PackingItem item, PackingPosition position) {
     67      ResidualSpace.Remove(position);
     68      base.PackItem(itemID, item, position);
    5369    }
    5470
  • trunk/sources/HeuristicLab.Problems.BinPacking/3.3/BinPacking.cs

    r15240 r15241  
    5050    [Storable]
    5151    protected Dictionary<int, List<int>> OccupationLayers { get; set; }
    52 
    53     [Storable]
    54     public Dictionary<TPos, Tuple<int,int,int>> ResidualSpace { get; protected set; }
    55 
     52   
    5653    #endregion Properties
    5754
     
    6562      Items = new ObservableDictionary<int, TItem>();
    6663      BinShape = (TBin)binShape.Clone();
     64      ExtremePoints = new SortedSet<TPos>();
    6765      OccupationLayers = new Dictionary<int, List<int>>();
    6866    }
     
    8179      }
    8280      this.BinShape = (TBin)original.BinShape.Clone(cloner);
     81      this.ExtremePoints = new SortedSet<TPos>(original.ExtremePoints.Select(p => cloner.Clone(p)));
    8382      this.OccupationLayers = new Dictionary<int, List<int>>();
    8483      foreach (var kvp in original.OccupationLayers) {
    8584        OccupationLayers.Add(kvp.Key, new List<int>(kvp.Value));
    8685      }
    87     }
    88 
    89     [StorableHook(HookType.AfterDeserialization)]
    90     private void AfterDeserialization() {
    91       // BackwardsCompatibility3.3
    92       #region Backwards compatible code, remove with 3.4
    93       if (ResidualSpace == null)
    94         ResidualSpace = new Dictionary<TPos, Tuple<int, int, int>>();
    95       #endregion
    9686    }
    9787
     
    110100      Positions[itemID] = position;
    111101      ExtremePoints.Remove(position);
    112       if (ResidualSpace != null) ResidualSpace.Remove(position);
    113102      foreach (int id in Items.Select(x => x.Key))
    114103        GenerateNewExtremePointsForNewItem(Items[id], Positions[id]);
Note: See TracChangeset for help on using the changeset viewer.