Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2695_dataset-ids/HeuristicLab.Problems.BinPacking/3.3/3D/MoveEvaluatorBase.cs @ 16881

Last change on this file since 16881 was 14162, checked in by gkronber, 8 years ago

#2641: first import of bin packing problem (TODO: persistence and sample)

File size: 5.0 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.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.BinPacking3D {
31  [StorableClass]
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 (ILookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; }
47    }
48    public ILookupParameter<PackingShape> BinShapeParameter {
49      get { return (ILookupParameter<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    public ILookupParameter<BoolValue> UseStackingConstraintsParameter {
61      get { return (ILookupParameter<BoolValue>)Parameters["UseStackingConstraints"]; }
62    }
63
64
65    [StorableConstructor]
66    protected MoveEvaluatorBase(bool deserializing) : base(deserializing) { }
67    protected MoveEvaluatorBase(MoveEvaluatorBase<TSol, TMove> original, Cloner cloner) : base(original, cloner) { }
68    protected MoveEvaluatorBase()
69      : base() {
70      Parameters.Add(new LookupParameter<TSol>("EncodedSolution", "The encoded solution candidate to evaluate"));
71      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a packing solution."));
72      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a packing solution."));
73      Parameters.Add(new LookupParameter<ReadOnlyItemList<PackingItem>>("Items", "Packing-item data taken from the bin-packing problem-instance."));
74      Parameters.Add(new LookupParameter<PackingShape>("BinShape", "Packing-bin data taken from the bin-packing problem-instance."));
75      Parameters.Add(new LookupParameter<IDecoder<TSol>>("Decoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
76      Parameters.Add(new LookupParameter<IEvaluator>("SolutionEvaluator", "The actual packing plan evaluation operator."));
77      Parameters.Add(new LookupParameter<TMove>("Move", "The move to evaluate."));
78      Parameters.Add(new LookupParameter<BoolValue>("UseStackingConstraints", "A flag that determines if stacking constriants should be checked when solving the problem"));
79    }
80
81    public override IOperation Apply() {
82      var move = MoveParameter.ActualValue;
83      var encSolCandidate = EncodedSolutionParameter.ActualValue;
84      var binShape = BinShapeParameter.ActualValue;
85      var items = ItemsParameter.ActualValue;
86
87
88      double moveQuality = EvaluateMove(encSolCandidate, move, binShape, items, UseStackingConstraintsParameter.ActualValue.Value);
89
90      if (MoveQualityParameter.ActualValue == null)
91        MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
92      else
93        MoveQualityParameter.ActualValue.Value = moveQuality;
94      return base.Apply();
95    }
96
97    public abstract double EvaluateMove(TSol encodedSolutionCandidate, TMove move, PackingShape binShape, ReadOnlyItemList<PackingItem> items, bool useStackingConstraints);
98  }
99}
Note: See TracBrowser for help on using the repository browser.