Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/PackingSolutionDecoder.cs @ 12246

Last change on this file since 12246 was 9598, checked in by jhelm, 11 years ago

#1966: Fixed a bug which caused the stacking-contraint to be wrongly enforced; Did some cleanup;

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Problems.BinPacking.Interfaces;
27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Common;
30using HeuristicLab.Operators;
31using HeuristicLab.Parameters;
32using HeuristicLab.Problems.BinPacking.Shapes;
33using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
34using HeuristicLab.Data;
35using HeuristicLab.Collections;
36
37namespace HeuristicLab.Problems.BinPacking.Decoders {
38
39  [Item("Packing-Solution Decoder", "An operator to create a concrete bin packing solution from a given encoding-instance.")]
40  [StorableClass]
41  public abstract class PackingSolutionDecoder<D, B, I> : SingleSuccessorOperator, IPackingSolutionDecoder
42    where D : class, IPackingDimensions
43    where B : PackingShape<D>, IPackingBin
44    where I : PackingShape<D>, IPackingItem {
45
46    public ILookupParameter<IRandom> RandomParameter {
47      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
48    }
49    private ILookupParameter<ItemList<I>> PackingItemMeasuresParameter {
50      get { return (LookupParameter<ItemList<I>>)Parameters["PackingItemMeasures"]; }
51    }
52    private ILookupParameter<B> PackingBinMeasuresParameter {
53      get { return (LookupParameter<B>)Parameters["PackingBinMeasures"]; }
54    }
55    public ILookupParameter<IItem> EncodedSolutionParameter {
56      get { return (ILookupParameter<IItem>)Parameters["EncodedSolution"]; }
57    }
58    public ILookupParameter<PackingPlan<D,B,I>> PackingPlanParameter {
59      get { return (ILookupParameter<PackingPlan<D, B, I>>)Parameters["PackingPlan"]; }
60    }
61    public ValueParameter<BoolValue> StackingConstraintsParameter {
62      get { return (ValueParameter<BoolValue>)Parameters["StackingConstraint"]; }
63    }
64
65
66    public PackingSolutionDecoder() : base() {
67      Parameters.Add(new LookupParameter<IItem>("EncodedSolution", "The new bin-packing solution represented as encoding."));
68      Parameters.Add(new LookupParameter<PackingPlan<D, B, I>>("PackingPlan", "The decoded bin-packing solution represented as generalized packing plan."));
69      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
70      Parameters.Add(new LookupParameter<ItemList<I>>("PackingItemMeasures", "Packing-item data taken from the bin-packing problem-instance."));
71      Parameters.Add(new LookupParameter<B>("PackingBinMeasures", "Packing-bin data taken from the bin-packing problem-instance."));
72      Parameters.Add(new ValueParameter<BoolValue>("StackingConstraint", "A flag determining whether stackingconstraints should be enforced or not.", new BoolValue(true)));
73    }
74
75    [StorableConstructor]
76    protected PackingSolutionDecoder(bool deserializing) : base(deserializing) { }
77    protected PackingSolutionDecoder(PackingSolutionDecoder<D,B,I> original, Cloner cloner)
78      : base(original, cloner) {
79    }
80
81    public abstract PackingPlan<D, B, I> CreatePackingPlanFromEncoding(IItem solution, B binMeasures, ItemList<I> itemMeasures);
82
83    public override IOperation Apply() {
84      PackingPlan<D, B, I> result = CreatePackingPlanFromEncoding(EncodedSolutionParameter.ActualValue, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
85      PackingPlanParameter.ActualValue = result;
86      return base.Apply();
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.