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