Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 15866 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: 4.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.Core;
23using System;
24using System.Collections.Generic;
25using System.Linq;
26using System.Text;
27using System.Threading.Tasks;
28using HeuristicLab.Common;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.BinPacking3D.Geometry;
31
32namespace 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}
Note: See TracBrowser for help on using the repository browser.