Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingShape.cs @ 14048

Last change on this file since 14048 was 14048, checked in by gkronber, 8 years ago

#1966: renamed *PackingDimension -> PackingPosition

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