-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule2TransToPhp.bas
More file actions
2774 lines (2020 loc) · 132 KB
/
module2TransToPhp.bas
File metadata and controls
2774 lines (2020 loc) · 132 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' Attribute VB_Name = "Module2"
' 'This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/.
' Option Explicit
' Const epsilon As Double = 0.0001
' Const column_offset As Long = 11
' 'data declarations
' Private Type item_type_data
' id As Long
' width As Double
' height As Double
' length As Double
' volume As Double
' weight As Double
' xy_rotatable As Boolean
' yz_rotatable As Boolean
' heavy As Boolean
' fragile As Boolean
' mandatory As Long
' profit As Double
' number_requested As Long
' sort_criterion As Double
' End Type
' Private Type item_list_data
' num_item_types As Long
' total_number_of_items As Long
' item_types() As item_type_data
' End Type
' Dim item_list As item_list_data
' Private Type container_type_data
' type_id As Long
' width As Double
' height As Double
' length As Double
' volume_capacity As Double
' weight_capacity As Double
' mandatory As Long
' cost As Double
' number_available As Long
' End Type
' Private Type container_list_data
' num_container_types As Long
' container_types() As container_type_data
' End Type
' Dim container_list As container_list_data
' Private Type compatibility_data
' item_to_item() As Boolean
' container_to_item() As Boolean
' End Type
' Dim compatibility_list As compatibility_data
' Private Type item_location
' origin_x As Double
' origin_y As Double
' origin_z As Double
' next_to_item_type As Long
' End Type
' Private Type item_in_container
' item_type As Long
' rotation As Long '1 to 6
' mandatory As Long
' origin_x As Double
' origin_y As Double
' origin_z As Double
' opposite_x As Double
' opposite_y As Double
' opposite_z As Double
' End Type
' Private Type container_data
' type_id As Long
' width As Double
' height As Double
' length As Double
' volume_capacity As Double
' weight_capacity As Double
' cost As Double
' item_cnt As Long
' mandatory As Long
' items() As item_in_container
' addition_point_count As Long
' addition_points() As item_location
' repack_item_count() As Long
' volume_packed As Double
' weight_packed As Double
' End Type
' Private Type solution_data
' num_containers As Long
' feasible As Boolean
' net_profit As Double
' total_volume As Double
' total_weight As Double
' total_dispersion As Double
' total_distance As Double
' total_x_moment As Double
' total_yz_moment As Double
' rotation_order() As Long
' item_type_order() As Long
' container() As container_data
' unpacked_item_count() As Long
' End Type
' Private Type instance_data
' front_side_support As Boolean
' item_item_compatibility_worksheet As Boolean 'true if the data exists
' container_item_compatibility_worksheet As Boolean 'true if the data exists
' End Type
' Dim instance As instance_data
' Private Type solver_option_data
' CPU_time_limit As Double
' item_sort_criterion As Long
' wall_building As Boolean
' End Type
' Dim solver_options As solver_option_data
' Private Type candidate_data
' mandatory As Long
' net_profit As Double
' total_volume As Double
' item_type_to_be_added As Long
' End Type
' Private Sub SortContainers(solution As solution_data, random_reorder_probability As Double)
' Dim i As Long
' Dim j As Long
' Dim candidate_index As Long
' Dim max_mandatory As Long
' Dim max_volume_packed As Double
' Dim min_ratio As Double
' Dim swap_container As container_data
' 'insertion sort
' If Rnd < 1 - random_reorder_probability Then
' 'insertion sort
' With solution
' For i = 1 To .num_containers
' candidate_index = i
' max_mandatory = .container(i).mandatory
' max_volume_packed = .container(i).volume_packed
' min_ratio = .container(i).cost / .container(i).volume_capacity
' For j = i + 1 To .num_containers
' If (.container(j).mandatory > max_mandatory) Or _
' ((.container(j).mandatory = max_mandatory) And (.container(j).volume_packed > max_volume_packed + epsilon)) Or _
' ((.container(j).mandatory = 0) And (max_mandatory = 0) And (.container(j).volume_packed > max_volume_packed - epsilon) And ((.container(j).cost / .container(j).volume_capacity) < min_ratio)) Then
' candidate_index = j
' max_mandatory = .container(j).mandatory
' max_volume_packed = .container(j).volume_packed
' min_ratio = .container(j).cost / .container(j).volume_capacity
' End If
' Next j
' If candidate_index <> i Then
' swap_container = .container(candidate_index)
' .container(candidate_index) = .container(i)
' .container(i) = swap_container
' End If
' Next i
' End With
' Else
' With solution
' For i = 1 To .num_containers
' candidate_index = Int((.num_containers - i + 1) * Rnd + i)
' If candidate_index <> i Then
' swap_container = .container(candidate_index)
' .container(candidate_index) = .container(i)
' .container(i) = swap_container
' End If
' Next i
' End With
' End If
' End Sub
' Private Sub PerturbSolution(solution As solution_data, container_id As Long, percent_time_left As Double)
' Dim i As Long
' Dim j As Long
' Dim k As Long
' Dim l As Long
' Dim swap_long As Long
' Dim operator_selection As Double
' Dim container_emptying_probability As Double
' Dim item_removal_probability As Double
' Dim repack_flag As Boolean
' Dim continue_flag As Boolean
' Dim max_z As Double
' With solution.container(container_id)
' ' container_emptying_probability = 1 - 0.8 * (.volume_packed / .volume_capacity)
' ' item_removal_probability = 1 - 0.8 * (.volume_packed / .volume_capacity)
' 'test
' container_emptying_probability = 0.05 + 0.15 * percent_time_left
' item_removal_probability = 0.05 + 0.15 * percent_time_left
' If .item_cnt > 0 Then
' If Rnd() < container_emptying_probability Then
' 'empty the container
' For j = 1 To .item_cnt
' solution.unpacked_item_count(.items(j).item_type) = solution.unpacked_item_count(.items(j).item_type) + 1
' solution.net_profit = solution.net_profit - item_list.item_types(.items(j).item_type).profit
' Next j
' solution.net_profit = solution.net_profit + .cost
' solution.total_volume = solution.total_volume - .volume_packed
' solution.total_weight = solution.total_weight - .weight_packed
' .item_cnt = 0
' .volume_packed = 0
' .weight_packed = 0
' .addition_point_count = 1
' .addition_points(1).origin_x = 0
' .addition_points(1).origin_y = 0
' .addition_points(1).origin_z = 0
' Else
' repack_flag = False
' operator_selection = Rnd
' If operator_selection < 0.3 Then
' For j = 1 To .item_cnt
' If ((solution.feasible = False) And (.items(j).mandatory = 0)) Or (Rnd() < item_removal_probability) Then
' solution.unpacked_item_count(.items(j).item_type) = solution.unpacked_item_count(.items(j).item_type) + 1
' solution.net_profit = solution.net_profit - item_list.item_types(.items(j).item_type).profit
' .items(j).item_type = 0
' repack_flag = True
' End If
' Next j
' ElseIf operator_selection < 0.3 Then
' max_z = 0
' For j = 1 To .item_cnt
' If max_z < .items(j).opposite_z Then max_z = .items(j).opposite_z
' Next j
' max_z = max_z * (0.1 + 0.5 * percent_time_left * Rnd)
' For j = 1 To .item_cnt
' If ((solution.feasible = False) And (.items(j).mandatory = 0)) Or (.items(j).opposite_z < max_z) Then
' solution.unpacked_item_count(.items(j).item_type) = solution.unpacked_item_count(.items(j).item_type) + 1
' solution.net_profit = solution.net_profit - item_list.item_types(.items(j).item_type).profit
' .items(j).item_type = 0
' repack_flag = True
' End If
' Next j
' Else
' max_z = 0
' For j = 1 To .item_cnt
' If max_z < .items(j).opposite_z Then max_z = .items(j).opposite_z
' Next j
' max_z = max_z * (0.6 - 0.5 * percent_time_left * Rnd)
' For j = 1 To .item_cnt
' If ((solution.feasible = False) And (.items(j).mandatory = 0)) Or (.items(j).opposite_z > max_z) Then
' solution.unpacked_item_count(.items(j).item_type) = solution.unpacked_item_count(.items(j).item_type) + 1
' solution.net_profit = solution.net_profit - item_list.item_types(.items(j).item_type).profit
' .items(j).item_type = 0
' repack_flag = True
' End If
' Next j
' End If
' If repack_flag = True Then
' For j = 1 To .item_cnt
' If .items(j).item_type > 0 Then
' solution.net_profit = solution.net_profit - item_list.item_types(.items(j).item_type).profit
' End If
' Next j
' solution.net_profit = solution.net_profit + .cost
' solution.total_volume = solution.total_volume - .volume_packed
' solution.total_weight = solution.total_weight - .weight_packed
' For j = 1 To item_list.num_item_types
' .repack_item_count(j) = 0
' Next j
' For j = 1 To .item_cnt
' If .items(j).item_type > 0 Then
' .repack_item_count(.items(j).item_type) = .repack_item_count(.items(j).item_type) + 1
' End If
' Next j
' .volume_packed = 0
' .weight_packed = 0
' .item_cnt = 0
' .addition_point_count = 1
' .addition_points(1).origin_x = 0
' .addition_points(1).origin_y = 0
' .addition_points(1).origin_z = 0
' 'repack now
' For j = 1 To item_list.num_item_types
' continue_flag = True
' Do While (.repack_item_count(solution.item_type_order(j)) > 0) And (continue_flag = True)
' continue_flag = AddItemToContainer(solution, container_id, solution.item_type_order(j), 2, True)
' Loop
' ' put the remaining items in the unpacked items list
' solution.unpacked_item_count(solution.item_type_order(j)) = solution.unpacked_item_count(solution.item_type_order(j)) + .repack_item_count(solution.item_type_order(j))
' .repack_item_count(solution.item_type_order(j)) = 0
' Next j
' End If
' End If
' End If
' End With
' End Sub
' Private Sub PerturbRotationAndOrderOfItems(solution As solution_data)
' Dim i As Long
' Dim j As Long
' Dim k As Long
' Dim swap_long As Long
' 'change the preferred rotation order randomly
' For i = 1 To item_list.num_item_types
' For j = 1 To 6
' k = Int((6 - j + 1) * Rnd + j) ' the order to swap with
' swap_long = solution.rotation_order(i, j)
' solution.rotation_order(i, j) = solution.rotation_order(i, k)
' solution.rotation_order(i, k) = swap_long
' Next j
' 'MsgBox ("Item type " & i & " rotation order: " & solution.rotation_order(i, 1) & solution.rotation_order(i, 2) & solution.rotation_order(i, 3) & solution.rotation_order(i, 4) & solution.rotation_order(i, 5) & solution.rotation_order(i, 6))
' Next i
' 'change the item order randomly - test
' For i = 1 To item_list.num_item_types
' j = Int((item_list.num_item_types - i + 1) * Rnd + i) ' the order to swap with
' swap_long = solution.item_type_order(i)
' solution.item_type_order(i) = solution.item_type_order(j)
' solution.item_type_order(j) = swap_long
' Next i
' End Sub
' Private Function AddItemToContainer(solution As solution_data, container_index As Long, item_type_index As Long, add_type As Long, item_cohesion As Boolean)
' Dim i As Long
' Dim j As Long
' Dim k As Long
' Dim rotation_index As Long
' Dim origin_x As Double
' Dim origin_y As Double
' Dim origin_z As Double
' Dim opposite_x As Double
' Dim opposite_y As Double
' Dim opposite_z As Double
' Dim min_x As Double
' Dim min_y As Double
' Dim min_z As Double
' Dim next_to_item_type As Long
' Dim candidate_position As Double
' Dim current_rotation As Long
' Dim candidate_rotation As Long
' Dim area_supported As Double
' Dim area_required As Double
' Dim intersection_right As Double
' Dim intersection_left As Double
' Dim intersection_top As Double
' Dim intersection_bottom As Double
' Dim support_flag As Boolean
' With solution.container(container_index)
' min_x = .width + 1
' min_y = .height + 1
' min_z = .length + 1
' next_to_item_type = 0
' candidate_position = 0
' 'compatibility check
' If instance.container_item_compatibility_worksheet = True Then
' If compatibility_list.container_to_item(.type_id, item_list.item_types(item_type_index).id) = False Then GoTo AddItemToContainer_Finish
' End If
' 'volume size check
' If .volume_packed + item_list.item_types(item_type_index).volume > .volume_capacity Then GoTo AddItemToContainer_Finish
' 'weight capacity check
' If .weight_packed + item_list.item_types(item_type_index).weight > .weight_capacity Then GoTo AddItemToContainer_Finish
'item to item compatibility check
' If instance.item_item_compatibility_worksheet = True Then
' For i = 1 To .item_cnt
' If compatibility_list.item_to_item(item_list.item_types(item_type_index).id, item_list.item_types(.items(i).item_type).id) = False Then GoTo AddItemToContainer_Finish
' Next i
' End If
' For rotation_index = 1 To 6
' 'test
' 'If candidate_position <> 0 Then GoTo AddItemToContainer_Finish
' current_rotation = solution.rotation_order(item_type_index, rotation_index)
' 'forbidden rotations
' If ((current_rotation = 3) Or (current_rotation = 4)) And (item_list.item_types(item_type_index).xy_rotatable = False) Then
' GoTo next_rotation_iteration
' End If
' If ((current_rotation = 5) Or (current_rotation = 6)) And (item_list.item_types(item_type_index).yz_rotatable = False) Then
' GoTo next_rotation_iteration
' End If
'symmetry breaking
' If (current_rotation = 2) And (Abs(item_list.item_types(item_type_index).width - item_list.item_types(item_type_index).length) < epsilon) Then
' GoTo next_rotation_iteration
' End If
' If (current_rotation = 4) And (Abs(item_list.item_types(item_type_index).width - item_list.item_types(item_type_index).height) < epsilon) Then
' GoTo next_rotation_iteration
' End If
' If (current_rotation = 6) And (Abs(item_list.item_types(item_type_index).height - item_list.item_types(item_type_index).length) < epsilon) Then
' GoTo next_rotation_iteration
' End If
' For i = 1 To .addition_point_count
' If (item_cohesion = True) And (candidate_position <> 0) And (next_to_item_type = item_type_index) And (.addition_points(i).next_to_item_type <> item_type_index) Then GoTo next_iteration
' origin_x = .addition_points(i).origin_x
' origin_y = .addition_points(i).origin_y
' origin_z = .addition_points(i).origin_z
' If (item_list.item_types(item_type_index).heavy = True) And (origin_y > epsilon) Then GoTo next_iteration ' heavy item cannot be placed on any other item
' If current_rotation = 1 Then
' opposite_x = origin_x + item_list.item_types(item_type_index).width
' opposite_y = origin_y + item_list.item_types(item_type_index).height
' opposite_z = origin_z + item_list.item_types(item_type_index).length
' ElseIf current_rotation = 2 Then
' opposite_x = origin_x + item_list.item_types(item_type_index).length
' opposite_y = origin_y + item_list.item_types(item_type_index).height
' opposite_z = origin_z + item_list.item_types(item_type_index).width
' ElseIf current_rotation = 3 Then
' opposite_x = origin_x + item_list.item_types(item_type_index).width
' opposite_y = origin_y + item_list.item_types(item_type_index).length
' opposite_z = origin_z + item_list.item_types(item_type_index).height
' ElseIf current_rotation = 4 Then
' opposite_x = origin_x + item_list.item_types(item_type_index).height
' opposite_y = origin_y + item_list.item_types(item_type_index).length
' opposite_z = origin_z + item_list.item_types(item_type_index).width
' ElseIf current_rotation = 5 Then
' opposite_x = origin_x + item_list.item_types(item_type_index).height
' opposite_y = origin_y + item_list.item_types(item_type_index).width
' opposite_z = origin_z + item_list.item_types(item_type_index).length
' ElseIf current_rotation = 6 Then
' opposite_x = origin_x + item_list.item_types(item_type_index).length
' opposite_y = origin_y + item_list.item_types(item_type_index).width
' opposite_z = origin_z + item_list.item_types(item_type_index).height
' End If
'check the feasibility of all four corners, w.r.t to the other items
' If (opposite_x > .width + epsilon) Or (opposite_y > .height + epsilon) Or (opposite_z > .length + epsilon) Then GoTo next_iteration
' For j = 1 To .item_cnt
' If (opposite_x < .items(j).origin_x + epsilon) Or _
' (.items(j).opposite_x < origin_x + epsilon) Or _
' (opposite_y < .items(j).origin_y + epsilon) Or _
' (.items(j).opposite_y < origin_y + epsilon) Or _
' (opposite_z < .items(j).origin_z + epsilon) Or _
' (.items(j).opposite_z < origin_z + epsilon) Then
' 'no conflict
' Else
' 'conflict
' GoTo next_iteration
' End If
' Next j
'vertical support
' If origin_y < epsilon Then
' support_flag = True
' Else
' area_supported = 0
' area_required = ((opposite_x - origin_x) * (opposite_z - origin_z))
' support_flag = False
' For j = .item_cnt To 1 Step -1
' If (Abs(origin_y - .items(j).opposite_y) < epsilon) Then
' 'check for intersection
' intersection_right = opposite_x
' If intersection_right > .items(j).opposite_x Then intersection_right = .items(j).opposite_x
' intersection_left = origin_x
' If intersection_left < .items(j).origin_x Then intersection_left = .items(j).origin_x
' intersection_top = opposite_z
' If intersection_top > .items(j).opposite_z Then intersection_top = .items(j).opposite_z
' intersection_bottom = origin_z
' If intersection_bottom < .items(j).origin_z Then intersection_bottom = .items(j).origin_z
' If (intersection_right > intersection_left) And (intersection_top > intersection_bottom) Then
' 'check for fragile items
' If item_list.item_types(.items(j).item_type).fragile = True Then
' GoTo next_iteration
' Else
' area_supported = area_supported + (intersection_right - intersection_left) * (intersection_top - intersection_bottom)
' If area_supported > area_required - epsilon Then
' support_flag = True
' Exit For
' End If
' End If
' End If
' End If
' Next j
' End If
' If support_flag = False Then GoTo next_iteration
'front side support
' If instance.front_side_support = True Then
' If origin_z < epsilon Then
' support_flag = True
' Else
' area_supported = 0
' area_required = ((opposite_x - origin_x) * (opposite_y - origin_y))
' support_flag = False
' For j = .item_cnt To 1 Step -1
' If (Abs(origin_z - .items(j).opposite_z) < epsilon) Then
' 'check for intersection
' intersection_right = opposite_x
' If intersection_right > .items(j).opposite_x Then intersection_right = .items(j).opposite_x
' intersection_left = origin_x
' If intersection_left < .items(j).origin_x Then intersection_left = .items(j).origin_x
' intersection_top = opposite_y
' If intersection_top > .items(j).opposite_y Then intersection_top = .items(j).opposite_y
' intersection_bottom = origin_y
' If intersection_bottom < .items(j).origin_y Then intersection_bottom = .items(j).origin_y
' If (intersection_right > intersection_left) And (intersection_top > intersection_bottom) Then
' area_supported = area_supported + (intersection_right - intersection_left) * (intersection_top - intersection_bottom)
' If area_supported > area_required - epsilon Then
' support_flag = True
' Exit For
' End If
' End If
' End If
' Next j
' End If
' End If
' If support_flag = False Then GoTo next_iteration
'no conflicts at this point
' If (item_cohesion = True) And (next_to_item_type <> item_type_index) And (.addition_points(i).next_to_item_type = item_type_index) Then
' min_x = origin_x
' min_y = origin_y
' min_z = origin_z
' candidate_position = i
' candidate_rotation = current_rotation
' next_to_item_type = .addition_points(i).next_to_item_type
' Else
' If solver_options.wall_building = True Then
' If (origin_z < min_z) Or _
' ((origin_z <= min_z + epsilon) And (origin_y < min_y)) Or _
' ((origin_z <= min_z + epsilon) And (origin_y <= min_y + epsilon) And (origin_x < min_x)) Then 'Or _
' ((origin_z <= min_z + epsilon) And (origin_y <= min_y + epsilon) And (origin_x <= min_x + epsilon) And ((opposite_x > .width + epsilon) Or (opposite_y > .height + epsilon))) Then
' min_x = origin_x
' min_y = origin_y
' min_z = origin_z
' candidate_position = i
' candidate_rotation = current_rotation
' next_to_item_type = .addition_points(i).next_to_item_type
' End If
' Else
' If (origin_y < min_y) Or _
' ((origin_y <= min_y + epsilon) And (origin_z < min_z)) Or _
' ((origin_y <= min_y + epsilon) And (origin_z <= min_z + epsilon) And (origin_x < min_x)) Then 'Or _
' ((origin_y <= min_y + epsilon) And (origin_x <= min_x + epsilon) And (origin_z <= min_z + epsilon) And ((opposite_x > .width + epsilon) Or (opposite_y > .height + epsilon))) Then
' min_x = origin_x
' min_y = origin_y
' min_z = origin_z
' candidate_position = i
' candidate_rotation = current_rotation
' next_to_item_type = .addition_points(i).next_to_item_type
' End If
' End If
' End If
' next_iteration:
' Next i
' next_rotation_iteration:
' Next rotation_index
' End With
' AddItemToContainer_Finish:
' If candidate_position = 0 Then
' AddItemToContainer = False
' Else
' With solution.container(container_index)
' .item_cnt = .item_cnt + 1
' .items(.item_cnt).item_type = item_type_index
' .items(.item_cnt).origin_x = .addition_points(candidate_position).origin_x
' .items(.item_cnt).origin_y = .addition_points(candidate_position).origin_y
' .items(.item_cnt).origin_z = .addition_points(candidate_position).origin_z
' .items(.item_cnt).rotation = candidate_rotation
' .items(.item_cnt).mandatory = item_list.item_types(item_type_index).mandatory
' If candidate_rotation = 1 Then
' .items(.item_cnt).opposite_x = .items(.item_cnt).origin_x + item_list.item_types(item_type_index).width
' .items(.item_cnt).opposite_y = .items(.item_cnt).origin_y + item_list.item_types(item_type_index).height
' .items(.item_cnt).opposite_z = .items(.item_cnt).origin_z + item_list.item_types(item_type_index).length
' ElseIf candidate_rotation = 2 Then
' .items(.item_cnt).opposite_x = .items(.item_cnt).origin_x + item_list.item_types(item_type_index).length
' .items(.item_cnt).opposite_y = .items(.item_cnt).origin_y + item_list.item_types(item_type_index).height
' .items(.item_cnt).opposite_z = .items(.item_cnt).origin_z + item_list.item_types(item_type_index).width
' ElseIf candidate_rotation = 3 Then
' .items(.item_cnt).opposite_x = .items(.item_cnt).origin_x + item_list.item_types(item_type_index).width
' .items(.item_cnt).opposite_y = .items(.item_cnt).origin_y + item_list.item_types(item_type_index).length
' .items(.item_cnt).opposite_z = .items(.item_cnt).origin_z + item_list.item_types(item_type_index).height
' ElseIf candidate_rotation = 4 Then
' .items(.item_cnt).opposite_x = .items(.item_cnt).origin_x + item_list.item_types(item_type_index).height
' .items(.item_cnt).opposite_y = .items(.item_cnt).origin_y + item_list.item_types(item_type_index).length
' .items(.item_cnt).opposite_z = .items(.item_cnt).origin_z + item_list.item_types(item_type_index).width
' ElseIf candidate_rotation = 5 Then
' .items(.item_cnt).opposite_x = .items(.item_cnt).origin_x + item_list.item_types(item_type_index).height
' .items(.item_cnt).opposite_y = .items(.item_cnt).origin_y + item_list.item_types(item_type_index).width
' .items(.item_cnt).opposite_z = .items(.item_cnt).origin_z + item_list.item_types(item_type_index).length
' ElseIf candidate_rotation = 6 Then
' .items(.item_cnt).opposite_x = .items(.item_cnt).origin_x + item_list.item_types(item_type_index).length
' .items(.item_cnt).opposite_y = .items(.item_cnt).origin_y + item_list.item_types(item_type_index).width
' .items(.item_cnt).opposite_z = .items(.item_cnt).origin_z + item_list.item_types(item_type_index).height
' End If
' .volume_packed = .volume_packed + item_list.item_types(item_type_index).volume
' .weight_packed = .weight_packed + item_list.item_types(item_type_index).weight
' If add_type = 2 Then
' .repack_item_count(item_type_index) = .repack_item_count(item_type_index) - 1
' End If
' 'update the addition points
' For i = candidate_position To .addition_point_count - 1
' .addition_points(i) = .addition_points(i + 1)
' Next i
' .addition_point_count = .addition_point_count - 1
' If (.items(.item_cnt).opposite_x < .width - epsilon) And (.items(.item_cnt).origin_y < .height - epsilon) And (.items(.item_cnt).origin_z < .length - epsilon) Then
' .addition_point_count = .addition_point_count + 1
' .addition_points(.addition_point_count).origin_x = .items(.item_cnt).opposite_x
' .addition_points(.addition_point_count).origin_y = .items(.item_cnt).origin_y
' .addition_points(.addition_point_count).origin_z = .items(.item_cnt).origin_z
' .addition_points(.addition_point_count).next_to_item_type = item_type_index
' End If
' If item_list.item_types(item_type_index).fragile = False Then ' no addition point on top of fragile items
' If (.items(.item_cnt).origin_x < .width - epsilon) And (.items(.item_cnt).opposite_y < .height - epsilon) And (.items(.item_cnt).origin_z < .length - epsilon) Then
' .addition_point_count = .addition_point_count + 1
' .addition_points(.addition_point_count).origin_x = .items(.item_cnt).origin_x
' .addition_points(.addition_point_count).origin_y = .items(.item_cnt).opposite_y
' .addition_points(.addition_point_count).origin_z = .items(.item_cnt).origin_z
' .addition_points(.addition_point_count).next_to_item_type = item_type_index
' End If
' End If
' If (.items(.item_cnt).origin_x < .width - epsilon) And (.items(.item_cnt).origin_y < .height - epsilon) And (.items(.item_cnt).opposite_z < .length - epsilon) Then
' .addition_point_count = .addition_point_count + 1
' .addition_points(.addition_point_count).origin_x = .items(.item_cnt).origin_x
' .addition_points(.addition_point_count).origin_y = .items(.item_cnt).origin_y
' .addition_points(.addition_point_count).origin_z = .items(.item_cnt).opposite_z
' .addition_points(.addition_point_count).next_to_item_type = item_type_index
' End If
' End With
' With solution
' 'update the profit
' ' If .container(container_index).item_cnt = 1 Then
' ' .net_profit = .net_profit + item_list.item_types(item_type_index).profit - .container(container_index).cost
' ' Else
' ' .net_profit = .net_profit + item_list.item_types(item_type_index).profit
' ' End If
' 'update the volume per container and the total volume
' .total_volume = .total_volume + item_list.item_types(item_type_index).volume
' .total_weight = .total_weight + item_list.item_types(item_type_index).weight
' 'update the unpacked items
' If add_type = 1 Then
' .unpacked_item_count(item_type_index) = .unpacked_item_count(item_type_index) - 1
' End If
' End With
' AddItemToContainer = True
' End If
' End Function
' Private Sub GetSolverOptions()
' ThisWorkbook.Worksheets("CLP Solver Console").Activate
' With solver_options
' If Cells(12, 3).Value = "Volume" Then
' .item_sort_criterion = 1
' ElseIf Cells(12, 3).Value = "Weight" Then
' .item_sort_criterion = 2
' Else
' .item_sort_criterion = 3
' End If
' If Cells(13, 3).Value = "Wall-building" Then
' .wall_building = True
' Else
' .wall_building = False
' End If
' .CPU_time_limit = Cells(14, 3).Value
' End With
' End Sub
' Private Sub GetItemData()
' item_list.num_item_types = ThisWorkbook.Worksheets("CLP Solver Console").Cells(2, 3).Value
' item_list.total_number_of_items = 0
' ReDim item_list.item_types(1 To item_list.num_item_types)
' ThisWorkbook.Worksheets("1.Items").Activate
' Dim i As Long
' Dim max_volume As Double
' Dim max_weight As Double
' max_volume = 0
' max_weight = 0
' With item_list
' For i = 1 To .num_item_types
' .item_types(i).id = i
' .item_types(i).width = Cells(2 + i, 4).Value
' .item_types(i).height = Cells(2 + i, 5).Value
' .item_types(i).length = Cells(2 + i, 6).Value
' .item_types(i).volume = Cells(2 + i, 7).Value
' If max_volume < .item_types(i).volume Then
' max_volume = .item_types(i).volume
' End If
' If Cells(2 + i, 9).Value = "Yes" Then
' .item_types(i).xy_rotatable = True
' Else
' .item_types(i).xy_rotatable = False
' End If
' If Cells(2 + i, 10).Value = "Yes" Then
' .item_types(i).yz_rotatable = True
' Else
' .item_types(i).yz_rotatable = False
' End If
' If (Abs(.item_types(i).width - .item_types(i).height) < epsilon) And (Abs(.item_types(i).width - .item_types(i).length) < epsilon) Then
' .item_types(i).xy_rotatable = False
' .item_types(i).yz_rotatable = False
' End If
' .item_types(i).weight = Cells(2 + i, 11).Value
' If max_weight < .item_types(i).weight Then
' max_weight = .item_types(i).weight
' End If
' If Cells(2 + i, 12).Value = "Yes" Then
' .item_types(i).heavy = True
' Else
' .item_types(i).heavy = False
' End If
' If Cells(2 + i, 13).Value = "Yes" Then
' .item_types(i).fragile = True
' Else
' .item_types(i).fragile = False
' End If
' If Cells(2 + i, 14).Value = "Must be packed" Then
' .item_types(i).mandatory = 1
' ElseIf Cells(2 + i, 14).Value = "May be packed" Then
' .item_types(i).mandatory = 0
' ElseIf Cells(2 + i, 14).Value = "Don't pack" Then
' .item_types(i).mandatory = -1
' End If
' .item_types(i).profit = Cells(2 + i, 15).Value
' .item_types(i).number_requested = Cells(2 + i, 16).Value
' item_list.total_number_of_items = item_list.total_number_of_items + .item_types(i).number_requested
' Next i
' For i = 1 To .num_item_types
' If solver_options.item_sort_criterion = 1 Then
' .item_types(i).sort_criterion = .item_types(i).volume * (max_weight + 1) + .item_types(i).weight
' ElseIf solver_options.item_sort_criterion = 2 Then
' .item_types(i).sort_criterion = .item_types(i).weight * (max_volume + 1) + .item_types(i).volume
' Else
' .item_types(i).sort_criterion = .item_types(i).width
' If .item_types(i).sort_criterion < .item_types(i).height Then
' .item_types(i).sort_criterion = .item_types(i).height
' End If
' If .item_types(i).sort_criterion < .item_types(i).length Then
' .item_types(i).sort_criterion = .item_types(i).length
' End If
' .item_types(i).sort_criterion = .item_types(i).sort_criterion * (max_volume + 1) + .item_types(i).volume
' End If
' Next i
' End With
' End Sub
' Private Sub GetContainerData()
' container_list.num_container_types = ThisWorkbook.Worksheets("CLP Solver Console").Cells(4, 3).Value
' ReDim container_list.container_types(1 To container_list.num_container_types)
' ThisWorkbook.Worksheets("2.Containers").Activate
' Dim i As Long
' With container_list
' For i = 1 To .num_container_types
' .container_types(i).type_id = i
' .container_types(i).width = Cells(1 + i, 3).Value
' .container_types(i).height = Cells(1 + i, 4).Value
' .container_types(i).length = Cells(1 + i, 5).Value
' .container_types(i).volume_capacity = Cells(1 + i, 6).Value
' .container_types(i).weight_capacity = Cells(1 + i, 7).Value
' If Cells(1 + i, 8).Value = "Must be used" Then
' .container_types(i).mandatory = 1
' ElseIf Cells(1 + i, 8).Value = "May be used" Then