Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/RegularSimpleRotationIdenticalBinPackingPlanEvaluator.cs @ 14048

Last change on this file since 14048 was 14048, checked in by gkronber, 8 years ago

#1966: renamed *PackingDimension -> PackingPosition

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Core;
23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24using HeuristicLab.Common;
25using HeuristicLab.Parameters;
26using HeuristicLab.Collections;
27
28namespace HeuristicLab.Problems.BinPacking {
29  [Item("Regular Simple-Rotation Identical-Bin Packingplan Evaluator", "Represents a evaluator class for bin-packing problems using regular shapes and only simple rotations.")]
30  [StorableClass]
31  public abstract class RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I> : PackingPlanEvaluator<D, B, I>
32    where D : class, IPackingPosition
33    where B : PackingShape<D>
34    where I : PackingShape<D>, IPackingItem {
35
36    #region Parameter Properties
37    public ILookupParameter<ItemList<I>> PackingItemMeasuresParameter {
38      get { return (ILookupParameter<ItemList<I>>)Parameters["PackingItemMeasures"]; }
39    }
40    public ILookupParameter<B> PackingBinMeasuresParameter {
41      get { return (ILookupParameter<B>)Parameters["PackingBinMeasures"]; }
42    }
43    #endregion
44
45    [StorableConstructor]
46    protected RegularSimpleRotationIdenticalBinPackingPlanEvaluator(bool deserializing) : base(deserializing) { }
47    protected RegularSimpleRotationIdenticalBinPackingPlanEvaluator(RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I> original, Cloner cloner)
48      : base(original, cloner) {
49    }
50    public RegularSimpleRotationIdenticalBinPackingPlanEvaluator()
51      : base() {
52      Parameters.Add(new LookupParameter<ItemList<I>>("PackingItemMeasures", "Packing-item data taken from the bin-packing problem-instance."));
53      Parameters.Add(new LookupParameter<B>("PackingBinMeasures", "Packing-bin data taken from the bin-packing problem-instance."));
54    }
55
56
57
58
59    protected bool HasOverlappingOrNotContainedItems(ObservableDictionary<int, D> positions, B binMeasure, ItemList<I> itemMeasures, int nrOfBins) {
60      //TODO: Optimize performance by removing unnecessary allocations..
61      for (int i = 0; i < itemMeasures.Count; i++) {
62        I packingItem = itemMeasures[i];
63        D currentPosition = positions[i];
64        if (!binMeasure.Encloses(currentPosition, packingItem))
65          return true;
66
67        for (int j = 0; j < itemMeasures.Count; j++) {
68          D checkedPosition = positions[j];
69          if (i != j && currentPosition.AssignedBin == checkedPosition.AssignedBin) {
70            I checkedItem = itemMeasures[j];
71            if (packingItem.Overlaps(currentPosition, checkedPosition, checkedItem))
72              return true;
73          }
74        }
75
76      }
77
78      return false;
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.