Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/09/13 12:58:39 (11 years ago)
Author:
jhelm
Message:

#1966: Bugfixing; Refactoring; Performancetuning;

File:
1 edited

Legend:

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

    r9598 r9599  
    5454
    5555    [Storable]
    56     public HashSet<D> ExtremePoints { get; protected set; }
     56    //public HashSet<D> ExtremePoints { get; protected set; }
     57    public SortedSet<D> ExtremePoints { get; protected set; }
    5758
    58     //[Storable]
    59     //public OccupiedPoints<D, B, I> OccupiedPoints { get; protected set; }
     59    [Storable]
     60    protected Dictionary<int, List<int>> OccupationLayers { get; set; }
     61
    6062    #endregion Properties
    6163
     
    6466      ItemMeasures = new ObservableDictionary<int, I>();
    6567      BinMeasures = (B)binMeasures.Clone();
    66       ExtremePoints = new HashSet<D>();
    67       ExtremePoints.Add(binMeasures.Origin);
     68      OccupationLayers = new Dictionary<int, List<int>>();
     69      InitializeOccupationLayers();
    6870    }
     71
    6972
    7073    [StorableConstructor]
     
    7578      this.ItemMeasures = new ObservableDictionary<int, I>(original.ItemMeasures);
    7679        this.BinMeasures = (B)original.BinMeasures.Clone(cloner);
     80        this.OccupationLayers = new Dictionary<int, List<int>>(original.OccupationLayers);
    7781    }
    7882   
     
    9195      ItemPositions[itemID] = position;
    9296      ExtremePoints.Remove(position);
    93       GenerateNewExtremePointsForNewItem(measures, position);
     97      foreach (int id in ItemMeasures.Select(x => x.Key))
     98        GenerateNewExtremePointsForNewItem(ItemMeasures[id], ItemPositions[id]);
     99     
     100       
     101      //GenerateNewExtremePointsForNewItem(measures, position);
    94102      //OccupiedPoints.OccupyPoints(measures, position, itemID);
     103
     104      AddNewItemToOccupationLayers(itemID, measures, position);
    95105    }
    96106
     
    107117
    108118    public int PointOccupation(D position) {
    109       foreach (var ipEntry in ItemPositions) {
    110         if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position))
    111           return ipEntry.Key;
     119      //foreach (var ipEntry in ItemPositions) {
     120      //  if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position))
     121      //    return ipEntry.Key;
     122      //}
     123      foreach (var id in GetLayerItemIDs(position)) {
     124        if (ItemMeasures[id].EnclosesPoint(ItemPositions[id], position))
     125          return id;
    112126      }
    113127      return -1;
    114128    }
     129
    115130    public bool IsPointOccupied(D position) {
    116       foreach (var ipEntry in ItemPositions) {
    117         if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position))
     131      //foreach (var ipEntry in ItemPositions) {
     132      //  if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position))
     133      //    return true;
     134      //}     
     135      foreach (var id in GetLayerItemIDs(position)) {
     136        if (ItemMeasures[id].EnclosesPoint(ItemPositions[id], position))
    118137          return true;
    119138      }
    120139      return false;
    121140    }
    122     public bool IsPositionFeasible(I currentItem, D position) {
     141    public bool IsPositionFeasible(I measures, D position) {
    123142      //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the point is supported by something; 3. the item does not collide with another already packed item
    124       if (!BinMeasures.Encloses(position, currentItem))
     143      if (!BinMeasures.Encloses(position, measures))
    125144        return false;
    126145
    127       foreach (var ipEntry in ItemPositions) {
    128         if (ItemMeasures[ipEntry.Key].Overlaps(ipEntry.Value, position, currentItem))
     146      //foreach (var ipEntry in ItemPositions) {
     147      //  if (ItemMeasures[ipEntry.Key].Overlaps(ipEntry.Value, position, measures))
     148      //    return false;
     149      //}
     150      foreach (var id in GetLayerItemIDs(measures, position)) {
     151        if (ItemMeasures[id].Overlaps(ItemPositions[id], position, measures))
    129152          return false;
    130153      }
     
    133156    }
    134157    public abstract int ShortestPossibleSideFromPoint (D position);
    135     public abstract bool IsStaticStable (I item, D position);
     158    public abstract bool IsStaticStable (I measures, D position);
     159
     160
     161    protected abstract void InitializeOccupationLayers();
     162    protected abstract void AddNewItemToOccupationLayers(int itemID, I measures, D position);
     163    protected abstract List<int> GetLayerItemIDs(D position);
     164    protected abstract List<int> GetLayerItemIDs(I measures, D position);
    136165  }   
    137166}
Note: See TracChangeset for help on using the changeset viewer.