Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change layout #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/PSACodeSprint.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions CSVParser/3DBinPacker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import random
import csv

from py3dbp import Packer, Bin, Item, Painter

COLORS = ["yellow", "olive", "pink", "brown", "red", "blue", "green", "purple", "orange", "gray"]
# Initialize variables to store bins and items
bins = []
bin_size = -1
items = []
item_size = 0
counter = 0

# Parse through the CSV file
with open('testval3.csv', mode='r', encoding='utf-8-sig') as csv_file:
csv_reader = csv.reader(csv_file)
# Iterate through the rows and parse bins and items
for row in csv_reader:
# Check if the row is empty
if not any(row):
continue

# If there is a single number in the row, it represents the number of bins or items
if row[1] == "":
num = int(row[0])
if bin_size == -1:
bin_size = num
counter = bin_size
else:
item_size = num
else:
a = row[0]
b = row[1]
values = tuple(int(val) for val in row if val)
if counter > 0:
bins.append(values)
counter -= 1
else:
items.append(values)

# init packing function
packer = Packer()
# init bin
for i in range(len(bins)):
box = Bin('Bin{}'.format(str(i+1)), bins[i], 100, 0, 0)
packer.addBin(box)

# add item
for i in range(len(items)):
packer.addItem(Item(
partno='Box-{}'.format(str(i+1)),
name='test{}'.format(str(i+1)),
typeof='cube',
WHD=items[i],
weight=1,
level=1,
loadbear=100,
updown=True,
color=random.choice(COLORS)
)
)

# calculate packing
packer.pack(
bigger_first=True,
distribute_items=True,
fix_point=True,
check_stable=True,
support_surface_ratio=0.75,
number_of_decimals=0
)

# put order
packer.putOrder()

output = "***************************************************\n"
for idx, b in enumerate(packer.bins):
output += f"** {b.string()} **\n"
output += "***************************************************\n"
output += "FITTED ITEMS:\n"
output += "***************************************************\n"
volume = b.width * b.height * b.depth
volume_t = 0
volume_f = 0
unfitted_name = ''
for item in b.items:
output += f"partno : {item.partno}\n"
output += f"position : {item.position}\n"
output += f"W*H*D : {item.width} * {item.height} * {item.depth}\n"
output += f"volume : {float(item.width) * float(item.height) * float(item.depth)}\n"
volume_t += float(item.width) * float(item.height) * float(item.depth)
output += "***************************************************\n"

output += f'space utilization : {round(volume_t / float(volume) * 100, 2)}%\n'
output += f'residual volume : {float(volume) - volume_t}\n'
output += "***************************************************\n"
# draw results
painter = Painter(b)
fig = painter.plotBoxAndItems(
title=b.partno,
alpha=0.8,
write_num=False,
fontsize=10
)

output += "***************************************************\n"
output += "UNFITTED ITEMS:\n"
for item in packer.unfit_items:
output += "***************************************************\n"
output += f"partno : {item.partno}\n"
output += f"W*H*D : {item.width} * {item.height} * {item.depth}\n"
output += f"volume : {float(item.width) * float(item.height) * float(item.depth)}\n"
volume_f += float(item.width) * float(item.height) * float(item.depth)
unfitted_name += f'{item.partno},'
output += "***************************************************\n"
output += "***************************************************\n"
output += f'unpacked items : {unfitted_name}\n'
output += f'unpacked items volume : {volume_f}\n'

# Print the entire output
print(output)

fig.show()
36 changes: 36 additions & 0 deletions CSVParser/testval.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
2,,
5,10,5
6,10,6
32,,
5,4,1
1,2,4
1,2,3
1,2,2
1,2,3
1,2,4
1,2,2
1,2,4
1,2,3
1,2,2
5,4,1
1,1,4
1,2,1
1,2,1
1,1,4
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,1
5,4,1
5,4,1
5,4,1
5,4,1
5,4,1
20 changes: 20 additions & 0 deletions CSVParser/testval2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
2,,
5,10,5
6,10,6
16,,
5,4,1
1,2,4
1,2,3
1,2,2
1,2,3
1,2,4
1,2,2
1,2,4
1,2,3
1,2,2
5,4,1
1,1,4
1,2,1
1,2,1
1,1,4
5,4,2
37 changes: 37 additions & 0 deletions CSVParser/testval3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
3,,
5,10,5
5,10,5
5,10,5
32,,
5,4,1
1,2,4
1,2,3
1,2,2
1,2,3
1,2,4
1,2,2
1,2,4
1,2,3
1,2,2
5,4,1
1,1,4
1,2,1
1,2,1
1,1,4
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,2
5,4,1
5,4,1
5,4,1
5,4,1
5,4,1
5,4,1
Loading