Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9674 was 9440, checked in by jhelm, 12 years ago

#1966: Implemented new encoding (MultiComponentVector/MCV); Implemented move-operators for MCV and GV encodings; Implemented new decoding-methods for PS, GV and MCV encodings (ExtremePoint-based packing);

File size: 3.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Problems.BinPacking.Interfaces;
6using HeuristicLab.Operators;
7using HeuristicLab.Core;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Common;
10using HeuristicLab.Data;
11using HeuristicLab.Problems.BinPacking.Decoders;
12using HeuristicLab.Parameters;
13using HeuristicLab.Problems.BinPacking.Shapes;
14using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
15
16namespace HeuristicLab.Problems.BinPacking.Evaluators {
17  [Item("Packingplan Evaluation Algorithm", "Represents a composition of a decoder and an evaluator for bin-packing problems.")]
18  [StorableClass]
19  public class PackingPlanEvaluationAlgorithm<E, D, B, I> : SingleSuccessorOperator, IPackingPlanEvaluationAlgorithm
20    where E : Item //E defines the used Encoding
21    where D : class, IPackingDimensions
22    where B : PackingShape<D>, IPackingBin
23    where I : PackingShape<D>, IPackingItem {
24
25    public IValueLookupParameter<IPackingSolutionDecoder> PackingSolutionDecoderParameter {
26      get { return (IValueLookupParameter<IPackingSolutionDecoder>)Parameters["PackingSolutionDecoder"]; }
27    }
28    ILookupParameter<IPackingSolutionDecoder> IPackingPlanEvaluationAlgorithm.PackingSolutionDecoderParameter {
29      get { return PackingSolutionDecoderParameter; }
30    }
31    public IValueLookupParameter<IPackingPlanEvaluator> PackingPlanEvaluatorParameter {
32      get { return (IValueLookupParameter<IPackingPlanEvaluator>)Parameters["PackingPlanEvaluator"]; }
33    }
34    ILookupParameter<IPackingPlanEvaluator> IPackingPlanEvaluationAlgorithm.PackingPlanEvaluatorParameter {
35      get { return PackingPlanEvaluatorParameter; }
36    }
37    public ILookupParameter<DoubleValue> QualityParameter {
38      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
39    }
40
41    [StorableConstructor]
42    protected PackingPlanEvaluationAlgorithm(bool deserializing) : base(deserializing) { }
43    protected PackingPlanEvaluationAlgorithm(PackingPlanEvaluationAlgorithm<E, D, B, I> original, Cloner cloner)
44      : base(original, cloner) {
45    }
46    public PackingPlanEvaluationAlgorithm ()
47      : base() {
48        Parameters.Add(new ValueLookupParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
49        Parameters.Add(new ValueLookupParameter<IPackingPlanEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator."));
50        Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution."));
51        QualityParameter.Hidden = true;
52    }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new PackingPlanEvaluationAlgorithm<E, D, B, I>(this, cloner);
55    }
56
57    public override IOperation Apply() {
58      var decoder = PackingSolutionDecoderParameter.ActualValue;
59      var evaluator = PackingPlanEvaluatorParameter.ActualValue;
60      if (evaluator == null) throw new InvalidOperationException("A PackingPlanEvaluator could not be found.");
61
62      var operations = new OperationCollection(base.Apply());
63      operations.Insert(0, ExecutionContext.CreateChildOperation(evaluator));
64      if (decoder != null) // decode before evaluating
65        operations.Insert(0, ExecutionContext.CreateChildOperation(decoder));
66      return operations;
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.