Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1966_HeuristicLab.BinPacking/old files/evaluators/DecodingEvaluator.cs @ 16755

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

#1966: new implementation for 2d bin packing problem with permutation encoding

File size: 3.8 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
22using System;
23using HeuristicLab.Operators;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HeuristicLab.Common;
27using HeuristicLab.Data;
28using HeuristicLab.Parameters;
29
30
31namespace HeuristicLab.Problems.BinPacking {
32  [Item("Bin Packing Evaluator (with decoder)", "Represents a composition of a decoder and an evaluator for bin-packing problems.")]
33  [StorableClass]
34  public class DecodingEvaluator<E, D, B, I> : SingleSuccessorOperator, IDecodingEvaluator
35    where E : Item //E defines the used Encoding
36    where D : class, IPackingPosition
37    where B : PackingShape<D>
38    where I : PackingShape<D>, IPackingItem {
39
40    public IValueLookupParameter<IPackingSolutionDecoder> PackingSolutionDecoderParameter {
41      get { return (IValueLookupParameter<IPackingSolutionDecoder>)Parameters["PackingSolutionDecoder"]; }
42    }
43    ILookupParameter<IPackingSolutionDecoder> IDecodingEvaluator.PackingSolutionDecoderParameter {
44      get { return PackingSolutionDecoderParameter; }
45    }
46    public IValueLookupParameter<IEvaluator> PackingPlanEvaluatorParameter {
47      get { return (IValueLookupParameter<IEvaluator>)Parameters["PackingPlanEvaluator"]; }
48    }
49    ILookupParameter<IEvaluator> IDecodingEvaluator.PackingPlanEvaluatorParameter {
50      get { return PackingPlanEvaluatorParameter; }
51    }
52    public ILookupParameter<DoubleValue> QualityParameter {
53      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
54    }
55
56    [StorableConstructor]
57    protected DecodingEvaluator(bool deserializing) : base(deserializing) { }
58    protected DecodingEvaluator(DecodingEvaluator<E, D, B, I> original, Cloner cloner)
59      : base(original, cloner) {
60    }
61    public DecodingEvaluator ()
62      : base() {
63        Parameters.Add(new ValueLookupParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
64        Parameters.Add(new ValueLookupParameter<IEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator."));
65        Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution."));
66        QualityParameter.Hidden = true;
67    }
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new DecodingEvaluator<E, D, B, I>(this, cloner);
70    }
71
72    public override IOperation Apply() {
73      var decoder = PackingSolutionDecoderParameter.ActualValue;
74      var evaluator = PackingPlanEvaluatorParameter.ActualValue;
75      if (evaluator == null) throw new InvalidOperationException("A PackingPlanEvaluator could not be found.");
76
77      var operations = new OperationCollection(base.Apply());
78      operations.Insert(0, ExecutionContext.CreateChildOperation(evaluator));
79      if (decoder != null) // decode before evaluating
80        operations.Insert(0, ExecutionContext.CreateChildOperation(decoder));
81      return operations;
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.