[15617] | 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
[14162] | 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 25 | using HeuristicLab.Problems.BinPacking;
|
---|
[15646] | 26 | using System;
|
---|
[14162] | 27 |
|
---|
| 28 | namespace 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> {
|
---|
[14167] | 32 | public Solution(PackingShape binShape) : this(binShape, false, false) { }
|
---|
| 33 | public Solution(PackingShape binShape, bool useExtremePoints, bool stackingConstraints) : base(binShape, useExtremePoints, stackingConstraints) { }
|
---|
[14162] | 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 | }
|
---|
[15646] | 42 |
|
---|
| 43 | public bool IsBetterThan(Solution other, IEvaluator evaluator, bool problemMaximization = true) {
|
---|
[15838] | 44 | var evaluatedThis = evaluator.EvaluateBinPacking(this);
|
---|
[15646] | 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 |
|
---|
[15838] | 54 | var evaluatedOther = evaluator.EvaluateBinPacking(other);
|
---|
[15646] | 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 |
|
---|
[15731] | 68 | if (evaluatedThis.Item4 > evaluatedOther.Item4) {
|
---|
| 69 | return false;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[15646] | 72 | if (evaluatedThis.Item3 > evaluatedOther.Item3) {
|
---|
| 73 | return false;
|
---|
| 74 | }
|
---|
| 75 | return true;
|
---|
| 76 |
|
---|
| 77 | }
|
---|
[14162] | 78 | }
|
---|
| 79 | } |
---|