Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/PackingPlanEvaluationAlgorithm.cs @ 13792

Last change on this file since 13792 was 13608, checked in by gkronber, 9 years ago

#1966 refactoring (moved 3d-specific classes into separate project)

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