Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2817:

  • Added a new packer.
  • Enhanced the material types.
  • Added extreme point pruning for layer support in the extrem point creators.
  • BinPacking3D: Added a graph for calculating weigth distribution of the items.
File size: 2.7 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.Persistence.Default.CompositeSerializers.Storable;
25using HeuristicLab.Problems.BinPacking;
26using System;
27
28namespace HeuristicLab.Problems.BinPacking3D {
29  [Item("Bin Packing Solution (3d)", "Represents a solution for a 3D bin packing problem.")]
30  [StorableClass]
31  public class Solution : PackingPlan<PackingPosition, PackingShape, PackingItem> {
32    public Solution(PackingShape binShape) : this(binShape, false, false) { }
33    public Solution(PackingShape binShape, bool useExtremePoints, bool stackingConstraints) : base(binShape, useExtremePoints, stackingConstraints) { }
34    [StorableConstructor]
35    protected Solution(bool deserializing) : base(deserializing) { }
36    protected Solution(Solution original, Cloner cloner)
37      : base(original, cloner) {
38    }
39    public override IDeepCloneable Clone(Cloner cloner) {
40      return new Solution(this, cloner);
41    }
42
43    public bool IsBetterThan(Solution other, IEvaluator evaluator, bool problemMaximization = true) {
44      var evaluatedThis = evaluator.Evaluate1(this);
45
46      if (double.IsInfinity(evaluatedThis.Item2) || double.IsNaN(evaluatedThis.Item2)) {
47        return false;
48      }
49
50      if (other == null) {
51        return true;
52      }
53
54      var evaluatedOther = evaluator.Evaluate1(other);
55      if (evaluatedThis.Item1 < evaluatedOther.Item1) {
56        return true;
57      } else if (evaluatedThis.Item1 > evaluatedOther.Item1) {
58        return false;
59      }
60     
61      if (evaluatedThis.Item2 > evaluatedOther.Item2) {
62        return true;
63      }
64      if (evaluatedThis.Item2 < evaluatedOther.Item2) {
65        return false;
66      }
67
68      if (evaluatedThis.Item4 > evaluatedOther.Item4) {
69        return false;
70      }
71
72      if (evaluatedThis.Item3 > evaluatedOther.Item3) {
73        return false;
74      }
75      return true;
76
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.