Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14151 was 14149, checked in by gkronber, 8 years ago

#1966: refactoring 2d problem

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