Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceReintegration/HeuristicLab.Problems.BinPacking/3.3/2D/MoveEvaluatorBase.cs @ 14927

Last change on this file since 14927 was 14927, checked in by gkronber, 7 years ago

#2520: changed all usages of StorableClass to use StorableType with an auto-generated GUID (did not add StorableType to other type definitions yet)

File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
26using HeuristicLab.Optimization;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence;
29
30namespace HeuristicLab.Problems.BinPacking2D {
31  [StorableType("691c3981-3242-4540-a119-c0faa2c28e4e")]
32  public abstract class MoveEvaluatorBase<TSol, TMove> : SingleSuccessorOperator,
33    ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IOperator<TSol>
34    where TSol : class, IItem
35    where TMove : class, IItem {
36    public ILookupParameter<TSol> EncodedSolutionParameter {
37      get { return (ILookupParameter<TSol>)Parameters["EncodedSolution"]; }
38    }
39    public ILookupParameter<DoubleValue> QualityParameter {
40      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
41    }
42    public ILookupParameter<DoubleValue> MoveQualityParameter {
43      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
44    }
45    public ILookupParameter<ReadOnlyItemList<PackingItem>> ItemsParameter {
46      get { return (LookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; }
47    }
48    public ILookupParameter<PackingShape> BinShapeParameter {
49      get { return (LookupParameter<PackingShape>)Parameters["BinShape"]; }
50    }
51    public ILookupParameter<IDecoder<TSol>> DecoderParameter {
52      get { return (ILookupParameter<IDecoder<TSol>>)Parameters["Decoder"]; }
53    }
54    public ILookupParameter<IEvaluator> SolutionEvaluatorParameter {
55      get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; }
56    }
57    public ILookupParameter<TMove> MoveParameter {
58      get { return (ILookupParameter<TMove>)Parameters["Move"]; }
59    }
60
61
62    [StorableConstructor]
63    protected MoveEvaluatorBase(bool deserializing) : base(deserializing) { }
64    protected MoveEvaluatorBase(MoveEvaluatorBase<TSol, TMove> original, Cloner cloner) : base(original, cloner) { }
65    protected MoveEvaluatorBase()
66      : base() {
67      Parameters.Add(new LookupParameter<TSol>("EncodedSolution", "The encoded solution candidate to evaluate"));
68      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a packing solution."));
69      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a packing solution."));
70      Parameters.Add(new LookupParameter<ReadOnlyItemList<PackingItem>>("Items", "Packing-item data taken from the bin-packing problem-instance."));
71      Parameters.Add(new LookupParameter<PackingShape>("BinShape", "Packing-bin data taken from the bin-packing problem-instance."));
72      Parameters.Add(new LookupParameter<IDecoder<TSol>>("Decoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
73      Parameters.Add(new LookupParameter<IEvaluator>("SolutionEvaluator", "The actual packing plan evaluation operator."));
74      Parameters.Add(new LookupParameter<TMove>("Move", "The move to evaluate."));
75    }
76
77    public override IOperation Apply() {
78      var move = MoveParameter.ActualValue;
79      var encSolCandidate = EncodedSolutionParameter.ActualValue;
80      var binShape = BinShapeParameter.ActualValue;
81      var items = ItemsParameter.ActualValue;
82
83
84      double moveQuality = EvaluateMove(encSolCandidate, move, binShape, items);
85
86      if (MoveQualityParameter.ActualValue == null)
87        MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
88      else
89        MoveQualityParameter.ActualValue.Value = moveQuality;
90      return base.Apply();
91    }
92
93    public abstract double EvaluateMove(TSol encodedSolutionCandidate, TMove move, PackingShape binShape, ReadOnlyItemList<PackingItem> items);
94  }
95}
Note: See TracBrowser for help on using the repository browser.