Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/old files/evaluators/DecodingEvaluator.cs @ 14856

Last change on this file since 14856 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
RevLine 
[13032]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;
[9348]23using HeuristicLab.Operators;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HeuristicLab.Common;
27using HeuristicLab.Data;
28using HeuristicLab.Parameters;
29
[14046]30
31namespace HeuristicLab.Problems.BinPacking {
[14054]32  [Item("Bin Packing Evaluator (with decoder)", "Represents a composition of a decoder and an evaluator for bin-packing problems.")]
[9348]33  [StorableClass]
[14054]34  public class DecodingEvaluator<E, D, B, I> : SingleSuccessorOperator, IDecodingEvaluator
[9348]35    where E : Item //E defines the used Encoding
[14048]36    where D : class, IPackingPosition
[14045]37    where B : PackingShape<D>
[9348]38    where I : PackingShape<D>, IPackingItem {
39
40    public IValueLookupParameter<IPackingSolutionDecoder> PackingSolutionDecoderParameter {
41      get { return (IValueLookupParameter<IPackingSolutionDecoder>)Parameters["PackingSolutionDecoder"]; }
42    }
[14054]43    ILookupParameter<IPackingSolutionDecoder> IDecodingEvaluator.PackingSolutionDecoderParameter {
[9348]44      get { return PackingSolutionDecoderParameter; }
45    }
[14050]46    public IValueLookupParameter<IEvaluator> PackingPlanEvaluatorParameter {
47      get { return (IValueLookupParameter<IEvaluator>)Parameters["PackingPlanEvaluator"]; }
[9348]48    }
[14054]49    ILookupParameter<IEvaluator> IDecodingEvaluator.PackingPlanEvaluatorParameter {
[9348]50      get { return PackingPlanEvaluatorParameter; }
51    }
52    public ILookupParameter<DoubleValue> QualityParameter {
53      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
54    }
55
56    [StorableConstructor]
[14054]57    protected DecodingEvaluator(bool deserializing) : base(deserializing) { }
58    protected DecodingEvaluator(DecodingEvaluator<E, D, B, I> original, Cloner cloner)
[9348]59      : base(original, cloner) {
60    }
[14054]61    public DecodingEvaluator ()
[9348]62      : base() {
63        Parameters.Add(new ValueLookupParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
[14050]64        Parameters.Add(new ValueLookupParameter<IEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator."));
[9348]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) {
[14054]69      return new DecodingEvaluator<E, D, B, I>(this, cloner);
[9348]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.