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.Core;
|
---|
23 | using System;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Text;
|
---|
27 | using System.Threading.Tasks;
|
---|
28 | using HeuristicLab.Common;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Problems.BinPacking3D.Geometry;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.BinPacking3D {
|
---|
33 | [Item("ResidualSpace", "Represents a residual space für a 3D bin-packing problem.")]
|
---|
34 | [StorableClass]
|
---|
35 | public class ResidualSpace : Item {
|
---|
36 |
|
---|
37 | public static ResidualSpace Create(int width, int height, int depth) {
|
---|
38 | return new ResidualSpace(width, height, depth);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public static ResidualSpace Create(ResidualSpace other) {
|
---|
42 | return new ResidualSpace() {
|
---|
43 | Width = other.Width,
|
---|
44 | Height = other.Height,
|
---|
45 | Depth = other.Depth
|
---|
46 | };
|
---|
47 | }
|
---|
48 |
|
---|
49 | public ResidualSpace() {
|
---|
50 | SetZero();
|
---|
51 | }
|
---|
52 |
|
---|
53 | public ResidualSpace(int width, int height, int depth) {
|
---|
54 | Width = width;
|
---|
55 | Height = height;
|
---|
56 | Depth = depth;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public ResidualSpace(Tuple<int, int, int> rs) {
|
---|
60 | Width = rs.Item1;
|
---|
61 | Height = rs.Item2;
|
---|
62 | Depth = rs.Item3;
|
---|
63 |
|
---|
64 | if (IsZero()) {
|
---|
65 | SetZero();
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | public ResidualSpace(BinPacking3D binPacking, Vector3D point) {
|
---|
70 | Width = binPacking.BinShape.Width - point.X;
|
---|
71 | Height = binPacking.BinShape.Height - point.Y;
|
---|
72 | Depth = binPacking.BinShape.Depth - point.Z;
|
---|
73 |
|
---|
74 | if (IsZero()) {
|
---|
75 | SetZero();
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | [StorableConstructor]
|
---|
80 | protected ResidualSpace(bool deserializing) : base(deserializing) { }
|
---|
81 |
|
---|
82 |
|
---|
83 | protected ResidualSpace(ResidualSpace original, Cloner cloner) : base(original, cloner) {
|
---|
84 | this.Width = original.Width;
|
---|
85 | this.Height = original.Height;
|
---|
86 | this.Depth = original.Depth;
|
---|
87 | }
|
---|
88 |
|
---|
89 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
90 | return new ResidualSpace(this, cloner);
|
---|
91 | }
|
---|
92 |
|
---|
93 | [Storable]
|
---|
94 | public int Width { get; set; }
|
---|
95 |
|
---|
96 | [Storable]
|
---|
97 | public int Height { get; set; }
|
---|
98 |
|
---|
99 | [Storable]
|
---|
100 | public int Depth { get; set; }
|
---|
101 |
|
---|
102 | public override bool Equals(object obj) {
|
---|
103 |
|
---|
104 | if (obj == null || GetType() != obj.GetType()) {
|
---|
105 | return false;
|
---|
106 | }
|
---|
107 | ResidualSpace rs = obj as ResidualSpace;
|
---|
108 | return this.Width == rs.Width && this.Height == rs.Height && this.Depth == rs.Depth;
|
---|
109 | }
|
---|
110 |
|
---|
111 | public override string ToString() {
|
---|
112 | return $"({Width},{Height},{Depth})";
|
---|
113 | }
|
---|
114 |
|
---|
115 | /*************************************************************
|
---|
116 | *
|
---|
117 | * ***********************************************************/
|
---|
118 |
|
---|
119 | public Tuple<int, int, int> ToTuple() {
|
---|
120 | return new Tuple<int, int, int>(Width, Height, Depth);
|
---|
121 | }
|
---|
122 |
|
---|
123 | public PackingItem ToPackingItem() {
|
---|
124 | return new PackingItem() {
|
---|
125 | OriginalWidth = this.Width,
|
---|
126 | OriginalHeight = this.Height,
|
---|
127 | OriginalDepth = this.Depth
|
---|
128 | };
|
---|
129 | }
|
---|
130 |
|
---|
131 | public bool IsZero() {
|
---|
132 | return Width == 0 || Height == 0 || Depth == 0;
|
---|
133 | }
|
---|
134 |
|
---|
135 | public void SetZero() {
|
---|
136 | Width = 0;
|
---|
137 | Height = 0;
|
---|
138 | Depth = 0;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|