[9348] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[13032] | 3 | * Copyright (C) 2002-2015 Joseph Helm and Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[9348] | 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 |
|
---|
[13032] | 22 |
|
---|
[9348] | 23 | using System;
|
---|
[13574] | 24 | using System.Collections.Generic;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Linq;
|
---|
[9348] | 27 | using HeuristicLab.Problems.BinPacking.Interfaces;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 | using HeuristicLab.Common;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.BinPacking.Shapes {
|
---|
| 33 | [Item("PackingShape", "Represents an abstract shape to describe the measures and the positioning of objects related to bin-packing problems.")]
|
---|
| 34 | [StorableClass]
|
---|
[13574] | 35 | public abstract class PackingShape<T> : Item, IPackingShape, IParameterizedItem
|
---|
[13497] | 36 | where T : class, IPackingDimensions {
|
---|
[9348] | 37 | public static Type PositionType {
|
---|
[13497] | 38 | get { return typeof(T); }
|
---|
[9348] | 39 | }
|
---|
| 40 |
|
---|
[13497] | 41 | public abstract bool EnclosesPoint(T myPosition, T checkedPoint);
|
---|
| 42 | public abstract bool Encloses(T checkedPosition, PackingShape<T> checkedShape);
|
---|
| 43 | public abstract bool Overlaps(T myPosition, T checkedPosition, PackingShape<T> checkedShape);
|
---|
[13605] | 44 | public abstract int Volume { get; }
|
---|
[13497] | 45 | public abstract T Origin { get; }
|
---|
[9348] | 46 |
|
---|
[13574] | 47 | protected PackingShape()
|
---|
| 48 | : base() {
|
---|
| 49 | Parameters = new ParameterCollection();
|
---|
[9348] | 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | [StorableConstructor]
|
---|
[13574] | 54 | protected PackingShape(bool deserializing) { }
|
---|
| 55 | protected PackingShape(PackingShape<T> original, Cloner cloner) {
|
---|
| 56 | this.Parameters = new ParameterCollection(original.Parameters.Select(p => cloner.Clone(p)));
|
---|
[9348] | 57 | }
|
---|
[13574] | 58 |
|
---|
| 59 | public virtual void CollectParameterValues(IDictionary<string, IItem> values) {
|
---|
| 60 | foreach (IValueParameter param in Parameters.OfType<IValueParameter>()) {
|
---|
| 61 | var children = GetCollectedValues(param);
|
---|
| 62 | foreach (var c in children) {
|
---|
| 63 | if (String.IsNullOrEmpty(c.Key))
|
---|
| 64 | values.Add(param.Name, c.Value);
|
---|
| 65 | else values.Add(param.Name + "." + c.Key, c.Value);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | protected virtual IEnumerable<KeyValuePair<string, IItem>> GetCollectedValues(IValueParameter param) {
|
---|
| 71 | if (param.Value == null) yield break;
|
---|
| 72 | if (param.GetsCollected) yield return new KeyValuePair<string, IItem>(String.Empty, param.Value);
|
---|
| 73 | var parameterizedItem = param.Value as IParameterizedItem;
|
---|
| 74 | if (parameterizedItem != null) {
|
---|
| 75 | var children = new Dictionary<string, IItem>();
|
---|
| 76 | parameterizedItem.CollectParameterValues(children);
|
---|
| 77 | foreach (var child in children) yield return child;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public IKeyedItemCollection<string, IParameter> Parameters { get; private set; }
|
---|
[9348] | 82 | }
|
---|
| 83 | }
|
---|