#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using HeuristicLab.Core;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
using HeuristicLab.Common;
using HeuristicLab.Parameters;
using HeuristicLab.Collections;
namespace HeuristicLab.Problems.BinPacking {
[Item("Regular Simple-Rotation Identical-Bin Packingplan Evaluator", "Represents a evaluator class for bin-packing problems using regular shapes and only simple rotations.")]
[StorableClass]
public abstract class RegularSimpleRotationIdenticalBinPackingPlanEvaluator : PackingPlanEvaluator
where D : class, IPackingPosition
where B : PackingShape
where I : PackingShape, IPackingItem {
#region Parameter Properties
public ILookupParameter> PackingItemMeasuresParameter {
get { return (ILookupParameter>)Parameters["PackingItemMeasures"]; }
}
public ILookupParameter PackingBinMeasuresParameter {
get { return (ILookupParameter)Parameters["PackingBinMeasures"]; }
}
#endregion
[StorableConstructor]
protected RegularSimpleRotationIdenticalBinPackingPlanEvaluator(bool deserializing) : base(deserializing) { }
protected RegularSimpleRotationIdenticalBinPackingPlanEvaluator(RegularSimpleRotationIdenticalBinPackingPlanEvaluator original, Cloner cloner)
: base(original, cloner) {
}
public RegularSimpleRotationIdenticalBinPackingPlanEvaluator()
: base() {
Parameters.Add(new LookupParameter>("PackingItemMeasures", "Packing-item data taken from the bin-packing problem-instance."));
Parameters.Add(new LookupParameter("PackingBinMeasures", "Packing-bin data taken from the bin-packing problem-instance."));
}
protected bool HasOverlappingOrNotContainedItems(ObservableDictionary positions, B binMeasure, ItemList itemMeasures, int nrOfBins) {
//TODO: Optimize performance by removing unnecessary allocations..
for (int i = 0; i < itemMeasures.Count; i++) {
I packingItem = itemMeasures[i];
D currentPosition = positions[i];
if (!binMeasure.Encloses(currentPosition, packingItem))
return true;
for (int j = 0; j < itemMeasures.Count; j++) {
D checkedPosition = positions[j];
if (i != j && currentPosition.AssignedBin == checkedPosition.AssignedBin) {
I checkedItem = itemMeasures[j];
if (packingItem.Overlaps(currentPosition, checkedPosition, checkedItem))
return true;
}
}
}
return false;
}
}
}