Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Evaluators/MoveEvaluatorBase.cs @ 15731

Last change on this file since 15731 was 15617, checked in by rhanghof, 7 years ago

#2817:

  • The items can be rotated and tilted now.
  • Added pruning of extreme points in packed bins.
  • Added new packer which packs items by positioning them on the point with the minimum of wasted space. He uses rotating and tilting of items.
  • Added classes for sorting given items.
File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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;
29using HeuristicLab.Problems.BinPacking3D.Encoding;
30
31namespace HeuristicLab.Problems.BinPacking3D.Evaluators {
32  [StorableClass]
33  public abstract class MoveEvaluatorBase<TSol, TMove> : SingleSuccessorOperator,
34    ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IOperator<TSol>
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>> ItemsParameter {
47      get { return (ILookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; }
48    }
49    public ILookupParameter<PackingShape> BinShapeParameter {
50      get { return (ILookupParameter<PackingShape>)Parameters["BinShape"]; }
51    }
52    public ILookupParameter<IDecoder<TSol>> DecoderParameter {
53      get { return (ILookupParameter<IDecoder<TSol>>)Parameters["Decoder"]; }
54    }
55    public ILookupParameter<IEvaluator> SolutionEvaluatorParameter {
56      get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; }
57    }
58    public ILookupParameter<TMove> MoveParameter {
59      get { return (ILookupParameter<TMove>)Parameters["Move"]; }
60    }
61    public ILookupParameter<BoolValue> UseStackingConstraintsParameter {
62      get { return (ILookupParameter<BoolValue>)Parameters["UseStackingConstraints"]; }
63    }
64
65
66    [StorableConstructor]
67    protected MoveEvaluatorBase(bool deserializing) : base(deserializing) { }
68    protected MoveEvaluatorBase(MoveEvaluatorBase<TSol, TMove> original, Cloner cloner) : base(original, cloner) { }
69    protected MoveEvaluatorBase()
70      : base() {
71      Parameters.Add(new LookupParameter<TSol>("EncodedSolution", "The encoded solution candidate to evaluate"));
72      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of a packing solution."));
73      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The evaluated quality of a move on a packing solution."));
74      Parameters.Add(new LookupParameter<ReadOnlyItemList<PackingItem>>("Items", "Packing-item data taken from the bin-packing problem-instance."));
75      Parameters.Add(new LookupParameter<PackingShape>("BinShape", "Packing-bin data taken from the bin-packing problem-instance."));
76      Parameters.Add(new LookupParameter<IDecoder<TSol>>("Decoder", "The decoding operator that is used to calculate a packing plan from the used representation."));
77      Parameters.Add(new LookupParameter<IEvaluator>("SolutionEvaluator", "The actual packing plan evaluation operator."));
78      Parameters.Add(new LookupParameter<TMove>("Move", "The move to evaluate."));
79      Parameters.Add(new LookupParameter<BoolValue>("UseStackingConstraints", "A flag that determines if stacking constriants should be checked when solving the problem"));
80    }
81
82    public override IOperation Apply() {
83      var move = MoveParameter.ActualValue;
84      var encSolCandidate = EncodedSolutionParameter.ActualValue;
85      var binShape = BinShapeParameter.ActualValue;
86      var items = ItemsParameter.ActualValue;
87
88
89      double moveQuality = EvaluateMove(encSolCandidate, move, binShape, items, UseStackingConstraintsParameter.ActualValue.Value);
90
91      if (MoveQualityParameter.ActualValue == null)
92        MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
93      else
94        MoveQualityParameter.ActualValue.Value = moveQuality;
95      return base.Apply();
96    }
97
98    public abstract double EvaluateMove(TSol encodedSolutionCandidate, TMove move, PackingShape binShape, ReadOnlyItemList<PackingItem> items, bool useStackingConstraints);
99  }
100}
Note: See TracBrowser for help on using the repository browser.