1  #region License Information


2  /* HeuristicLab


3  * Copyright (C) 20022012 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 


22  using System;


23  using System.Collections.Generic;


24  using System.Linq;


25  using System.Text;


26  using HeuristicLab.Core;


27  using HeuristicLab.Problems.BinPacking.Interfaces;


28  using HeuristicLab.Operators;


29  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;


30  using HeuristicLab.Common;


31  using HeuristicLab.Parameters;


32  using HeuristicLab.Data;


33  using HeuristicLab.Problems.BinPacking.PackingPlans;


34  using HeuristicLab.Problems.BinPacking.Shapes;


35  using HeuristicLab.Collections;


36 


37  namespace HeuristicLab.Problems.BinPacking.Evaluators {


38  [Item("Regular SimpleRotation IdenticalBin Packingplan Evaluator", "Represents a evaluator class for binpacking problems using regular shapes and only simple rotations.")]


39  [StorableClass]


40  public abstract class RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I> : PackingPlanEvaluator<D, B, I>


41  where D : class, IPackingDimensions


42  where B : PackingShape<D>, IPackingBin, IRegularPackingShape


43  where I : PackingShape<D>, IPackingItem, IRegularPackingShape {


44 


45  #region Parameter Properties


46  public ILookupParameter<ItemList<I>> PackingItemMeasuresParameter {


47  get { return (ILookupParameter<ItemList<I>>)Parameters["PackingItemMeasures"]; }


48  }


49  public ILookupParameter<B> PackingBinMeasuresParameter {


50  get { return (ILookupParameter<B>)Parameters["PackingBinMeasures"]; }


51  }


52  #endregion


53 


54  [StorableConstructor]


55  protected RegularSimpleRotationIdenticalBinPackingPlanEvaluator(bool deserializing) : base(deserializing) { }


56  protected RegularSimpleRotationIdenticalBinPackingPlanEvaluator(RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D,B,I> original, Cloner cloner)


57  : base(original, cloner) {


58  }


59  public RegularSimpleRotationIdenticalBinPackingPlanEvaluator()


60  : base() {


61  Parameters.Add(new LookupParameter<ItemList<I>>("PackingItemMeasures", "Packingitem data taken from the binpacking probleminstance."));


62  Parameters.Add(new LookupParameter<B>("PackingBinMeasures", "Packingbin data taken from the binpacking probleminstance."));


63  }


64 


65 


66 


67 


68  protected bool HasOverlappingOrNotContainedItems(ObservableDictionary<int, D> positions, B binMeasure, ItemList<I> itemMeasures, int nrOfBins) {


69  //TODO: Optimize performance by removing unnecessary allocations..


70  for (int i = 0; i < itemMeasures.Count; i++ ) {


71  I packingItem = itemMeasures [i];


72  D currentPosition = positions[i];


73  if (!binMeasure.Encloses(currentPosition, packingItem))


74  return true;


75 


76  for (int j = 0; j < itemMeasures.Count; j++) {


77  D checkedPosition = positions[j];


78  if (i != j && currentPosition.AssignedBin == checkedPosition.AssignedBin) {


79  I checkedItem = itemMeasures[j];


80  if (packingItem.Overlaps(currentPosition, checkedPosition, checkedItem))


81  return true;


82  }


83  }


84 


85  }


86 


87  return false;


88  }


89  }


90  }

