[14162] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 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 | using System;
|
---|
| 23 | using System.Linq;
|
---|
[16720] | 24 | using HEAL.Attic;
|
---|
[14162] | 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Collections;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.BinPacking {
|
---|
[16720] | 31 | [StorableType("2E5A4B2A-EB2B-49F8-9BE8-45DA1A421F3E")]
|
---|
[14162] | 32 | public abstract class PackingPlan<D, B, I> : Item
|
---|
| 33 | where D : class, IPackingPosition
|
---|
| 34 | where B : PackingShape<D>
|
---|
| 35 | where I : PackingShape<D>, IPackingItem {
|
---|
| 36 |
|
---|
| 37 | #region Properties
|
---|
| 38 | public int NrOfBins {
|
---|
| 39 | get {
|
---|
[14167] | 40 | if (Bins != null)
|
---|
| 41 | return Bins.Count;
|
---|
[14162] | 42 | else return 0;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | [Storable]
|
---|
| 46 | protected bool StackingConstraints { get; set; }
|
---|
| 47 | [Storable]
|
---|
| 48 | protected bool UseExtremePoints { get; set; }
|
---|
| 49 |
|
---|
| 50 | [Storable]
|
---|
[14167] | 51 | public B BinShape { get; private set; }
|
---|
[14162] | 52 |
|
---|
| 53 | [Storable]
|
---|
[14167] | 54 | public ObservableList<BinPacking<D, B, I>> Bins { get; set; }
|
---|
[14162] | 55 |
|
---|
| 56 | [Storable]
|
---|
| 57 | private DoubleValue quality;
|
---|
| 58 | public DoubleValue Quality {
|
---|
| 59 | get { return quality; }
|
---|
| 60 | set {
|
---|
| 61 | if (quality != value) {
|
---|
| 62 | if (quality != null) DeregisterQualityEvents();
|
---|
| 63 | quality = value;
|
---|
| 64 | if (quality != null) RegisterQualityEvents();
|
---|
| 65 | OnQualityChanged();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | #endregion
|
---|
| 70 |
|
---|
[14167] | 71 | protected PackingPlan(B binShape, bool useExtremePoints, bool stackingConstraints)
|
---|
[14162] | 72 | : base() {
|
---|
[14167] | 73 | BinShape = (B)binShape.Clone();
|
---|
[14162] | 74 | StackingConstraints = stackingConstraints;
|
---|
| 75 | UseExtremePoints = useExtremePoints;
|
---|
[14167] | 76 | Bins = new ObservableList<BinPacking<D, B, I>>();
|
---|
[14162] | 77 | }
|
---|
| 78 |
|
---|
| 79 | [StorableConstructor]
|
---|
[16720] | 80 | protected PackingPlan(StorableConstructorFlag _) : base(_) { }
|
---|
[14162] | 81 | protected PackingPlan(PackingPlan<D, B, I> original, Cloner cloner)
|
---|
| 82 | : base(original, cloner) {
|
---|
[14167] | 83 | this.Bins = new ObservableList<BinPacking<D, B, I>>(original.Bins.Select(p => cloner.Clone(p)));
|
---|
[14162] | 84 | UseExtremePoints = original.UseExtremePoints;
|
---|
| 85 | StackingConstraints = original.StackingConstraints;
|
---|
[14167] | 86 | BinShape = cloner.Clone(original.BinShape);
|
---|
[14162] | 87 | Quality = cloner.Clone(original.Quality);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | public void UpdateBinPackings() {
|
---|
[14167] | 92 | Bins.RemoveAll(x => x.Positions.Count == 0);
|
---|
| 93 | Bins = new ObservableList<BinPacking<D, B, I>>(Bins.OrderByDescending(bp => bp.PackingDensity));
|
---|
[14162] | 94 | }
|
---|
| 95 |
|
---|
| 96 | #region Events
|
---|
| 97 | public event EventHandler QualityChanged;
|
---|
| 98 | private void OnQualityChanged() {
|
---|
| 99 | var changed = QualityChanged;
|
---|
| 100 | if (changed != null)
|
---|
| 101 | changed(this, EventArgs.Empty);
|
---|
| 102 | }
|
---|
| 103 | private void RegisterQualityEvents() {
|
---|
| 104 | Quality.ValueChanged += new EventHandler(Quality_ValueChanged);
|
---|
| 105 | }
|
---|
| 106 | private void DeregisterQualityEvents() {
|
---|
| 107 | Quality.ValueChanged -= new EventHandler(Quality_ValueChanged);
|
---|
| 108 | }
|
---|
| 109 | private void Quality_ValueChanged(object sender, EventArgs e) {
|
---|
| 110 | OnQualityChanged();
|
---|
| 111 | }
|
---|
| 112 | #endregion
|
---|
| 113 | }
|
---|
| 114 | }
|
---|