Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9599


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

#1966: Bugfixing; Refactoring; Performancetuning;

Location:
branches/HeuristicLab.BinPacking
Files:
13 edited

Legend:

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

    r9598 r9599  
    2626  /// Plugin class for HeuristicLab.Problems.BinPacking.Views plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Problems.BinPacking.Views", "3.3.7.9596")]
     28  [Plugin("HeuristicLab.Problems.BinPacking.Views", "3.3.7.9598")]
    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

    r9598 r9599  
    5454// by using the '*' as shown below:
    5555[assembly: AssemblyVersion("3.3.0.0")]
    56 [assembly: AssemblyFileVersion("3.3.7.9596")]
     56[assembly: AssemblyFileVersion("3.3.7.9598")]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/BinBasedMultiComponentVectorCrossover.cs

    r9596 r9599  
    4646
    4747      int nrOfItems = parent1.NrOfItems;
     48
    4849      bool[] itemAlreadyAssigned = new bool[nrOfItems];
    4950      int nrOfBins = parent1.NrOfBins > parent2.NrOfBins ? parent2.NrOfBins : parent1.NrOfBins;
     
    8283        if (!itemAlreadyAssigned[itemID])
    8384          child.PackingInformations[0].Add(new PackingInformation(itemID, random.Next(2) == 0 ? true : false));
    84       }
    85 
     85      }               
    8686
    8787      return child;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/SequenceBasedMultiComponentVectorCrossover.cs

    r9596 r9599  
    9292          child.PackingInformations[0].Add(new PackingInformation(itemID, random.Next(2) == 0 ? true : false));
    9393      }
    94 
    9594     
    9695      return child;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/ThreeWayMultiComponentVectorManipulator.cs

    r9495 r9599  
    5858        if (individual.NrOfBins > 1)
    5959          do { targetBin = random.Next(individual.NrOfBins); }
    60           while (targetBin != affectedBin);
     60          while (targetBin == affectedBin);
    6161        individual.PackingInformations = SingleGroupingMove.GetVectorAfterMove(individual, affectedBin, affectedIndex, targetBin).PackingInformations;
    6262      }
     
    6767        if (nrOfItems > 1)
    6868          do { targetIndex = random.Next(nrOfItems); }
    69           while (targetIndex != affectedIndex);
     69          while (targetIndex == affectedIndex);
    7070        individual.PackingInformations = ChangePositionMove.GetVectorAfterMove(individual, affectedBin, affectedIndex, targetIndex).PackingInformations;
    7171      }
  • 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}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking2D.cs

    r9598 r9599  
    4141  public class BinPacking2D : BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> {
    4242
    43     public BinPacking2D(RectangularPackingBin binMeasures) : base(binMeasures) {
    44       //OccupiedPoints = new OccupiedPoints2D(binMeasures);
     43    public BinPacking2D(RectangularPackingBin binMeasures)
     44      : base(binMeasures) {
     45      //ExtremePoints = new HashSet<TwoDimensionalPacking>();
     46      ExtremePoints = new SortedSet<TwoDimensionalPacking>(new EPComparer2D());
     47      ExtremePoints.Add(binMeasures.Origin);
    4548    }
    4649    [StorableConstructor]
     
    4851    protected BinPacking2D(BinPacking2D original, Cloner cloner)
    4952      : base(original, cloner) {
     53      this.ExtremePoints = new SortedSet<TwoDimensionalPacking>(original.ExtremePoints, new EPComparer2D());
    5054    }
    5155    public override IDeepCloneable Clone(Cloner cloner) {
     
    6266      if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height) {
    6367        //Traversing down the y-axis       
    64         while (sourcePointX.Y > 0 && (-1).Equals(IsPointOccupied(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y - 1)))) {
     68        while (sourcePointX.Y > 0 && !IsPointOccupied(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y - 1))) {
    6569          sourcePointX.Y--;
    6670        }
     
    7579      if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height) {
    7680        //Traversing down the x-axis 
    77         while (sourcePointY.X > 0 && (-1).Equals(IsPointOccupied(new TwoDimensionalPacking (0,sourcePointY.X - 1, sourcePointY.Y)))) {
     81        while (sourcePointY.X > 0 && !IsPointOccupied(new TwoDimensionalPacking (0,sourcePointY.X - 1, sourcePointY.Y))) {
    7882          sourcePointY.X--;
    7983        }
     
    8185      }
    8286
    83       ExtremePoints = new HashSet<TwoDimensionalPacking>(ExtremePoints.
    84         OrderBy(ep => ep.X).
    85         ThenBy(ep => ep.Y).
    86         ThenBy(ep => ShortestPossibleSideFromPoint(ep)));
     87      //ExtremePoints.RemoveWhere(ep => IsPointOccupied(ep));
     88
     89      //ExtremePoints = new HashSet<TwoDimensionalPacking>(ExtremePoints.
     90      //  OrderBy(ep => ep.X).
     91      //  ThenBy(ep => ep.Y).
     92      //  ThenBy(ep => ShortestPossibleSideFromPoint(ep)));
    8793    }
    8894
     
    190196      throw new NotImplementedException();
    191197    }
     198
     199
     200    protected override void InitializeOccupationLayers() {
     201      for (int i = 0; i*10 <= BinMeasures.Width; i += 1 ) {
     202        OccupationLayers[i] = new List<int>();
     203      }
     204    }
     205    protected override void AddNewItemToOccupationLayers(int itemID, RectangularPackingItem measures, TwoDimensionalPacking position) {
     206      int x1 = position.X / 10;
     207      int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;
     208
     209      for (int i = x1; i <= x2; i++)
     210        OccupationLayers[i].Add(itemID);
     211    }
     212    protected override List<int> GetLayerItemIDs(TwoDimensionalPacking position) {
     213      return OccupationLayers[position.X / 10];
     214    }
     215    protected override List<int> GetLayerItemIDs(RectangularPackingItem measures, TwoDimensionalPacking position) {
     216      List<int> result = new List<int> ();
     217      int x1 = position.X / 10;
     218      int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;
     219
     220      for (int i = x1; i <= x2; i++)
     221        result.AddRange(OccupationLayers[i]);
     222
     223      return result;
     224    }
     225  }
     226  public class EPComparer2D : IComparer<TwoDimensionalPacking> {
     227    public int Compare(TwoDimensionalPacking a, TwoDimensionalPacking b) {
     228      int result = a.X.CompareTo(b.X);
     229      if (result == 0)
     230        result = a.Y.CompareTo(b.Y);
     231
     232      return result;
     233    }
    192234  }
    193235}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking3D.cs

    r9598 r9599  
    4141  public class BinPacking3D : BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> {
    4242
    43     public BinPacking3D(CuboidPackingBin binMeasures) : base(binMeasures) {
    44       //OccupiedPoints = new OccupiedPoints3D(binMeasures);
     43    public BinPacking3D(CuboidPackingBin binMeasures)
     44      : base(binMeasures) {
     45      //ExtremePoints = new HashSet<ThreeDimensionalPacking>();
     46      ExtremePoints = new SortedSet<ThreeDimensionalPacking>(new EPComparer3D());
     47      ExtremePoints.Add(binMeasures.Origin);
    4548    }
    4649    [StorableConstructor]
     
    4851    protected BinPacking3D(BinPacking3D original, Cloner cloner)
    4952      : base(original, cloner) {
    50         this.depthWasDoubled = original.depthWasDoubled;
     53      this.depthWasDoubled = original.depthWasDoubled;
     54      this.ExtremePoints = new SortedSet<ThreeDimensionalPacking>(original.ExtremePoints, new EPComparer3D());
    5155    }
    5256    public override IDeepCloneable Clone(Cloner cloner) {
     
    6367        //Traversing down the y-axis           
    6468        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
    65         while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown (current))) {
    66           current = ThreeDimensionalPacking.MoveDown(current);
    67         }
    68         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    69         while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     69        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown (current))) {
     70          current = ThreeDimensionalPacking.MoveDown(current);
     71        }
     72        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     73        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    7074          current = ThreeDimensionalPacking.MoveLeft(current);
    7175        }
     
    7478        //Traversing down the z-axis                 
    7579        current = new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z);
    76         while (current.Z > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveBack (current))) {
     80        while (current.Z > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveBack (current))) {
    7781          current = ThreeDimensionalPacking.MoveBack(current);
    7882        }
    7983        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    80         while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     84        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    8185          current = ThreeDimensionalPacking.MoveDown(current);
    8286        }
     
    9296        //Traversing down the x-axis         
    9397        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
    94         while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     98        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    9599          current = ThreeDimensionalPacking.MoveLeft(current);
    96100        }
    97101        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    98         while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     102        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    99103          current = ThreeDimensionalPacking.MoveDown(current);
    100104        }
     
    103107        //Traversing down the z-axis                                                                   
    104108        current = new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z);
    105         while (current.Z > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) {
     109        while (current.Z > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveBack(current))) {
    106110          current = ThreeDimensionalPacking.MoveBack(current);
    107111        }
    108112        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    109         while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     113        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    110114          current = ThreeDimensionalPacking.MoveDown(current);
    111115        }
     
    122126        //Traversing down the x-axis                                                                             
    123127        ThreeDimensionalPacking current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
    124         while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     128        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    125129          current = ThreeDimensionalPacking.MoveLeft(current);
    126130        }
    127131        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    128         while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     132        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    129133          current = ThreeDimensionalPacking.MoveDown(current);
    130134        }
     
    133137        //Traversing down the y-axis                                                                     
    134138        current = new ThreeDimensionalPacking(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z);
    135         while (current.Y > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
    136           current = ThreeDimensionalPacking.MoveDown(current);
    137         }
    138         ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
    139         while (current.X > 0 && IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
     139        while (current.Y > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveDown(current))) {
     140          current = ThreeDimensionalPacking.MoveDown(current);
     141        }
     142        ExtremePoints.Add((ThreeDimensionalPacking)current.Clone());
     143        while (current.X > 0 && !IsPointOccupied(ThreeDimensionalPacking.MoveLeft(current))) {
    140144          current = ThreeDimensionalPacking.MoveLeft(current);
    141145        }
     
    143147      }
    144148
    145       ExtremePoints = new HashSet<ThreeDimensionalPacking>(ExtremePoints.
    146         OrderBy(ep => ep.Z).
    147         ThenBy(ep => ep.X).
    148         ThenBy(ep => ep.Y)//.ThenBy(ep => ShortestPossibleSideFromPoint(ep))
    149         );
     149      //ExtremePoints.RemoveWhere(ep => IsPointOccupied (ep));
     150
     151      //ExtremePoints = new HashSet<ThreeDimensionalPacking>(ExtremePoints.
     152      //  OrderBy(ep => ep.Z).
     153      //  ThenBy(ep => ep.X).
     154      //  ThenBy(ep => ep.Y)//.ThenBy(ep => ShortestPossibleSideFromPoint(ep))
     155      //  );
    150156    }
    151157
     
    281287
    282288      if (IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z))
    283         && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width, position.Y - 1, position.Z))
    284         && IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z + item.Depth))
    285         && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width, position.Y - 1, position.Z + item.Depth)))
     289        && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width-1, position.Y - 1, position.Z))
     290        && IsPointOccupied (new ThreeDimensionalPacking (0, position.X, position.Y - 1, position.Z + item.Depth-1))
     291        && IsPointOccupied (new ThreeDimensionalPacking (0, position.X + item.Width-1, position.Y - 1, position.Z + item.Depth-1)))
    286292        return true;
    287293
     
    307313    }
    308314
    309 
    310315    [Storable]
    311316    private bool depthWasDoubled = false;
     
    336341
    337342      if (ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)
    338         && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width, ep.Y - 1, ep.Z))].SupportsStacking(item)
    339         && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z + item.Depth))].SupportsStacking(item)
    340         && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width, ep.Y - 1, ep.Z + item.Depth))].SupportsStacking(item))
     343        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width-1, ep.Y - 1, ep.Z))].SupportsStacking(item)
     344        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X, ep.Y - 1, ep.Z + item.Depth-1))].SupportsStacking(item)
     345        && ItemMeasures[PointOccupation(new ThreeDimensionalPacking(0, ep.X + item.Width-1, ep.Y - 1, ep.Z + item.Depth-1))].SupportsStacking(item))
    341346        return true;
    342347
    343348      return false;
     349    }   
     350   
     351
     352    protected override void InitializeOccupationLayers() {
     353      for (int i = 0; i*10 <= BinMeasures.Depth; i += 1) {
     354        OccupationLayers[i] = new List<int>();
     355      }
     356    }
     357    protected override void AddNewItemToOccupationLayers(int itemID, CuboidPackingItem measures, ThreeDimensionalPacking position) {
     358      int z1 = position.Z / 10;
     359      int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;
     360
     361      for (int i = z1; i <= z2; i++)
     362        OccupationLayers[i].Add(itemID);
     363    }
     364    protected override List<int> GetLayerItemIDs(ThreeDimensionalPacking position) {
     365      return OccupationLayers[position.Z / 10];
     366    }
     367    protected override List<int> GetLayerItemIDs(CuboidPackingItem measures, ThreeDimensionalPacking position) {
     368      List<int> result = new List<int>();
     369      int z1 = position.Z / 10;
     370      int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;
     371
     372      for (int i = z1; i <= z2; i++)
     373        result.AddRange(OccupationLayers[i]);
     374
     375      return result;
     376    }
     377  }
     378  public class EPComparer3D : IComparer<ThreeDimensionalPacking> {
     379    public int Compare(ThreeDimensionalPacking a, ThreeDimensionalPacking b) {
     380        int result = a.Z.CompareTo (b.Z);
     381      if (result == 0)
     382        result = a.X.CompareTo (b.X);
     383      if (result == 0)
     384        result = a.Y.CompareTo(b.Y);
     385
     386      return result;
    344387    }
    345388  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/PackingPlan.cs

    r9596 r9599  
    3838using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
    3939using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
     40using HeuristicLab.Encodings.IntegerVectorEncoding;
    4041
    4142namespace HeuristicLab.Encodings.PackingEncoding.PackingPlan {
     
    128129            bp.PackItem(id, itemMeasures[id], position);
    129130            remainingIDs.Remove(id);
     131            break;
    130132          }
    131133        }
     
    142144      }
    143145      UpdateBinPackings();
     146
     147      var newSolution = new ObservableDictionary<int,ItemList<PackingInformation>> ();
     148      foreach (var bp in BinPackings) {
     149        int binIndex = newSolution.Count;
     150        newSolution[binIndex] = new ItemList<PackingInformation>();
     151        foreach (var entry in bp.ItemPositions)
     152          newSolution[binIndex].Add(new PackingInformation (entry.Key, entry.Value.Rotated));
     153      }
     154      solution.PackingInformations = newSolution;
    144155    }
    145156    public void Pack(GroupingVectorEncoding solution, ItemList<I> itemMeasures) {
     
    167178            bp.PackItem(id, itemMeasures[id], position);
    168179            remainingIDs.Remove(id);
     180            break;
    169181          }
    170182        }
     
    181193      }
    182194      UpdateBinPackings();
     195
     196      var newSolution = new int[solution.GroupingVector.Length];
     197      int binIndex = 0;
     198      foreach (var bp in BinPackings) {
     199        foreach (var entry in bp.ItemPositions)
     200          newSolution[entry.Key] = binIndex;
     201        binIndex++;
     202      }
     203      solution.GroupingVector = new IntegerVector (newSolution);
    183204    }
    184205    public void Pack(PackingSequenceEncoding solution, ItemList<I> itemMeasures) {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Interfaces/IPackingDimensions.cs

    r9348 r9599  
    2929  public interface IPackingDimensions : IItem {
    3030    Int32 AssignedBin { get; }
     31    bool Rotated { get; }
    3132  }
    3233}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Plugin.cs

    r9598 r9599  
    2626  /// Plugin class for HeuristicLab.Problems.BinPacking plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Problems.BinPacking", "3.3.7.9596")]
     28  [Plugin("HeuristicLab.Problems.BinPacking", "3.3.7.9598")]
    2929  [PluginFile("HeuristicLab.Problems.BinPacking-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/CuboidPackingShape.cs

    r9596 r9599  
    5757
    5858    public override bool EnclosesPoint(ThreeDimensionalPacking myPosition, ThreeDimensionalPacking checkedPoint) {
    59       var c = new CuboidDiagonal(myPosition, this);
    60       return (c.x1 <= checkedPoint.X &&
    61                 c.x2 >= checkedPoint.X &&
    62                 c.y1 <= checkedPoint.Y &&
    63                 c.y2 >= checkedPoint.Y &&
    64                 c.z1 <= checkedPoint.Z &&
    65                 c.z2 >= checkedPoint.Z);
     59      return (myPosition.X <= checkedPoint.X &&
     60                (myPosition.X + (myPosition.Rotated ? Depth : Width) - 1) >= checkedPoint.X &&
     61                myPosition.Y <= checkedPoint.Y &&
     62                (myPosition.Y + Height - 1) >= checkedPoint.Y &&
     63                myPosition.Z <= checkedPoint.Z &&
     64                (myPosition.Z + (myPosition.Rotated ? Width : Depth) - 1) >= checkedPoint.Z);
    6665    }
    6766    public override bool Encloses(ThreeDimensionalPacking checkedPosition, PackingShape<ThreeDimensionalPacking> checkedShape) {
     
    8786    }
    8887    private bool Overlaps(CuboidDiagonal c1, CuboidDiagonal c2) {
    89       return !(c1.x1 >= c2.x2 ||
    90                c1.y1 >= c2.y2 || 
    91                c1.z1 >= c2.z2 ||
    92                c1.x2 <= c2.x1 ||
    93                c1.y2 <= c2.y1 ||
    94                c1.z2 <= c2.z1);
     88      return !(c1.x1 > c2.x2 ||
     89               c1.y1 > c2.y2 || 
     90               c1.z1 > c2.z2 ||
     91               c1.x2 < c2.x1 ||
     92               c1.y2 < c2.y1 ||
     93               c1.z2 < c2.z1);
    9594    }
    9695
     
    175174        y1 = myPosition.Y;
    176175        z1 = myPosition.Z;
    177         x2 = myPosition.X + (myPosition.Rotated ? myShape.Depth : myShape.Width);
    178         y2 = myPosition.Y + myShape.Height;
    179         z2 = myPosition.Z + (myPosition.Rotated ? myShape.Width : myShape.Depth);
     176        x2 = myPosition.X + (myPosition.Rotated ? myShape.Depth : myShape.Width) - 1;
     177        y2 = myPosition.Y + myShape.Height - 1;
     178        z2 = myPosition.Z + (myPosition.Rotated ? myShape.Width : myShape.Depth) - 1;
    180179      }
    181180    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs

    r9596 r9599  
    5252
    5353    public override bool EnclosesPoint(TwoDimensionalPacking myPosition, TwoDimensionalPacking checkedPoint) {
    54       var r = new RectangleDiagonal(myPosition, this);
    55       return (r.x1 <= checkedPoint.X &&
    56                 r.x2 >= checkedPoint.X &&
    57                 r.y1 <= checkedPoint.Y &&
    58                 r.y2 >= checkedPoint.Y);
     54      return (myPosition.X <= checkedPoint.X &&
     55                (myPosition.X + (myPosition.Rotated ? Height : Width) - 1) >= checkedPoint.X &&
     56                myPosition.Y <= checkedPoint.Y &&
     57                (myPosition.Y + (myPosition.Rotated ? Width : Height) - 1) >= checkedPoint.Y);
    5958    }
    6059    public override bool Encloses(TwoDimensionalPacking checkedPosition, PackingShape<TwoDimensionalPacking> checkedShape) {
     
    7877    }
    7978    private bool Overlaps(RectangleDiagonal r1, RectangleDiagonal r2) {
    80       return !(r1.x1 >= r2.x2 ||
    81                r1.y1 >= r2.y2 ||
    82                r1.x2 <= r2.x1 ||
    83                r1.y2 <= r2.y1);
     79      return !(r1.x1 > r2.x2 ||
     80               r1.y1 > r2.y2 ||
     81               r1.x2 < r2.x1 ||
     82               r1.y2 < r2.y1);
    8483    }
    8584
     
    150149        x1 = myPosition.X;
    151150        y1 = myPosition.Y;
    152         x2 = myPosition.X + (myPosition.Rotated ? myShape.Height : myShape.Width);
    153         y2 = myPosition.Y + (myPosition.Rotated ? myShape.Width : myShape.Height);
     151        x2 = myPosition.X + (myPosition.Rotated ? myShape.Height : myShape.Width) - 1;
     152        y2 = myPosition.Y + (myPosition.Rotated ? myShape.Width : myShape.Height) - 1;
    154153      }
    155154    }
Note: See TracChangeset for help on using the changeset viewer.