#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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 System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Core; using HeuristicLab.Common; using HeuristicLab.Collections; namespace HeuristicLab.Problems.BinPacking { [Item("BinPacking", "Represents a single-bin packing for a bin-packing problem.")] [StorableClass] public abstract class BinPacking : Item where TPos : class, IPackingPosition where TBin : PackingShape where TItem : PackingShape { #region Properties [Storable] //key = item id public ObservableDictionary Positions { get; private set; } [Storable] //key = item id public ObservableDictionary Items { get; private set; } [Storable] public TBin BinShape { get; private set; } public double PackingDensity { get { double result = 0; foreach (var entry in Items) result += entry.Value.Volume; result /= BinShape.Volume; return result; } } public int FreeVolume { get { return BinShape.Volume - Items.Sum(x => x.Value.Volume); } } #endregion Properties protected BinPacking(TBin binShape) : base() { Positions = new ObservableDictionary(); Items = new ObservableDictionary(); BinShape = (TBin)binShape.Clone(); } [StorableConstructor] protected BinPacking(bool deserializing) : base(deserializing) { } protected BinPacking(BinPacking original, Cloner cloner) : base(original, cloner) { this.Positions = new ObservableDictionary(); foreach (var kvp in original.Positions) { Positions.Add(kvp.Key, cloner.Clone(kvp.Value)); } this.Items = new ObservableDictionary(); foreach (var kvp in original.Items) { Items.Add(kvp.Key, cloner.Clone(kvp.Value)); } this.BinShape = (TBin)original.BinShape.Clone(cloner); } /// /// Generate new extreme points for a given item /// /// /// protected abstract void GenerateNewExtremePointsForNewItem(TItem item, TPos position); /// /// Packs an item into the bin packing /// /// /// /// public abstract void PackItem(int itemID, TItem item, TPos position); /// /// Checks if the given position is feasible for the given item /// /// /// /// /// Returns true if the given position is feasible for the given item public abstract bool IsPositionFeasible(TItem item, TPos position, bool stackingConstraints); /// /// Checks if the given item is static stable on the given position /// /// Item /// Position of the item /// Returns true if the given item is static stable on the given position public abstract bool IsStaticStable(TItem measures, TPos position); } }