py3dbl 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
py3dbl-1.0.0/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
py3dbl-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: py3dbl
3
+ Version: 1.0.0
4
+ Summary: A powerful tool for 3D bin packing problem solving
5
+ Author-email: Giuliano Pardini <giulianpardini@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Giulian7/py3dbl
8
+ Project-URL: Issues, https://github.com/Giulian7/py3dbl/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # About this project
17
+
18
+ This project is a complete
19
+
20
+ # How to run and test
21
+
22
+ 1. Clone this repository on your machine
23
+ 2. Create a virtual enviroment (e.g. *python3 -m venv "enviroment_name"*)
24
+ 3. Install the required packages as of *requirements.txt* (e.g. *pip install -r requirements.txt*)
25
+ 4. Execute *test.ipynb* and enjoy the visit (to execute a jupyter notebook simply run *jupyter notebook "notebook_name"*)
py3dbl-1.0.0/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # About this project
2
+
3
+ This project is a complete
4
+
5
+ # How to run and test
6
+
7
+ 1. Clone this repository on your machine
8
+ 2. Create a virtual enviroment (e.g. *python3 -m venv "enviroment_name"*)
9
+ 3. Install the required packages as of *requirements.txt* (e.g. *pip install -r requirements.txt*)
10
+ 4. Execute *test.ipynb* and enjoy the visit (to execute a jupyter notebook simply run *jupyter notebook "notebook_name"*)
@@ -0,0 +1,19 @@
1
+ [project]
2
+ name = "py3dbl"
3
+ version = "1.0.0"
4
+ authors = [
5
+ { name="Giuliano Pardini", email="giulianpardini@gmail.com" },
6
+ ]
7
+ description = "A powerful tool for 3D bin packing problem solving"
8
+ readme = "README.md"
9
+ requires-python = ">=3.9"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+ license = "MIT"
15
+ license-files = ["LICEN[CS]E*"]
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/Giulian7/py3dbl"
19
+ Issues = "https://github.com/Giulian7/py3dbl/issues"
py3dbl-1.0.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,8 @@
1
+ from py3dbl_core.Packer import Packer
2
+ from py3dbl_core.Bin import Bin, BinModel
3
+ from py3dbl_core.Item import Item
4
+ from py3dbl_core.Space import Volume, Vector3
5
+ from .item_generator import item_generator
6
+ from .render import render_bin_interactive, render_item_interactive, render_volume_interactive
7
+ from py3dbl_core.Constraints import Constraint, constraint, constraints
8
+ from py3dbl_core.Algorithms import PackingAlgorithm, algorithm, algorithms
@@ -0,0 +1,3 @@
1
+ #import benchmarking as b
2
+ #from py3dbl.Constraints import constraints
3
+ #b.packing_benchmarker(["py3dbp","base_packer"],[constraints['weight_within_limit'],constraints['fits_inside_bin'],constraints['no_overlap']],end=300,start=100)
@@ -0,0 +1,115 @@
1
+ import py3dbl
2
+ import time
3
+ import platform
4
+ from datetime import datetime
5
+
6
+ START = 100
7
+ STEP = 100
8
+ ITER = 3
9
+
10
+ BIN_PARAMS = {
11
+ "width":2,
12
+ "depth":2,
13
+ "height":2,
14
+ "max_weight":100
15
+ }
16
+
17
+ ITEM_PARAMS = {
18
+ "width":(.1,1),
19
+ "depth":(.1,1),
20
+ "height":(.1,1),
21
+ "weight":(.1,1)
22
+ }
23
+
24
+ def packing_benchmarker(algorithms : list[str], constraints : list[py3dbl.Constraints.Constraint], end : int, start : int = START, step : int = 100, bin_params : dict = BIN_PARAMS, item_params : dict = ITEM_PARAMS, iterations : int = ITER, output_file : str = "benchmarking_result.txt"):
25
+ """
26
+ Put the listed algorithms in the same conditions (constraints set, item batch, model, ecc.) and test it for the number of times set by iterations
27
+
28
+ :param algorithms: List names of algorithms to use, the name should be a registred in py3dbl.algorithms or py3dbp
29
+ """
30
+
31
+ model = py3dbl.BinModel(None,[bin_params['width'],bin_params['height'],bin_params['depth']],bin_params['max_weight'],constraints)
32
+ def packer_from_algorithm(algorithm : str):
33
+ if algorithm == 'py3dbp':
34
+ # in case of py3dbp I need to adjust the packer interface
35
+ import py3dbp
36
+ def _add_batch(packer,batch):
37
+ for i in batch:
38
+ packer.items.append(py3dbp.Item(None,i.width,i.height,i.depth,i.weight))
39
+ packer.bins.append(py3dbp.Bin(None,bin_params['width'],bin_params['height'],bin_params['depth'],bin_params['max_weight']))
40
+ def _reset_items(self):
41
+ self.items = list()
42
+ self.bins = list()
43
+ packer = py3dbp.Packer()
44
+ packer.reset_items = (lambda :_reset_items(packer))
45
+ packer.add_batch = (lambda batch: _add_batch(packer, batch))
46
+ packer.pack = (lambda : py3dbp.Packer.pack(packer,distribute_items=True))
47
+ def _count_bin(packer):
48
+ idx = 0
49
+ for bin in packer.bins:
50
+ if len(bin.items) == 0:
51
+ break
52
+ idx += 1
53
+ return idx
54
+ packer.used_bins = (lambda : _count_bin(packer))
55
+ else:
56
+ packer = py3dbl.Packer(algorithm=py3dbl.algorithms[algorithm],default_bin=model)
57
+ packer.used_bins = (lambda : len(packer.current_configuration))
58
+ packer.name = algorithm
59
+ return packer
60
+
61
+ packers = [packer_from_algorithm(algorithm) for algorithm in algorithms]
62
+
63
+ results = dict()
64
+ with open(output_file,mode="a",newline='') as file:
65
+ file.write(("="*10)+datetime.now().strftime("%Y-%m-%d %H:%M:%S")+("="*10)+"\n")
66
+ file.write("System Information:\n")
67
+ uname = platform.uname()
68
+ file.writelines([
69
+ f" System: {uname.system}\n",
70
+ f" Node Name: {uname.node}\n",
71
+ f" Release: {uname.release}\n",
72
+ f" Version: {uname.version}\n",
73
+ f" Machine: {uname.machine}\n",
74
+ f" Processor: {uname.processor}\n"
75
+ ])
76
+ file.write("Banchmarking Parameters:\n")
77
+ file.writelines([
78
+ " items dimensions:\n",
79
+ *[" "+str(param)+": "+str(value)+"\n" for param,value in item_params.items()],
80
+ " bin parameters:\n",
81
+ *[" "+str(param)+": "+str(value)+"\n" for param,value in bin_params.items()],
82
+ " constraints:\n",
83
+ *[" "+str(constraint)+"\n" for constraint in constraints]
84
+ ])
85
+ for size in range(start,end+1,step):
86
+ results[size] = dict()
87
+ for algorithm in algorithms:
88
+ results[size][algorithm] = {"time":0,"bins":0}
89
+ for _ in range(iterations):
90
+ items = py3dbl.item_generator(
91
+ width=item_params['width'],
92
+ height=item_params['height'],
93
+ depth=item_params['depth'],
94
+ weight=item_params['weight'],
95
+ batch_size=size,
96
+ use_gaussian_distrib=False
97
+ )
98
+ for packer in packers:
99
+ packer.reset_items()
100
+ packer.add_batch(items)
101
+ start = time.time()
102
+ packer.pack()
103
+ end = time.time()
104
+ results[size][packer.name]["time"] += end-start
105
+ results[size][packer.name]["bins"] += packer.used_bins()
106
+
107
+
108
+ file.write(str(size)+" items:\n")
109
+ for algorithm,result in results[size].items():
110
+ result["time"] /= iterations
111
+ result["bins"] /= iterations
112
+ file.write(" " + algorithm + ":\n")
113
+ file.write(" time: " + str(round(result["time"],2)) + ", bins: " + str(round(result["bins"],2)) + "\n")
114
+
115
+ return results
@@ -0,0 +1,60 @@
1
+ from decimal import Decimal
2
+ from random import random,randint,gauss
3
+ from py3dbl_core.Item import Item
4
+ from py3dbl_core.Space import Vector3, Volume
5
+
6
+ def item_generator(width : tuple[Decimal,Decimal] , height : tuple[Decimal,Decimal], depth : tuple[Decimal,Decimal], weight : tuple[Decimal,Decimal], priority_range : tuple[int,int] = (0,0), batch_size : int = 1, use_gaussian_distrib : bool = False, decimals : int = 3) -> Item|list[Item]:
7
+ """
8
+ Generate Item objects with the given specifics
9
+
10
+ :param width: Width min-max range or mu-sigma params
11
+ :type width: tuple[Decimal, Decimal]
12
+ :param height: Height min-max range or mu-sigma params
13
+ :type height: tuple[Decimal, Decimal]
14
+ :param depth: Depth min-max range or mu-sigma params
15
+ :type depth: tuple[Decimal, Decimal]
16
+ :param weight: Weight min-max range or mu-sigma params
17
+ :type weight: tuple[Decimal, Decimal]
18
+ :param priority_range: Priority min-max range
19
+ :type priority_range: tuple[int, int]
20
+ :param batch_size: Number of items to generate
21
+ :type batch_size: int
22
+ :param use_gaussian_distrib: if True size and weight are gaussian varibles and width,height,depth and weight are the mu-sigma params associated, if False size and weight are simple random variables and width,height,depth and weight are the minimum and maximum values
23
+ :type use_gaussian_distrib: bool
24
+ """
25
+
26
+ randf = (lambda mu,sigma: abs(gauss(mu,sigma))) if use_gaussian_distrib else (lambda min,max: abs(min+random()*(max-min)))
27
+
28
+ if batch_size == 1:
29
+ ret = Item(
30
+ name = None,
31
+ volume = Volume(
32
+ size = Vector3(
33
+ x=Decimal(randf(width[0],width[1])),
34
+ y=Decimal(randf(height[0],height[1])),
35
+ z=Decimal(randf(depth[0],depth[1]))
36
+ )
37
+ ),
38
+ weight = Decimal(randf(weight[0],weight[1])),
39
+ priority= (randint(priority_range[0],priority_range[1]))
40
+ )
41
+ ret.format_numbers(decimals)
42
+ return ret
43
+ else:
44
+ items = []
45
+ for i in range(0,batch_size):
46
+ item = Item(
47
+ name = str(i),
48
+ volume = Volume(
49
+ size = Vector3(
50
+ x=Decimal(randf(width[0],width[1])),
51
+ y=Decimal(randf(height[0],height[1])),
52
+ z=Decimal(randf(depth[0],depth[1]))
53
+ )
54
+ ),
55
+ weight = Decimal(randf(weight[0],weight[1])),
56
+ priority= (randint(priority_range[0],priority_range[1]))
57
+ )
58
+ item.format_numbers(decimals)
59
+ items.append(item)
60
+ return items
@@ -0,0 +1,78 @@
1
+ import plotly.graph_objects as go
2
+ from py3dbl_core.Bin import Bin
3
+ from py3dbl_core.Item import Item
4
+ from py3dbl_core.Space import Volume
5
+
6
+ COLORS = ["cyan","red","yellow","blue","green","brown","magenta"]
7
+ BORDER_WIDTH = 1
8
+ BORDER_COLOR = "black"
9
+ TRANSPARENCY = .5
10
+
11
+ def render_volume_interactive(volume : Volume, fig : go.Figure, color : str, name : str = "", show_border : bool = True, border_width : float = BORDER_WIDTH, border_color : str = BORDER_COLOR, transparency : float = TRANSPARENCY):
12
+ """
13
+ An interactive 3D rendering of a volume object
14
+
15
+ :param volume: Target volume
16
+ :type volume: Volume
17
+ :param fig: A go figure as rendering target
18
+ :type fig: go.Figure
19
+ :param color: Color of the rendered volume
20
+ :type color: str
21
+ :param name: A name to associate to the volume
22
+ :type name: str
23
+ :param border_width: Size of the volume's border
24
+ :type border_width: float
25
+ :param border_color: Color of the volume's border
26
+ :type border_color: str
27
+ :param transparency: Transparency of the object
28
+ :type transparency: float
29
+ """
30
+ x, y, z = [float(value) for value in volume.position] # position from bottom-back-left corner
31
+ w, h, d = [float(value) for value in volume.size] # actual dimensions of the item (considered rotation)
32
+ fig.add_trace(go.Mesh3d(
33
+ x=[x, x+w, x+w, x, x, x+w, x+w, x],
34
+ z=[y, y, y+h, y+h, y, y, y+h, y+h],
35
+ y=[z, z, z, z, z+d, z+d, z+d, z+d],
36
+ contour_show = show_border,
37
+ contour_width= border_width,
38
+ contour_color= border_color,
39
+ color=color,
40
+ opacity= (1.0 - transparency),
41
+ name=name,
42
+ alphahull=0,
43
+ showscale=False
44
+ ))
45
+
46
+ def render_item_interactive(item : Item, fig : go.Figure, color : str, show_border : bool = True, border_width : float = BORDER_WIDTH, border_color : str = BORDER_COLOR, transparency : float = TRANSPARENCY):
47
+ render_volume_interactive(item,fig,color,item.name,show_border,border_width,border_color,transparency)
48
+
49
+ def render_bin_interactive(bin : Bin, colors : list[str] = COLORS, render_bin : bool = True, border_width : float = BORDER_WIDTH, border_color : str = BORDER_COLOR, transparency : float = TRANSPARENCY):
50
+
51
+ fig = go.Figure()
52
+
53
+ bin_render_params = {
54
+ "color": "lightgrey",
55
+ "name": "Bin",
56
+ "show_border": False
57
+ }
58
+
59
+ for dead_volume in bin._model.dead_volumes:
60
+ render_volume_interactive(volume=dead_volume,fig=fig,transparency=.1,**bin_render_params)
61
+
62
+ for idx,item in enumerate(bin.items):
63
+ render_item_interactive(item=item,fig=fig,color=colors[idx%len(colors)],border_width=border_width,border_color=border_color,transparency=transparency)
64
+
65
+ if render_bin:
66
+ render_volume_interactive(Volume(bin.dimensions),fig=fig,transparency=.9,**bin_render_params)
67
+
68
+ fig.update_layout(
69
+ scene=dict(
70
+ xaxis=dict(title='Width'),
71
+ zaxis=dict(title='Height'),
72
+ yaxis=dict(title='Depth'),
73
+ aspectmode='data'
74
+ ),
75
+ title=f"3D Packing Visualization - {bin}"
76
+ )
77
+
78
+ fig.show()
@@ -0,0 +1,21 @@
1
+ import py3dbl
2
+
3
+ packer = py3dbl.Packer(algorithm=py3dbl.algorithms['base_packer'])
4
+ packer.set_default_bin(py3dbl.BinModel(
5
+ name="Container",
6
+ size=[2,2,4],
7
+ max_weight=3000,
8
+ constraints=[
9
+ py3dbl.constraints['weight_within_limit'],
10
+ py3dbl.constraints['fits_inside_bin'],
11
+ py3dbl.constraints['no_overlap']
12
+ ],
13
+ ))
14
+ packer.add_batch(py3dbl.item_generator(
15
+ width=(.1,1),
16
+ height=(.1,1),
17
+ depth=(.1,1),
18
+ weight=(.1,1),
19
+ batch_size=100
20
+ ))
21
+ packer.pack()
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: py3dbl
3
+ Version: 1.0.0
4
+ Summary: A powerful tool for 3D bin packing problem solving
5
+ Author-email: Giuliano Pardini <giulianpardini@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Giulian7/py3dbl
8
+ Project-URL: Issues, https://github.com/Giulian7/py3dbl/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # About this project
17
+
18
+ This project is a complete
19
+
20
+ # How to run and test
21
+
22
+ 1. Clone this repository on your machine
23
+ 2. Create a virtual enviroment (e.g. *python3 -m venv "enviroment_name"*)
24
+ 3. Install the required packages as of *requirements.txt* (e.g. *pip install -r requirements.txt*)
25
+ 4. Execute *test.ipynb* and enjoy the visit (to execute a jupyter notebook simply run *jupyter notebook "notebook_name"*)
@@ -0,0 +1,20 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/py3dbl/__init__.py
5
+ src/py3dbl/benchmark.py
6
+ src/py3dbl/benchmarking.py
7
+ src/py3dbl/item_generator.py
8
+ src/py3dbl/render.py
9
+ src/py3dbl/using_py3dbl.py
10
+ src/py3dbl.egg-info/PKG-INFO
11
+ src/py3dbl.egg-info/SOURCES.txt
12
+ src/py3dbl.egg-info/dependency_links.txt
13
+ src/py3dbl.egg-info/top_level.txt
14
+ src/py3dbl_core/Algorithms.py
15
+ src/py3dbl_core/Bin.py
16
+ src/py3dbl_core/Constraints.py
17
+ src/py3dbl_core/Decimal.py
18
+ src/py3dbl_core/Item.py
19
+ src/py3dbl_core/Packer.py
20
+ src/py3dbl_core/Space.py
@@ -0,0 +1,2 @@
1
+ py3dbl
2
+ py3dbl_core