py3dbc 1.0.0__tar.gz → 1.0.2__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.
- py3dbc-1.0.2/PKG-INFO +369 -0
- py3dbc-1.0.2/README.md +326 -0
- py3dbc-1.0.2/py3dbc.egg-info/PKG-INFO +369 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/setup.py +2 -2
- py3dbc-1.0.0/PKG-INFO +0 -259
- py3dbc-1.0.0/README.md +0 -216
- py3dbc-1.0.0/py3dbc.egg-info/PKG-INFO +0 -259
- {py3dbc-1.0.0 → py3dbc-1.0.2}/LICENSE +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/__init__.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/maritime/__init__.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/maritime/constraints.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/maritime/container.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/maritime/packer.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/maritime/ship.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/physics/__init__.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc/physics/stability.py +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc.egg-info/SOURCES.txt +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc.egg-info/dependency_links.txt +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc.egg-info/requires.txt +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/py3dbc.egg-info/top_level.txt +0 -0
- {py3dbc-1.0.0 → py3dbc-1.0.2}/setup.cfg +0 -0
py3dbc-1.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py3dbc
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: 3D Bin Packing for Containers - Maritime optimization with ship stability physics
|
|
5
|
+
Home-page: https://github.com/SarthSatpute/py3dbc
|
|
6
|
+
Author: Sarth Satpute
|
|
7
|
+
Author-email: sarthsatpute18@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/SarthSatpute/py3dbc/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/SarthSatpute/py3dbc#readme
|
|
11
|
+
Project-URL: Source Code, https://github.com/SarthSatpute/py3dbc
|
|
12
|
+
Keywords: 3d-bin-packing,container-optimization,maritime,ship-stability,logistics,cargo
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Operating System :: OS Independent
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: py3dbp>=1.1.0
|
|
28
|
+
Requires-Dist: pandas>=1.3.0
|
|
29
|
+
Requires-Dist: numpy>=1.21.0
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: author-email
|
|
32
|
+
Dynamic: classifier
|
|
33
|
+
Dynamic: description
|
|
34
|
+
Dynamic: description-content-type
|
|
35
|
+
Dynamic: home-page
|
|
36
|
+
Dynamic: keywords
|
|
37
|
+
Dynamic: license
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: project-url
|
|
40
|
+
Dynamic: requires-dist
|
|
41
|
+
Dynamic: requires-python
|
|
42
|
+
Dynamic: summary
|
|
43
|
+
|
|
44
|
+
# py3dbc
|
|
45
|
+
|
|
46
|
+
**3D Bin Packing for Container Ships**
|
|
47
|
+
|
|
48
|
+
Maritime cargo optimization library with physics-based stability validation.
|
|
49
|
+
|
|
50
|
+
[](https://opensource.org/licenses/MIT)
|
|
51
|
+
[](https://www.python.org/downloads/)
|
|
52
|
+
[](https://pypi.org/project/py3dbc/)
|
|
53
|
+
[](https://pepy.tech/project/py3dbc)
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Overview
|
|
58
|
+
|
|
59
|
+
**py3dbc** (3D Bin Packing for Containers) extends the [py3dbp](https://github.com/jerry800416/3D-bin-packing) library with maritime-specific constraints and naval architecture physics for container ship cargo optimization.
|
|
60
|
+
|
|
61
|
+
While py3dbp handles general 3D bin packing, it doesn't account for ship stability physics or maritime safety regulations. py3dbc addresses this gap by integrating metacentric height (GM) calculations, hazmat separation rules, and regulatory compliance checks.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Key Features
|
|
66
|
+
|
|
67
|
+
### Ship Stability Validation
|
|
68
|
+
- Real-time metacentric height (GM) calculation using naval architecture principles
|
|
69
|
+
- Dynamic center of gravity (KG) tracking during container placement
|
|
70
|
+
- Automatic rejection of placements that would compromise ship stability
|
|
71
|
+
- Compliance with IMO stability standards (GM ≥ 0.3m)
|
|
72
|
+
|
|
73
|
+
### Maritime Safety Constraints
|
|
74
|
+
- **Hazmat Separation:** Enforces minimum Manhattan distance between dangerous goods
|
|
75
|
+
- **Reefer Power Allocation:** Assigns refrigerated containers only to powered slots
|
|
76
|
+
- **Weight Distribution:** Validates tier capacity and stack limits
|
|
77
|
+
- **Regulatory Compliance:** Ensures adherence to maritime safety standards
|
|
78
|
+
|
|
79
|
+
### Container Classification
|
|
80
|
+
- General cargo (standard dry containers)
|
|
81
|
+
- Reefer containers (temperature-controlled, require power)
|
|
82
|
+
- Hazmat containers (dangerous goods with separation requirements)
|
|
83
|
+
- Automatic TEU calculation (20ft = 1 TEU, 40ft = 2 TEU)
|
|
84
|
+
|
|
85
|
+
### Realistic Ship Modeling
|
|
86
|
+
- Discrete bay-row-tier slot grid matching actual ship geometry
|
|
87
|
+
- 3D spatial coordinates for visualization
|
|
88
|
+
- Stack weight tracking per position
|
|
89
|
+
- Support for variable ship configurations
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Installation
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install py3dbc
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Requirements:** Python 3.8+
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Quick Start
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from py3dbc.maritime.ship import ContainerShip
|
|
107
|
+
from py3dbc.maritime.container import MaritimeContainer
|
|
108
|
+
from py3dbc.maritime.packer import MaritimePacker
|
|
109
|
+
|
|
110
|
+
# Initialize ship with stability parameters
|
|
111
|
+
ship = ContainerShip(
|
|
112
|
+
ship_name='FEEDER_01',
|
|
113
|
+
dimensions=(100, 20, 15),
|
|
114
|
+
bays=7,
|
|
115
|
+
rows=14,
|
|
116
|
+
tiers=7,
|
|
117
|
+
stability_params={
|
|
118
|
+
'kg_lightship': 6.5,
|
|
119
|
+
'lightship_weight': 3500,
|
|
120
|
+
'kb': 4.2,
|
|
121
|
+
'bm': 4.5,
|
|
122
|
+
'gm_min': 0.3
|
|
123
|
+
},
|
|
124
|
+
max_weight=8000
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# Define containers
|
|
128
|
+
containers = [
|
|
129
|
+
MaritimeContainer(
|
|
130
|
+
container_id='GEN001',
|
|
131
|
+
teu_size='20ft',
|
|
132
|
+
cargo_type='general',
|
|
133
|
+
total_weight=22.5,
|
|
134
|
+
dimensions=(6.1, 2.4, 2.6)
|
|
135
|
+
),
|
|
136
|
+
MaritimeContainer(
|
|
137
|
+
container_id='REF001',
|
|
138
|
+
teu_size='20ft',
|
|
139
|
+
cargo_type='reefer',
|
|
140
|
+
total_weight=18.0,
|
|
141
|
+
dimensions=(6.1, 2.4, 2.6)
|
|
142
|
+
),
|
|
143
|
+
MaritimeContainer(
|
|
144
|
+
container_id='HAZ001',
|
|
145
|
+
teu_size='20ft',
|
|
146
|
+
cargo_type='hazmat',
|
|
147
|
+
total_weight=14.5,
|
|
148
|
+
dimensions=(6.1, 2.4, 2.6),
|
|
149
|
+
hazmat_class='Class_3'
|
|
150
|
+
)
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
# Run optimization
|
|
154
|
+
packer = MaritimePacker(ship, gm_threshold=0.3, hazmat_separation=3)
|
|
155
|
+
result = packer.pack(containers, strategy='heavy_first')
|
|
156
|
+
|
|
157
|
+
# Analyze results
|
|
158
|
+
print(f"Placement Success Rate: {result['metrics']['placement_rate']:.1f}%")
|
|
159
|
+
print(f"Ship Stability: {'STABLE' if result['metrics']['is_stable'] else 'UNSTABLE'}")
|
|
160
|
+
print(f"Final GM: {result['metrics']['gm']:.2f}m")
|
|
161
|
+
print(f"Slot Utilization: {result['metrics']['slot_utilization']:.1f}%")
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## How It Works
|
|
167
|
+
|
|
168
|
+
### Stability Physics
|
|
169
|
+
|
|
170
|
+
py3dbc calculates metacentric height using fundamental naval architecture equations:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
GM = KB + BM - KG
|
|
174
|
+
|
|
175
|
+
Where:
|
|
176
|
+
KB = Vertical center of buoyancy (ship constant)
|
|
177
|
+
BM = Metacentric radius (function of ship geometry)
|
|
178
|
+
KG = Vertical center of gravity (updated per placement)
|
|
179
|
+
|
|
180
|
+
Stability Criterion: GM ≥ GM_min (typically 0.3m for container ships)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The center of gravity is recalculated after each container placement using the moment-summation method, ensuring real-time stability validation throughout the packing process.
|
|
184
|
+
|
|
185
|
+
### Optimization Algorithm
|
|
186
|
+
|
|
187
|
+
The packing algorithm follows a greedy heuristic approach with constraint validation:
|
|
188
|
+
|
|
189
|
+
1. **Sort containers** by selected strategy (heavy_first, priority, or hazmat_first)
|
|
190
|
+
2. **For each container:**
|
|
191
|
+
- Identify all available slots matching size requirements
|
|
192
|
+
- Filter slots by hard constraints (weight limits, power availability, hazmat separation)
|
|
193
|
+
- Validate stability impact of each candidate placement
|
|
194
|
+
- Score remaining slots using weighted heuristics (tier preference, centerline proximity, stability margin)
|
|
195
|
+
- Place container in highest-scoring valid slot
|
|
196
|
+
3. **Update ship state** (weight distribution, GM, slot occupancy)
|
|
197
|
+
4. **Continue** until all containers placed or no valid slots remain
|
|
198
|
+
|
|
199
|
+
### Constraint Validation
|
|
200
|
+
|
|
201
|
+
**Weight Constraints:**
|
|
202
|
+
```python
|
|
203
|
+
Container weight ≤ Tier capacity
|
|
204
|
+
Stack weight ≤ Maximum stack limit (decreases with height)
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Hazmat Separation:**
|
|
208
|
+
```python
|
|
209
|
+
Manhattan distance = |bay₁ - bay₂| + |row₁ - row₂| + |tier₁ - tier₂|
|
|
210
|
+
Distance ≥ Minimum separation (default: 3 slots)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**Reefer Power:**
|
|
214
|
+
```python
|
|
215
|
+
Reefer containers → Only slots with power_available = True
|
|
216
|
+
General/Hazmat → Any available slot
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Performance
|
|
222
|
+
|
|
223
|
+
Validated on synthetic maritime scenarios:
|
|
224
|
+
|
|
225
|
+
| Metric | Result |
|
|
226
|
+
|--------|--------|
|
|
227
|
+
| Placement Success Rate | 91.1% |
|
|
228
|
+
| Slot Utilization | 83.9% |
|
|
229
|
+
| Stability Compliance | 100% |
|
|
230
|
+
| Processing Speed | <2s for 600+ containers |
|
|
231
|
+
|
|
232
|
+
Comparison with manual planning: 20-30% improvement in utilization while maintaining 100% stability compliance.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Use Cases
|
|
237
|
+
|
|
238
|
+
- **Port Terminal Operations:** Automated generation of container loading plans
|
|
239
|
+
- **Maritime Logistics:** Pre-voyage cargo optimization and stowage planning
|
|
240
|
+
- **Safety Validation:** Verification of manual load plans against stability requirements
|
|
241
|
+
- **Training and Education:** Demonstration of naval architecture principles and constraint optimization
|
|
242
|
+
- **Research:** Algorithm development for maritime optimization problems
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## API Reference
|
|
247
|
+
|
|
248
|
+
### Core Classes
|
|
249
|
+
|
|
250
|
+
#### `MaritimeContainer`
|
|
251
|
+
|
|
252
|
+
Extends py3dbp's `Item` class with maritime-specific attributes.
|
|
253
|
+
|
|
254
|
+
**Parameters:**
|
|
255
|
+
- `container_id` (str): Unique container identifier
|
|
256
|
+
- `teu_size` (str): '20ft' or '40ft'
|
|
257
|
+
- `cargo_type` (str): 'general', 'reefer', or 'hazmat'
|
|
258
|
+
- `total_weight` (float): Container weight in tonnes
|
|
259
|
+
- `dimensions` (tuple): (length, width, height) in meters
|
|
260
|
+
- `hazmat_class` (str, optional): Hazmat classification if applicable
|
|
261
|
+
- `loading_priority` (int, optional): Priority level for placement
|
|
262
|
+
|
|
263
|
+
#### `ContainerShip`
|
|
264
|
+
|
|
265
|
+
Extends py3dbp's `Bin` class with ship-specific structure and stability parameters.
|
|
266
|
+
|
|
267
|
+
**Parameters:**
|
|
268
|
+
- `ship_name` (str): Ship identifier
|
|
269
|
+
- `dimensions` (tuple): (length, beam, depth) in meters
|
|
270
|
+
- `bays` (int): Number of longitudinal sections
|
|
271
|
+
- `rows` (int): Number of transverse positions
|
|
272
|
+
- `tiers` (int): Number of vertical levels
|
|
273
|
+
- `stability_params` (dict): Naval architecture constants
|
|
274
|
+
- `max_weight` (float): Deadweight capacity in tonnes
|
|
275
|
+
|
|
276
|
+
#### `MaritimePacker`
|
|
277
|
+
|
|
278
|
+
Main optimization engine with integrated constraint validation.
|
|
279
|
+
|
|
280
|
+
**Parameters:**
|
|
281
|
+
- `ship` (ContainerShip): Ship instance to pack
|
|
282
|
+
- `gm_threshold` (float): Minimum acceptable GM in meters
|
|
283
|
+
- `hazmat_separation` (int): Minimum slot distance between hazmat containers
|
|
284
|
+
|
|
285
|
+
**Methods:**
|
|
286
|
+
- `pack(containers, strategy)`: Execute packing algorithm
|
|
287
|
+
- Returns: Dictionary with placement results and metrics
|
|
288
|
+
|
|
289
|
+
**Available Strategies:**
|
|
290
|
+
- `'heavy_first'`: Sort by weight (descending)
|
|
291
|
+
- `'priority'`: Sort by loading priority
|
|
292
|
+
- `'hazmat_first'`: Place hazmat containers first
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## Advanced Usage
|
|
297
|
+
|
|
298
|
+
### Custom Scoring Function
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
# Modify slot scoring weights
|
|
302
|
+
packer = MaritimePacker(ship, gm_threshold=0.3)
|
|
303
|
+
packer.tier_weight = 0.4 # Prefer lower tiers
|
|
304
|
+
packer.stability_weight = 0.3 # Balance stability
|
|
305
|
+
packer.centerline_weight = 0.2 # Prefer centerline
|
|
306
|
+
packer.bay_weight = 0.1 # Forward placement preference
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Multi-Strategy Optimization
|
|
310
|
+
|
|
311
|
+
```python
|
|
312
|
+
strategies = ['heavy_first', 'priority', 'hazmat_first']
|
|
313
|
+
results = []
|
|
314
|
+
|
|
315
|
+
for strategy in strategies:
|
|
316
|
+
result = packer.pack(containers.copy(), strategy=strategy)
|
|
317
|
+
results.append(result)
|
|
318
|
+
|
|
319
|
+
# Select best result by placement rate
|
|
320
|
+
best_result = max(results, key=lambda r: r['metrics']['placement_rate'])
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) file for details.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Citation
|
|
333
|
+
|
|
334
|
+
If you use py3dbc in academic research, please cite:
|
|
335
|
+
|
|
336
|
+
```bibtex
|
|
337
|
+
@software{py3dbc2025,
|
|
338
|
+
author = {Satpute Sarth, Pardeshi Pranav},
|
|
339
|
+
title = {py3dbc: 3D Bin Packing for Container Ships},
|
|
340
|
+
year = {2025},
|
|
341
|
+
publisher = {PyPI},
|
|
342
|
+
url = {https://pypi.org/project/py3dbc/}
|
|
343
|
+
}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## Support
|
|
349
|
+
|
|
350
|
+
- **Documentation:** [GitHub Repository](https://github.com/SarthSatpute/py3dbc)
|
|
351
|
+
- **Issues:** [GitHub Issues](https://github.com/SarthSatpute/py3dbc/issues)
|
|
352
|
+
- **Discussions:** [GitHub Discussions](https://github.com/SarthSatpute/py3dbc/discussions)
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Related Projects
|
|
357
|
+
|
|
358
|
+
- **CargoOptix:** Full-stack web application using py3dbc for interactive cargo optimization
|
|
359
|
+
- **py3dbp:** Base library for general 3D bin packing (credit to original authors)
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Acknowledgments
|
|
364
|
+
|
|
365
|
+
Built upon the [py3dbp](https://github.com/jerry800416/3D-bin-packing) library by jerry800416.
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
**If you find this library useful, please consider starring the repository.**
|
py3dbc-1.0.2/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# py3dbc
|
|
2
|
+
|
|
3
|
+
**3D Bin Packing for Container Ships**
|
|
4
|
+
|
|
5
|
+
Maritime cargo optimization library with physics-based stability validation.
|
|
6
|
+
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
[](https://www.python.org/downloads/)
|
|
9
|
+
[](https://pypi.org/project/py3dbc/)
|
|
10
|
+
[](https://pepy.tech/project/py3dbc)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
**py3dbc** (3D Bin Packing for Containers) extends the [py3dbp](https://github.com/jerry800416/3D-bin-packing) library with maritime-specific constraints and naval architecture physics for container ship cargo optimization.
|
|
17
|
+
|
|
18
|
+
While py3dbp handles general 3D bin packing, it doesn't account for ship stability physics or maritime safety regulations. py3dbc addresses this gap by integrating metacentric height (GM) calculations, hazmat separation rules, and regulatory compliance checks.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Key Features
|
|
23
|
+
|
|
24
|
+
### Ship Stability Validation
|
|
25
|
+
- Real-time metacentric height (GM) calculation using naval architecture principles
|
|
26
|
+
- Dynamic center of gravity (KG) tracking during container placement
|
|
27
|
+
- Automatic rejection of placements that would compromise ship stability
|
|
28
|
+
- Compliance with IMO stability standards (GM ≥ 0.3m)
|
|
29
|
+
|
|
30
|
+
### Maritime Safety Constraints
|
|
31
|
+
- **Hazmat Separation:** Enforces minimum Manhattan distance between dangerous goods
|
|
32
|
+
- **Reefer Power Allocation:** Assigns refrigerated containers only to powered slots
|
|
33
|
+
- **Weight Distribution:** Validates tier capacity and stack limits
|
|
34
|
+
- **Regulatory Compliance:** Ensures adherence to maritime safety standards
|
|
35
|
+
|
|
36
|
+
### Container Classification
|
|
37
|
+
- General cargo (standard dry containers)
|
|
38
|
+
- Reefer containers (temperature-controlled, require power)
|
|
39
|
+
- Hazmat containers (dangerous goods with separation requirements)
|
|
40
|
+
- Automatic TEU calculation (20ft = 1 TEU, 40ft = 2 TEU)
|
|
41
|
+
|
|
42
|
+
### Realistic Ship Modeling
|
|
43
|
+
- Discrete bay-row-tier slot grid matching actual ship geometry
|
|
44
|
+
- 3D spatial coordinates for visualization
|
|
45
|
+
- Stack weight tracking per position
|
|
46
|
+
- Support for variable ship configurations
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install py3dbc
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Requirements:** Python 3.8+
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Quick Start
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from py3dbc.maritime.ship import ContainerShip
|
|
64
|
+
from py3dbc.maritime.container import MaritimeContainer
|
|
65
|
+
from py3dbc.maritime.packer import MaritimePacker
|
|
66
|
+
|
|
67
|
+
# Initialize ship with stability parameters
|
|
68
|
+
ship = ContainerShip(
|
|
69
|
+
ship_name='FEEDER_01',
|
|
70
|
+
dimensions=(100, 20, 15),
|
|
71
|
+
bays=7,
|
|
72
|
+
rows=14,
|
|
73
|
+
tiers=7,
|
|
74
|
+
stability_params={
|
|
75
|
+
'kg_lightship': 6.5,
|
|
76
|
+
'lightship_weight': 3500,
|
|
77
|
+
'kb': 4.2,
|
|
78
|
+
'bm': 4.5,
|
|
79
|
+
'gm_min': 0.3
|
|
80
|
+
},
|
|
81
|
+
max_weight=8000
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# Define containers
|
|
85
|
+
containers = [
|
|
86
|
+
MaritimeContainer(
|
|
87
|
+
container_id='GEN001',
|
|
88
|
+
teu_size='20ft',
|
|
89
|
+
cargo_type='general',
|
|
90
|
+
total_weight=22.5,
|
|
91
|
+
dimensions=(6.1, 2.4, 2.6)
|
|
92
|
+
),
|
|
93
|
+
MaritimeContainer(
|
|
94
|
+
container_id='REF001',
|
|
95
|
+
teu_size='20ft',
|
|
96
|
+
cargo_type='reefer',
|
|
97
|
+
total_weight=18.0,
|
|
98
|
+
dimensions=(6.1, 2.4, 2.6)
|
|
99
|
+
),
|
|
100
|
+
MaritimeContainer(
|
|
101
|
+
container_id='HAZ001',
|
|
102
|
+
teu_size='20ft',
|
|
103
|
+
cargo_type='hazmat',
|
|
104
|
+
total_weight=14.5,
|
|
105
|
+
dimensions=(6.1, 2.4, 2.6),
|
|
106
|
+
hazmat_class='Class_3'
|
|
107
|
+
)
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
# Run optimization
|
|
111
|
+
packer = MaritimePacker(ship, gm_threshold=0.3, hazmat_separation=3)
|
|
112
|
+
result = packer.pack(containers, strategy='heavy_first')
|
|
113
|
+
|
|
114
|
+
# Analyze results
|
|
115
|
+
print(f"Placement Success Rate: {result['metrics']['placement_rate']:.1f}%")
|
|
116
|
+
print(f"Ship Stability: {'STABLE' if result['metrics']['is_stable'] else 'UNSTABLE'}")
|
|
117
|
+
print(f"Final GM: {result['metrics']['gm']:.2f}m")
|
|
118
|
+
print(f"Slot Utilization: {result['metrics']['slot_utilization']:.1f}%")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## How It Works
|
|
124
|
+
|
|
125
|
+
### Stability Physics
|
|
126
|
+
|
|
127
|
+
py3dbc calculates metacentric height using fundamental naval architecture equations:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
GM = KB + BM - KG
|
|
131
|
+
|
|
132
|
+
Where:
|
|
133
|
+
KB = Vertical center of buoyancy (ship constant)
|
|
134
|
+
BM = Metacentric radius (function of ship geometry)
|
|
135
|
+
KG = Vertical center of gravity (updated per placement)
|
|
136
|
+
|
|
137
|
+
Stability Criterion: GM ≥ GM_min (typically 0.3m for container ships)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The center of gravity is recalculated after each container placement using the moment-summation method, ensuring real-time stability validation throughout the packing process.
|
|
141
|
+
|
|
142
|
+
### Optimization Algorithm
|
|
143
|
+
|
|
144
|
+
The packing algorithm follows a greedy heuristic approach with constraint validation:
|
|
145
|
+
|
|
146
|
+
1. **Sort containers** by selected strategy (heavy_first, priority, or hazmat_first)
|
|
147
|
+
2. **For each container:**
|
|
148
|
+
- Identify all available slots matching size requirements
|
|
149
|
+
- Filter slots by hard constraints (weight limits, power availability, hazmat separation)
|
|
150
|
+
- Validate stability impact of each candidate placement
|
|
151
|
+
- Score remaining slots using weighted heuristics (tier preference, centerline proximity, stability margin)
|
|
152
|
+
- Place container in highest-scoring valid slot
|
|
153
|
+
3. **Update ship state** (weight distribution, GM, slot occupancy)
|
|
154
|
+
4. **Continue** until all containers placed or no valid slots remain
|
|
155
|
+
|
|
156
|
+
### Constraint Validation
|
|
157
|
+
|
|
158
|
+
**Weight Constraints:**
|
|
159
|
+
```python
|
|
160
|
+
Container weight ≤ Tier capacity
|
|
161
|
+
Stack weight ≤ Maximum stack limit (decreases with height)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Hazmat Separation:**
|
|
165
|
+
```python
|
|
166
|
+
Manhattan distance = |bay₁ - bay₂| + |row₁ - row₂| + |tier₁ - tier₂|
|
|
167
|
+
Distance ≥ Minimum separation (default: 3 slots)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Reefer Power:**
|
|
171
|
+
```python
|
|
172
|
+
Reefer containers → Only slots with power_available = True
|
|
173
|
+
General/Hazmat → Any available slot
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Performance
|
|
179
|
+
|
|
180
|
+
Validated on synthetic maritime scenarios:
|
|
181
|
+
|
|
182
|
+
| Metric | Result |
|
|
183
|
+
|--------|--------|
|
|
184
|
+
| Placement Success Rate | 91.1% |
|
|
185
|
+
| Slot Utilization | 83.9% |
|
|
186
|
+
| Stability Compliance | 100% |
|
|
187
|
+
| Processing Speed | <2s for 600+ containers |
|
|
188
|
+
|
|
189
|
+
Comparison with manual planning: 20-30% improvement in utilization while maintaining 100% stability compliance.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Use Cases
|
|
194
|
+
|
|
195
|
+
- **Port Terminal Operations:** Automated generation of container loading plans
|
|
196
|
+
- **Maritime Logistics:** Pre-voyage cargo optimization and stowage planning
|
|
197
|
+
- **Safety Validation:** Verification of manual load plans against stability requirements
|
|
198
|
+
- **Training and Education:** Demonstration of naval architecture principles and constraint optimization
|
|
199
|
+
- **Research:** Algorithm development for maritime optimization problems
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## API Reference
|
|
204
|
+
|
|
205
|
+
### Core Classes
|
|
206
|
+
|
|
207
|
+
#### `MaritimeContainer`
|
|
208
|
+
|
|
209
|
+
Extends py3dbp's `Item` class with maritime-specific attributes.
|
|
210
|
+
|
|
211
|
+
**Parameters:**
|
|
212
|
+
- `container_id` (str): Unique container identifier
|
|
213
|
+
- `teu_size` (str): '20ft' or '40ft'
|
|
214
|
+
- `cargo_type` (str): 'general', 'reefer', or 'hazmat'
|
|
215
|
+
- `total_weight` (float): Container weight in tonnes
|
|
216
|
+
- `dimensions` (tuple): (length, width, height) in meters
|
|
217
|
+
- `hazmat_class` (str, optional): Hazmat classification if applicable
|
|
218
|
+
- `loading_priority` (int, optional): Priority level for placement
|
|
219
|
+
|
|
220
|
+
#### `ContainerShip`
|
|
221
|
+
|
|
222
|
+
Extends py3dbp's `Bin` class with ship-specific structure and stability parameters.
|
|
223
|
+
|
|
224
|
+
**Parameters:**
|
|
225
|
+
- `ship_name` (str): Ship identifier
|
|
226
|
+
- `dimensions` (tuple): (length, beam, depth) in meters
|
|
227
|
+
- `bays` (int): Number of longitudinal sections
|
|
228
|
+
- `rows` (int): Number of transverse positions
|
|
229
|
+
- `tiers` (int): Number of vertical levels
|
|
230
|
+
- `stability_params` (dict): Naval architecture constants
|
|
231
|
+
- `max_weight` (float): Deadweight capacity in tonnes
|
|
232
|
+
|
|
233
|
+
#### `MaritimePacker`
|
|
234
|
+
|
|
235
|
+
Main optimization engine with integrated constraint validation.
|
|
236
|
+
|
|
237
|
+
**Parameters:**
|
|
238
|
+
- `ship` (ContainerShip): Ship instance to pack
|
|
239
|
+
- `gm_threshold` (float): Minimum acceptable GM in meters
|
|
240
|
+
- `hazmat_separation` (int): Minimum slot distance between hazmat containers
|
|
241
|
+
|
|
242
|
+
**Methods:**
|
|
243
|
+
- `pack(containers, strategy)`: Execute packing algorithm
|
|
244
|
+
- Returns: Dictionary with placement results and metrics
|
|
245
|
+
|
|
246
|
+
**Available Strategies:**
|
|
247
|
+
- `'heavy_first'`: Sort by weight (descending)
|
|
248
|
+
- `'priority'`: Sort by loading priority
|
|
249
|
+
- `'hazmat_first'`: Place hazmat containers first
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Advanced Usage
|
|
254
|
+
|
|
255
|
+
### Custom Scoring Function
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
# Modify slot scoring weights
|
|
259
|
+
packer = MaritimePacker(ship, gm_threshold=0.3)
|
|
260
|
+
packer.tier_weight = 0.4 # Prefer lower tiers
|
|
261
|
+
packer.stability_weight = 0.3 # Balance stability
|
|
262
|
+
packer.centerline_weight = 0.2 # Prefer centerline
|
|
263
|
+
packer.bay_weight = 0.1 # Forward placement preference
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Multi-Strategy Optimization
|
|
267
|
+
|
|
268
|
+
```python
|
|
269
|
+
strategies = ['heavy_first', 'priority', 'hazmat_first']
|
|
270
|
+
results = []
|
|
271
|
+
|
|
272
|
+
for strategy in strategies:
|
|
273
|
+
result = packer.pack(containers.copy(), strategy=strategy)
|
|
274
|
+
results.append(result)
|
|
275
|
+
|
|
276
|
+
# Select best result by placement rate
|
|
277
|
+
best_result = max(results, key=lambda r: r['metrics']['placement_rate'])
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
This project is licensed under the MIT License. See [LICENSE](LICENSE) file for details.
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## Citation
|
|
290
|
+
|
|
291
|
+
If you use py3dbc in academic research, please cite:
|
|
292
|
+
|
|
293
|
+
```bibtex
|
|
294
|
+
@software{py3dbc2025,
|
|
295
|
+
author = {Satpute Sarth, Pardeshi Pranav},
|
|
296
|
+
title = {py3dbc: 3D Bin Packing for Container Ships},
|
|
297
|
+
year = {2025},
|
|
298
|
+
publisher = {PyPI},
|
|
299
|
+
url = {https://pypi.org/project/py3dbc/}
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Support
|
|
306
|
+
|
|
307
|
+
- **Documentation:** [GitHub Repository](https://github.com/SarthSatpute/py3dbc)
|
|
308
|
+
- **Issues:** [GitHub Issues](https://github.com/SarthSatpute/py3dbc/issues)
|
|
309
|
+
- **Discussions:** [GitHub Discussions](https://github.com/SarthSatpute/py3dbc/discussions)
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
## Related Projects
|
|
314
|
+
|
|
315
|
+
- **CargoOptix:** Full-stack web application using py3dbc for interactive cargo optimization
|
|
316
|
+
- **py3dbp:** Base library for general 3D bin packing (credit to original authors)
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## Acknowledgments
|
|
321
|
+
|
|
322
|
+
Built upon the [py3dbp](https://github.com/jerry800416/3D-bin-packing) library by jerry800416.
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
**If you find this library useful, please consider starring the repository.**
|