1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Problems.BinPacking.Interfaces;
|
---|
6 | using HeuristicLab.Operators;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using HeuristicLab.Common;
|
---|
10 | using HeuristicLab.Data;
|
---|
11 | using HeuristicLab.Problems.BinPacking.Decoders;
|
---|
12 | using HeuristicLab.Parameters;
|
---|
13 | using HeuristicLab.Problems.BinPacking.Shapes;
|
---|
14 | using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
|
---|
15 |
|
---|
16 | namespace 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 | } |
---|