-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule1TransToPhp.bas
More file actions
2422 lines (1809 loc) · 95.4 KB
/
module1TransToPhp.bas
File metadata and controls
2422 lines (1809 loc) · 95.4 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 = "Module1"
' '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
' Const width_limit As Double = 300
' Const height_limit As Double = 300
' Const displacement_multiplier As Double = 0.353
Function CheckWorksheetExistence(sheetName As String) As Boolean
Dim WorksheetExists As Boolean
WorksheetExists = False
Dim Sht As Worksheet
For Each Sht In ThisWorkbook.Worksheets
If (Sht.Name = sheetName) Then
WorksheetExists = True
End If
Next Sht
CheckWorksheetExistence = WorksheetExists
End Function
Sub SetupConsoleWorksheet()
Dim WorksheetExists As Boolean
WorksheetExists = CheckWorksheetExistence("CLP Solver Console")
Dim reply As Integer
If WorksheetExists = False Then
ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)).Name = "CLP Solver Console"
End If
ThisWorkbook.Worksheets("CLP Solver Console").Activate
'Problem parameters
Cells(1, 1).Value = "Sequence"
Cells(1, 1).Select
Selection.Font.Bold = True
Cells(1, 2).Value = "Parameter"
Cells(1, 3).Value = "Value"
Cells(1, 4).Value = "Remarks"
Range(Cells(1, 1), Cells(1, 4)).Select
Selection.Interior.ColorIndex = 1
Selection.Font.ColorIndex = 2
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
'GIS License
Cells(2, 1).Value = "1.Items"
Cells(2, 1).Select
Selection.Font.Bold = True
Cells(2, 2).Value = "Number of types of items"
Cells(2, 3).Validation.Delete
With Cells(2, 3).Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="1", Formula2:="100"
.ErrorMessage = "Please enter an integer from 1 to 100"
End With
If Cells(2, 3).Value = "" Then
Cells(2, 3).Value = 1
End If
Cells(2, 3).Font.ColorIndex = 2
Cells(2, 3).Interior.ColorIndex = 50
Cells(2, 4).Value = "[1,100]"
Range(Cells(2, 1), Cells(2, 4)).Select
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Cells(4, 1).Value = "2.Containers"
Cells(4, 1).Select
Selection.Font.Bold = True
Cells(4, 2).Value = "Number of types of containers"
Cells(4, 3).Validation.Delete
With Cells(4, 3).Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="1", Formula2:="10"
.ErrorMessage = "Please enter an integer from 1 to 10"
End With
If Cells(4, 3).Value = "" Then
Cells(4, 3).Value = 1
End If
Cells(4, 3).Font.ColorIndex = 2
Cells(4, 3).Interior.ColorIndex = 50
Cells(4, 4).Value = "[1,10]"
Range(Cells(4, 1), Cells(4, 4)).Select
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Cells(6, 1).Value = "3.Solution"
Cells(6, 1).Select
Selection.Font.Bold = True
Cells(6, 2).Value = "Front side support required?"
Cells(6, 3).Validation.Delete
With Cells(6, 3).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(6, 3).Value = "No"
Cells(6, 3).Font.ColorIndex = 2
Cells(6, 3).Interior.ColorIndex = 50
Cells(6, 4).Value = ""
Range(Cells(6, 1), Cells(6, 4)).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
'Visualization parameters
Cells(8, 1).Value = "4.Visualization"
Cells(8, 1).Select
Selection.Font.Bold = True
Cells(8, 2).Value = "Item labels"
Cells(8, 3).Validation.Delete
With Cells(8, 3).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(8, 3).Value = "Yes"
Cells(8, 3).Font.ColorIndex = 2
Cells(8, 3).Interior.ColorIndex = 50
Cells(9, 2).Value = "Container labels"
Cells(9, 3).Validation.Delete
With Cells(9, 3).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(9, 3).Value = "No"
Cells(9, 3).Font.ColorIndex = 2
Cells(9, 3).Interior.ColorIndex = 50
Cells(10, 2).Value = "Animation advances by:"
Cells(10, 3).Validation.Delete
With Cells(10, 3).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="One second intervals, Message box between every two items"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(10, 3).Value = "One second intervals"
Cells(10, 3).Font.ColorIndex = 2
Cells(10, 3).Interior.ColorIndex = 50
Range(Cells(8, 1), Cells(10, 4)).Select
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
'Algorithmic parameters
Cells(12, 1).Value = "5.Solver"
Cells(12, 1).Select
Selection.Font.Bold = True
Cells(12, 2).Value = "First-Fit-Decreasing based on:"
Cells(12, 3).Validation.Delete
With Cells(12, 3).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Volume, Weight, Max {width; height; length}"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(12, 3).Value = "Volume"
Cells(12, 3).Font.ColorIndex = 2
Cells(12, 3).Interior.ColorIndex = 50
Cells(13, 2).Value = "Constructive heuristic:"
Cells(13, 3).Validation.Delete
With Cells(13, 3).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Wall-building, Layer-building"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(13, 3).Value = "Wall-building"
Cells(13, 3).Font.ColorIndex = 2
Cells(13, 3).Interior.ColorIndex = 50
Cells(13, 4).Value = ""
Cells(14, 2).Value = "CPU time limit (seconds)"
Cells(14, 3).Validation.Delete
With Cells(14, 3).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreaterEqual, Formula1:="10"
.ErrorMessage = "Please enter a value greater than or equal to 10 seconds."
End With
If Cells(14, 3).Value = "" Then
Cells(14, 3).Value = 60
End If
Cells(14, 3).Font.ColorIndex = 2
Cells(14, 3).Interior.ColorIndex = 50
Cells(14, 4).Value = "Recommendation: At least one second per item."
Range(Cells(12, 1), Cells(14, 4)).Select
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Columns("A").AutoFit
Columns("B").AutoFit
'Columns("C").AutoFit
Columns("D").AutoFit
Columns("C").EntireColumn.ColumnWidth = 35
Rows("1").Select
Selection.Font.Bold = True
Cells(1, 1).Select
End Sub
Sub SetupItemsWorksheet()
Dim WorksheetExists As Boolean
WorksheetExists = CheckWorksheetExistence("1.Items")
Dim reply As Integer
If WorksheetExists = True Then
reply = MsgBox("This will overwrite existing item data, and erase container, solution, and visualization data. Do you want to continue?", vbYesNo, "CLP Spreadsheet Solver")
If reply = vbNo Then
Exit Sub
Else
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("1.Items").Delete
ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)).Name = "1.Items"
WorksheetExists = CheckWorksheetExistence("1.3.Item-Item Compatibility")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Delete
End If
WorksheetExists = CheckWorksheetExistence("2.Containers")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("2.Containers").Delete
End If
WorksheetExists = CheckWorksheetExistence("2.3.Container-ItemCompatibility")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("2.3.Container-ItemCompatibility").Delete
End If
WorksheetExists = CheckWorksheetExistence("3.Solution")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("3.Solution").Delete
End If
WorksheetExists = CheckWorksheetExistence("4.Visualization")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("4.Visualization").Delete
End If
Application.DisplayAlerts = True
End If
Else
ThisWorkbook.Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "1.Items"
End If
ThisWorkbook.Worksheets("1.Items").Activate
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim formula_delimiter As String
If InStr(CStr(WorksheetFunction.Pi), ".") > 0 Then
formula_delimiter = ","
Else
formula_delimiter = ";"
End If
Dim num_item_types As Long
num_item_types = ThisWorkbook.Worksheets("CLP Solver Console").Cells(2, 3).Value
Dim formulaText As String
Cells(1, 8).Value = "Can be placed on:"
Cells(2, 1).Value = "Item Type ID"
Cells(2, 2).Value = "Name"
Cells(2, 3).Value = "Colour / Image file name"
Cells(2, 4).Value = "Width (x)"
Cells(2, 5).Value = "Height (y)"
Cells(2, 6).Value = "Length (z)"
Cells(2, 7).Value = "Volume "
Cells(2, 8).Value = "x/z surface?"
Cells(2, 9).Value = "x/y surface?"
Cells(2, 10).Value = "y/z surface?"
Cells(2, 11).Value = "Weight "
Cells(2, 12).Value = "Heavy item?"
Cells(2, 13).Value = "Fragile item?"
Cells(2, 14).Value = "Must be packed?"
Cells(2, 15).Value = "Profit"
Cells(2, 16).Value = "Number of items"
Range(Cells(1, 1), Cells(2, 16)).Select
Selection.Font.Bold = True
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Range(Cells(1, 8), Cells(2, 10)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Selection.Interior.ColorIndex = 15
Dim i As Long
For i = 1 To num_item_types
Range(Cells(2 + i, 1), Cells(2 + i, 16)).Select
Selection.Font.ColorIndex = 2
Selection.Interior.ColorIndex = 50
If i Mod 2 = 0 Then
Selection.Interior.TintAndShade = 0.02
Else
Selection.Interior.TintAndShade = -0.02
End If
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Cells(2 + i, 1).Value = i
Cells(2 + i, 1).Font.ColorIndex = 2
Cells(2 + i, 1).Interior.ColorIndex = 1
Cells(2 + i, 1).FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Cells(2 + i, 1).Address & ")"
Cells(2 + i, 1).FormatConditions(1).Interior.ColorIndex = 3
Cells(2 + i, 2).Value = "Item type " & i
Cells(2 + i, 2).FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Cells(2 + i, 2).Address & ")"
Cells(2 + i, 2).FormatConditions(1).Interior.ColorIndex = 3
Cells(2 + i, 3).Value = ""
Cells(2 + i, 3).Interior.ColorIndex = (3 + i) Mod 57
Cells(2 + i, 4).NumberFormat = "0.00"
Cells(2 + i, 4).Value = 1
With Cells(2 + i, 4).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=0
.ErrorMessage = "Please enter a positive value"
End With
Cells(2 + i, 5).NumberFormat = "0.00"
Cells(2 + i, 5).Value = 1
With Cells(2 + i, 5).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=0
.ErrorMessage = "Please enter a positive value"
End With
Cells(2 + i, 6).NumberFormat = "0.00"
Cells(2 + i, 6).Value = 1
With Cells(2 + i, 6).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=0
.ErrorMessage = "Please enter a positive value"
End With
Cells(2 + i, 7).NumberFormat = "0.00"
Cells(2 + i, 7).Formula = "=" & Cells(2 + i, 4).Address(False, False) & "*" & Cells(2 + i, 5).Address(False, False) & "*" & Cells(2 + i, 6).Address(False, False)
Cells(2 + i, 7).Interior.ColorIndex = 36
Cells(2 + i, 7).Font.ColorIndex = 1
Cells(2 + i, 8).Value = "Yes"
Cells(2 + i, 8).Interior.ColorIndex = 1
Cells(2 + i, 8).Font.ColorIndex = 2
With Cells(2 + i, 9).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(2 + i, 9).Value = "Yes"
Cells(2 + i, 9).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="No"
Cells(2 + i, 9).FormatConditions(1).Interior.ColorIndex = 43
With Cells(2 + i, 10).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(2 + i, 10).Value = "Yes"
Cells(2 + i, 10).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="No"
Cells(2 + i, 10).FormatConditions(1).Interior.ColorIndex = 43
Cells(2 + i, 11).NumberFormat = "0.00"
Cells(2 + i, 11).Value = 0
With Cells(2 + i, 11).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=-epsilon
.ErrorMessage = "Please enter a nonnegative value"
End With
With Cells(2 + i, 12).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(2 + i, 12).Value = "No"
Cells(2 + i, 12).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Yes"
Cells(2 + i, 12).FormatConditions(1).Interior.ColorIndex = 4
With Cells(2 + i, 13).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(2 + i, 13).Value = "No"
Cells(2 + i, 13).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Yes"
Cells(2 + i, 13).FormatConditions(1).Interior.ColorIndex = 4
With Cells(2 + i, 14).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Must be packed, May be packed, Do not pack"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(2 + i, 14).Value = "Must be packed"
Cells(2 + i, 14).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="May be packed"
Cells(2 + i, 14).FormatConditions(1).Interior.ColorIndex = 4
Cells(2 + i, 14).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Do not pack"
Cells(2 + i, 14).FormatConditions(2).Interior.ColorIndex = 43
Cells(2 + i, 15).NumberFormat = "0.00"
Cells(2 + i, 15).Value = 0
With Cells(2 + i, 15).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=-epsilon
.ErrorMessage = "Please enter a nonnegative value"
End With
Cells(2 + i, 16).Value = 1
With Cells(2 + i, 16).Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:="0"
.ErrorMessage = "Please enter a positive integer value"
End With
Next i
' Cells(2, 15).Value = "Total volume requirement:"
' Cells(3, 15).Formula = "=SUMPRODUCT(" & Cells(3, 7).Address(False, False) & ":" & Cells(2 + num_item_types, 7).Address(False, False) & "," & Cells(3, 14).Address(False, False) & ":" & Cells(2 + num_item_types, 14).Address(False, False) & ")"
' Cells(3, 15).Interior.ColorIndex = 36
' Cells(3, 15).Font.ColorIndex = 1
' Cells(3, 15).NumberFormat = "0.00"
' Display all duplicate values in red
Dim uv As UniqueValues
Set uv = Range(Cells(2, 2), Cells(1 + num_item_types, 2)).FormatConditions.AddUniqueValues
uv.DupeUnique = xlDuplicate
uv.Interior.ColorIndex = 3
uv.StopIfTrue = False
Dim item_width As Double
Dim item_height As Double
Dim item_length As Double
Dim nw_x As Double
Dim nw_y As Double
item_width = Columns("D").width + Columns("E").width + Columns("F").width
item_height = item_width
item_length = item_width
nw_x = Columns("A").width + Columns("B").width + Columns("C").width
nw_y = ((num_item_types + 3) * Rows(1).height) + item_length * displacement_multiplier
ActiveSheet.Shapes.AddShape(msoShapeRectangle, nw_x, nw_y, item_width, item_height).Select 'type, left, top, width, height
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.Transparency = 1
With Selection.ShapeRange.ThreeD
.Visible = True
.depth = item_length
.ContourWidth = 0.2
.ExtrusionColor.RGB = RGB(255, 255, 255) 'for containers
.SetExtrusionDirection msoExtrusionTopRight
.PresetLightingDirection = msoLightingTopRight
.PresetMaterial = msoMaterialTranslucentPowder 'for containers
End With
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, nw_x + item_width / 2, nw_y + item_height, Columns("D").width, 2 * Rows(1).height).TextFrame.Characters.Text = "x"
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).TextFrame.Characters.Font.Size = 11
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).TextFrame.Characters.Font.Bold = True
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.Visible = msoFalse
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Line.Visible = msoFalse
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, nw_x, nw_y + item_height / 2, Columns("D").width, 2 * Rows(1).height).TextFrame.Characters.Text = "y"
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).TextFrame.Characters.Font.Size = 11
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).TextFrame.Characters.Font.Bold = True
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.Visible = msoFalse
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Line.Visible = msoFalse
ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, nw_x + item_width * (1 + displacement_multiplier / 2), nw_y + item_height * 0.75, Columns("D").width, 2 * Rows(1).height).TextFrame.Characters.Text = "z"
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).TextFrame.Characters.Font.Size = 11
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).TextFrame.Characters.Font.Bold = True
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Fill.Visible = msoFalse
ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Line.Visible = msoFalse
Columns("A:P").AutoFit
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Cells(1, 1).Select
End Sub
Sub SetupContainersWorksheet()
Dim WorksheetExists As Boolean
WorksheetExists = CheckWorksheetExistence("2.Containers")
Dim reply As Integer
If WorksheetExists = True Then
reply = MsgBox("This will overwrite existing container data, and erase solution and visualization data. Do you want to continue?", vbYesNo, "CLP Spreadsheet Solver")
If reply = vbNo Then
Exit Sub
Else
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("2.Containers").Delete
ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)).Name = "2.Containers"
WorksheetExists = CheckWorksheetExistence("2.3.Container-ItemCompatibility")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("2.3.Container-ItemCompatibility").Delete
End If
WorksheetExists = CheckWorksheetExistence("3.Solution")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("3.Solution").Delete
End If
WorksheetExists = CheckWorksheetExistence("4.Visualization")
If WorksheetExists = True Then
ThisWorkbook.Worksheets("4.Visualization").Delete
End If
Application.DisplayAlerts = True
End If
Else
ThisWorkbook.Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "2.Containers"
End If
ThisWorkbook.Worksheets("2.Containers").Activate
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim num_container_types As Long
num_container_types = ThisWorkbook.Worksheets("CLP Solver Console").Cells(4, 3).Value
Dim formulaText As String
Cells(1, 1).Value = "Container Type ID"
Cells(1, 2).Value = "Name"
Cells(1, 3).Value = "Width (x)"
Cells(1, 4).Value = "Height (y)"
Cells(1, 5).Value = "Length (z)"
Cells(1, 6).Value = "Volume capacity"
Cells(1, 7).Value = "Weight capacity"
Cells(1, 8).Value = "May be used?"
Cells(1, 9).Value = "Cost"
Cells(1, 10).Value = "Number of containers"
Range(Cells(1, 1), Cells(1, 10)).Select
Selection.Font.Bold = True
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Dim i As Long
For i = 1 To num_container_types
Range(Cells(1 + i, 1), Cells(1 + i, 10)).Select
Selection.Font.ColorIndex = 2
Selection.Interior.ColorIndex = 50
If i Mod 2 = 0 Then
Selection.Interior.TintAndShade = 0.02
Else
Selection.Interior.TintAndShade = -0.02
End If
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Cells(1 + i, 1).Value = i
Cells(1 + i, 1).Font.ColorIndex = 2
Cells(1 + i, 1).Interior.ColorIndex = 1
Cells(1 + i, 1).FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Cells(1 + i, 1).Address(False, False) & ")"
Cells(1 + i, 1).FormatConditions(1).Interior.ColorIndex = 3
Cells(1 + i, 2).Value = "Container type " & i
Cells(1 + i, 2).FormatConditions.Add Type:=xlExpression, Formula1:="=ISBLANK(" & Cells(1 + i, 2).Address(False, False) & ")"
Cells(1 + i, 2).FormatConditions(1).Interior.ColorIndex = 3
Cells(1 + i, 3).NumberFormat = "0.00"
Cells(1 + i, 3).Value = 1
With Cells(1 + i, 3).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=0
.ErrorMessage = "Please enter a positive value"
End With
Cells(1 + i, 4).NumberFormat = "0.00"
Cells(1 + i, 4).Value = 1
With Cells(1 + i, 4).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=0
.ErrorMessage = "Please enter a positive value"
End With
Cells(1 + i, 5).NumberFormat = "0.00"
Cells(1 + i, 5).Value = 1
With Cells(1 + i, 5).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=0
.ErrorMessage = "Please enter a positive value"
End With
Cells(1 + i, 6).NumberFormat = "0.00"
Cells(1 + i, 6).Formula = "=" & Cells(1 + i, 3).Address(False, False) & "*" & Cells(1 + i, 4).Address(False, False) & "*" & Cells(1 + i, 5).Address(False, False)
Cells(1 + i, 6).Interior.ColorIndex = 36
Cells(1 + i, 6).Font.ColorIndex = 1
Cells(1 + i, 7).NumberFormat = "0.00"
Cells(1 + i, 7).Value = 1
With Cells(1 + i, 7).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=0
.ErrorMessage = "Please enter a positive value"
End With
With Cells(1 + i, 8).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="May be used, Do not use" 'removed Must be used
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(1 + i, 8).Value = "May be used"
Cells(1 + i, 8).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Must be used"
Cells(1 + i, 8).FormatConditions(1).Interior.ColorIndex = 4
Cells(1 + i, 8).FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Do not use"
Cells(1 + i, 8).FormatConditions(2).Interior.ColorIndex = 43
Cells(1 + i, 9).NumberFormat = "0.00"
Cells(1 + i, 9).Value = 1
With Cells(1 + i, 9).Validation
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:=-epsilon
.ErrorMessage = "Please enter a nonnegative value"
End With
Cells(1 + i, 10).Value = 1
With Cells(1 + i, 10).Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, Operator:=xlGreater, Formula1:="0"
.ErrorMessage = "Please enter a positive integer value"
End With
Next i
' Cells(1, 11).Value = "Total volume capacity:"
' Cells(2, 11).Formula = "=SUMPRODUCT(" & Cells(2, 6).Address(False, False) & ":" & Cells(1 + num_container_types, 6).Address(False, False) & "," & Cells(2, 10).Address(False, False) & ":" & Cells(1 + num_container_types, 10).Address(False, False) & ")"
' Cells(2, 11).Interior.ColorIndex = 36
' Cells(2, 11).Font.ColorIndex = 1
' Cells(2, 11).NumberFormat = "0.00"
' Display all duplicate values in red
Dim uv As UniqueValues
Set uv = Range(Cells(2, 2), Cells(1 + num_container_types, 2)).FormatConditions.AddUniqueValues
uv.DupeUnique = xlDuplicate
uv.Interior.ColorIndex = 3
uv.StopIfTrue = False
Columns("A:J").AutoFit
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Cells(1, 1).Select
End Sub
Sub SetupItemItemCompatibilityWorksheet()
Dim WorksheetExists As Boolean
WorksheetExists = CheckWorksheetExistence("1.Items")
If WorksheetExists = False Then
MsgBox "Worksheet 1.Items must exist for the item-item compatibility worksheet to be setup."
Exit Sub
End If
Dim num_item_types As Long
num_item_types = ThisWorkbook.Worksheets("CLP Solver Console").Cells(2, 3).Value
If num_item_types = 1 Then
MsgBox "There should be more than one type of item for the item-item compatibility worksheet to be setup."
Exit Sub
End If
WorksheetExists = CheckWorksheetExistence("1.3.Item-Item Compatibility")
Dim reply As Integer
If WorksheetExists = True Then
reply = MsgBox("This will overwrite existing item-item compatibility data. Do you want to continue?", vbYesNo, "CLP Spreadsheet Solver")
If reply = vbNo Then
Exit Sub
Else
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Delete
ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)).Name = "1.3.Item-Item Compatibility"
Application.DisplayAlerts = True
End If
Else
ThisWorkbook.Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "1.3.Item-Item Compatibility"
End If
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Activate
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Cells(2, 1).Value = "Item Type 1"
Cells(2, 2).Value = "Item type 2"
Cells(2, 3).Value = "Compatible?"
Range(Cells(1, 1), Cells(2, 3)).Select
Selection.Font.Bold = True
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
Dim i As Long
Dim j As Long
Dim k As Long
k = 3
For i = 1 To num_item_types
For j = i + 1 To num_item_types
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Range(Cells(k, 1), Cells(k, 3)).Select
Selection.Font.ColorIndex = 2
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 1).Value = ThisWorkbook.Sheets("1.Items").Cells(2 + i, 2).Value
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 1).Font.ColorIndex = 2
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 1).Interior.ColorIndex = 1
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 2).Value = ThisWorkbook.Sheets("1.Items").Cells(2 + j, 2).Value
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 2).Font.ColorIndex = 2
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 2).Interior.ColorIndex = 1
With ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 3).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Yes, No"
.IgnoreBlank = True
.InCellDropdown = True
End With
Cells(k, 3).Value = "Yes"
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 3).Font.ColorIndex = 2
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Cells(k, 3).Interior.ColorIndex = 50
k = k + 1
Next j
Next i
ThisWorkbook.Worksheets("1.3.Item-Item Compatibility").Activate
Range(Cells(1, 3), Cells(k - 1, 3)).Select
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="No"
Selection.FormatConditions(1).Interior.ColorIndex = 43
Columns("A").AutoFit
Columns("B").AutoFit
Columns("C").AutoFit
Cells(1, 1).Value = "Two items are compatible if they can be placed into the same container."
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Cells(1, 1).Select
End Sub
Sub SetupContainerItemCompatibilityWorksheet()
Dim WorksheetExists As Boolean
WorksheetExists = CheckWorksheetExistence("1.Items") And CheckWorksheetExistence("2.Containers")
If WorksheetExists = False Then
MsgBox "Worksheets 1.Items and 2.Containers must exist for the container-item compatibility worksheet to be setup."
Exit Sub
End If
WorksheetExists = CheckWorksheetExistence("2.3.Container-ItemCompatibility")
Dim reply As Integer
If WorksheetExists = True Then
reply = MsgBox("This will overwrite existing container-item compatibility data. Do you want to continue?", vbYesNo, "CLP Spreadsheet Solver")
If reply = vbNo Then
Exit Sub
Else
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("2.3.Container-ItemCompatibility").Delete
ThisWorkbook.Worksheets.Add(After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)).Name = "2.3.Container-ItemCompatibility"
Application.DisplayAlerts = True
End If
Else
ThisWorkbook.Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "2.3.Container-ItemCompatibility"
End If
ThisWorkbook.Worksheets("2.3.Container-ItemCompatibility").Activate
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim num_item_types As Long
num_item_types = ThisWorkbook.Worksheets("CLP Solver Console").Cells(2, 3).Value
Dim num_container_types As Long
num_container_types = ThisWorkbook.Worksheets("CLP Solver Console").Cells(4, 3).Value
Cells(2, 1).Value = "Container Type"
Cells(2, 2).Value = "Item type"
Cells(2, 3).Value = "Compatible?"
Range(Cells(1, 1), Cells(2, 3)).Select
Selection.Font.Bold = True
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 16
.TintAndShade = 0
.weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)