Skip to content

Commit 6b8bb3a

Browse files
authored
Merge pull request #24 from MiriamNagar/performance-improvement-addition
Triplet packing algorithm addition
2 parents e3cdb08 + f3d7598 commit 6b8bb3a

File tree

124 files changed

+23357
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+23357
-5
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6-
# C extensions
7-
*.so
8-
96
# Distribution / packaging
107
.Python
118
build/

examples/packing_algorithms.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,30 @@
2727
print("\nW, 75: ",prtpy.pack(algorithm=prtpy.packing.first_fit_decreasing, binsize=75, items=itemsW, outputtype=prtpy.out.PartitionAndSums))
2828
print("W, 76: ",prtpy.pack(algorithm=prtpy.packing.first_fit_decreasing, binsize=76, items=itemsW, outputtype=prtpy.out.PartitionAndSums))
2929

30+
# triplet packing algorithm demonstration
31+
# source article: ["Solution of Bin Packing Instances in Falkenauer T Class: Not So Hard"]
32+
print("\n\nBacktrack triplet packing method:\n")
33+
items=[
34+
369, 334, 297, 447, 302, 251, 409, 339, 252, 402,
35+
333, 265, 399, 347, 254, 462, 277, 261, 465, 280,
36+
255, 412, 313, 275, 444, 305, 251, 403, 308, 289,
37+
468, 270, 262, 426, 314, 260, 411, 307, 282, 382,
38+
361, 257, 396, 340, 264, 396, 304, 300, 473, 267,
39+
260, 475, 269, 256, 376, 366, 258, 423, 319, 258
40+
]
41+
bins = prtpy.pack(algorithm=prtpy.packing.triplet_packing, binsize=1000, items=items, outputtype=prtpy.out.PartitionAndSums)
42+
print(bins)
43+
44+
print("\n\nLocal search triplet packing method:\n")
45+
items = [
46+
495, 493, 485, 478, 477, 462, 461, 459, 456, 451,
47+
429, 426, 414, 405, 391, 378, 375, 371, 369, 368,
48+
367, 361, 357, 354, 347, 345, 332, 316, 298, 297,
49+
293, 293, 281, 281, 278, 278, 277, 277, 275, 273,
50+
270, 268, 265, 265, 263, 263, 262, 261, 261, 258,
51+
258, 257, 256, 255, 255, 254, 254, 252, 250, 250
52+
]
53+
kwargs={'use_local_search' : True}
54+
bins = prtpy.pack(algorithm=prtpy.packing.triplet_packing, binsize=1000, items=items, outputtype=prtpy.out.PartitionAndSums, **kwargs)
55+
print(bins)
56+
# check_triplet_bins(bins, 1000)

prtpy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class packing:
5858
from prtpy.packing.first_fit import online as first_fit, decreasing as first_fit_decreasing
5959
from prtpy.packing.first_fit import online as ff, decreasing as ffd
6060
from prtpy.packing.bin_completion import bin_completion
61+
from prtpy.packing.triplet_packing import triplet_packing
6162

6263
packing.first_fit.__name__ = "first-fit"
6364
packing.first_fit_decreasing.__name__ = "first-fit-decreasing"

prtpy/binners.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ def numbins(self, bins: BinsArray) -> int:
107107
"""
108108
return None
109109

110-
111-
112110
@abstractmethod
113111
def sums(self, bins: BinsArray) -> Tuple[float]:
114112
"""
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
120
2+
1000
3+
497
4+
497
5+
495
6+
485
7+
480
8+
478
9+
474
10+
473
11+
472
12+
470
13+
466
14+
450
15+
446
16+
445
17+
445
18+
444
19+
439
20+
434
21+
430
22+
420
23+
419
24+
414
25+
412
26+
410
27+
407
28+
405
29+
400
30+
397
31+
395
32+
376
33+
372
34+
370
35+
366
36+
366
37+
366
38+
366
39+
366
40+
363
41+
363
42+
362
43+
361
44+
357
45+
357
46+
356
47+
356
48+
355
49+
352
50+
351
51+
350
52+
350
53+
350
54+
347
55+
336
56+
333
57+
329
58+
325
59+
320
60+
315
61+
314
62+
313
63+
307
64+
303
65+
302
66+
301
67+
299
68+
298
69+
298
70+
298
71+
295
72+
294
73+
292
74+
290
75+
288
76+
287
77+
283
78+
282
79+
282
80+
276
81+
275
82+
275
83+
274
84+
273
85+
273
86+
272
87+
272
88+
271
89+
271
90+
269
91+
269
92+
268
93+
267
94+
267
95+
266
96+
263
97+
263
98+
262
99+
262
100+
261
101+
260
102+
259
103+
259
104+
259
105+
258
106+
256
107+
255
108+
254
109+
254
110+
254
111+
253
112+
253
113+
253
114+
253
115+
252
116+
252
117+
252
118+
252
119+
251
120+
251
121+
250
122+
250
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
120
2+
1000
3+
498
4+
496
5+
493
6+
491
7+
491
8+
485
9+
483
10+
465
11+
448
12+
444
13+
433
14+
432
15+
429
16+
427
17+
424
18+
421
19+
421
20+
414
21+
408
22+
406
23+
403
24+
402
25+
399
26+
398
27+
396
28+
393
29+
392
30+
389
31+
389
32+
383
33+
381
34+
380
35+
375
36+
372
37+
372
38+
368
39+
367
40+
366
41+
365
42+
365
43+
363
44+
363
45+
363
46+
357
47+
353
48+
353
49+
351
50+
347
51+
340
52+
338
53+
336
54+
335
55+
331
56+
330
57+
329
58+
328
59+
328
60+
325
61+
324
62+
322
63+
317
64+
316
65+
316
66+
313
67+
311
68+
311
69+
308
70+
308
71+
303
72+
303
73+
303
74+
298
75+
296
76+
296
77+
295
78+
295
79+
294
80+
292
81+
289
82+
289
83+
283
84+
282
85+
280
86+
279
87+
277
88+
276
89+
275
90+
271
91+
268
92+
268
93+
268
94+
266
95+
265
96+
265
97+
265
98+
262
99+
262
100+
260
101+
260
102+
260
103+
259
104+
259
105+
259
106+
259
107+
257
108+
256
109+
255
110+
254
111+
254
112+
253
113+
253
114+
252
115+
252
116+
251
117+
251
118+
251
119+
250
120+
250
121+
250
122+
250

0 commit comments

Comments
 (0)