# source:branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ResidualSpace.cs@15520

Last change on this file since 15520 was 15520, checked in by rhanghof, 22 months ago
• Changed the calculation algorithm for creating extreme points by using line based projection
• Changed the calculation of the residual spaces for line based projection
File size: 3.1 KB
Line
1using HeuristicLab.Core;
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
7using HeuristicLab.Common;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Problems.BinPacking3D.Geometry;
10
11namespace HeuristicLab.Problems.BinPacking3D {
12  [Item("ResidualSpace", "Represents a residual space für a 3D bin-packing problem.")]
13  [StorableClass]
14  public class ResidualSpace : Item {
15
16    public static ResidualSpace Create(int width, int height, int depth) {
17      return new ResidualSpace(width, height, depth);
18    }
19
20    public static ResidualSpace Create(ResidualSpace other) {
21      return new ResidualSpace() {
22        Width = other.Width,
23        Height = other.Height,
24        Depth = other.Depth
25      };
26    }
27
28    public ResidualSpace() {
29      SetZero();
30    }
31
32    public ResidualSpace(int width, int height, int depth) {
33      Width = width;
34      Height = height;
35      Depth = depth;
36    }
37
38    public ResidualSpace(Tuple<int, int, int> rs) {
39      Width = rs.Item1;
40      Height = rs.Item2;
41      Depth = rs.Item3;
42
43      if (IsZero()) {
44        SetZero();
45      }
46    }
47
48    public ResidualSpace(BinPacking3D binPacking, Vector3D point) {
49      Width = binPacking.BinShape.Width - point.X;
50      Height = binPacking.BinShape.Height - point.Y;
51      Depth = binPacking.BinShape.Depth - point.Z;
52
53      if (IsZero()) {
54        SetZero();
55      }
56    }
57
58    [StorableConstructor]
59    protected ResidualSpace(bool deserializing) : base(deserializing) { }
60
61
62    protected ResidualSpace(ResidualSpace original, Cloner cloner) : base(original, cloner) {
63      this.Width = original.Width;
64      this.Height = original.Height;
65      this.Depth = original.Depth;
66    }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new ResidualSpace(this, cloner);
70    }
71
72    [Storable]
73    public int Width { get; set; }
74
75    [Storable]
76    public int Height { get; set; }
77
78    [Storable]
79    public int Depth { get; set; }
80
81    public override bool Equals(object obj) {
82
83      if (obj == null || GetType() != obj.GetType()) {
84        return false;
85      }
86      ResidualSpace rs = obj as ResidualSpace;
87      return this.Width == rs.Width && this.Height == rs.Height && this.Depth == rs.Depth;
88    }
89
90    public override string ToString() {
91      return \$"({Width},{Height},{Depth})";
92    }
93
94    /*************************************************************
95     *
96     * ***********************************************************/
97
98    public Tuple<int, int, int> ToTuple() {
99      return new Tuple<int, int, int>(Width, Height, Depth);
100    }
101
102    public PackingItem ToPackingItem() {
103      return new PackingItem() {
104        Width = this.Width,
105        Height = this.Height,
106        Depth = this.Depth
107      };
108    }
109
110    public bool IsZero() {
111      return Width == 0 || Height == 0 || Depth == 0;
112    }
113
114    public void SetZero() {
115      Width = 0;
116      Height = 0;
117      Depth = 0;
118    }
119  }
120}
Note: See TracBrowser for help on using the repository browser.