-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmt_planner.cpp
1981 lines (1756 loc) · 96.7 KB
/
smt_planner.cpp
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
/***************************************************************************
*smt-planner.cpp - A smt-planner for the rcll domain
*
*Created: Created on Wed Mar 21 21:32 2018 by Igor Nicolai Bongartz
****************************************************************************/
#include "smt_planner.h"
SmtPlanner::SmtPlanner(void) {
}
/**
* Setter
*/
void SmtPlanner::setAmountRobots(int amount_robots)
{
this->amount_robots = amount_robots;
}
void SmtPlanner::setComplexity(int desired_complexity)
{
this->desired_complexity = desired_complexity;
}
void SmtPlanner::setGameFile(std::string game_file)
{
this->game_file = game_file;
}
void SmtPlanner::setNavgraphFile(std::string navgraph_file)
{
this->navgraph_file = navgraph_file;
}
/**
* init_pre function sets maps before reading the input files
*/
void SmtPlanner::init_pre()
{
// Order
order_colors["BASE_RED"] = 1;
order_colors["BASE_BLACK"] = 2;
order_colors["BASE_SILVER"] = 3;
order_colors["RING_BLUE"] = 1;
order_colors["RING_GREEN"] = 2;
order_colors["RING_YELLOW"] = 3;
order_colors["RING_ORANGE"] = 4;
order_colors["CAP_BLACK"] = 1;
order_colors["CAP_GREY"] = 2;
// Rings and Caps (Note that information for caps is static and for rings is extracted later)
station_colors["C1"]="CS1"; // CS1 with CAP_GREY
station_colors["C2"]="CS2"; // CS2 with CAP_BLACK
// Navgraph
node_names[0] = team+"-ins-in";
node_names[1] = team+"-BS-O";
node_names[2] = team+"-CS1-I";
node_names[3] = team+"-CS1-O";
node_names[4] = team+"-CS2-I";
node_names[5] = team+"-CS2-O";
node_names[6] = team+"-DS-I";
node_names[7] = team+"-RS1-I";
node_names[8] = team+"-RS1-O";
node_names[9] = team+"-RS2-I";
node_names[10] = team+"-RS2-O";
node_names_inverted[team+"-ins-in"] = 0;
node_names_inverted[team+"-BS-O"] = 1;
node_names_inverted[team+"-CS1-I"] = 2;
node_names_inverted[team+"-CS1-O"] = 3;
node_names_inverted[team+"-CS2-I"] = 4;
node_names_inverted[team+"-CS2-O"] = 5;
node_names_inverted[team+"-DS-I"] = 6;
node_names_inverted[team+"-RS1-I"] = 7;
node_names_inverted[team+"-RS1-O"] = 8;
node_names_inverted[team+"-RS2-I"] = 9;
node_names_inverted[team+"-RS2-O"] = 10;
// Prepare PlanHorizon
// MACRO ACTIONS
amount_min_req_actions_macro.push_back(6);
amount_min_req_actions_macro.push_back(8);
amount_min_req_actions_macro.push_back(10);
amount_min_req_actions_macro.push_back(12);
index_upper_bound_actions_macro.push_back(6);
index_upper_bound_actions_macro.push_back(9);
index_upper_bound_actions_macro.push_back(11);
index_upper_bound_actions_macro.push_back(13);
amount_req_actions_add_bases_macro = 2;
// PURE ACTIONS
amount_min_req_actions_pure.push_back(11);
amount_min_req_actions_pure.push_back(14);
amount_min_req_actions_pure.push_back(17);
amount_min_req_actions_pure.push_back(20);
index_upper_bound_actions_pure.push_back(11);
index_upper_bound_actions_pure.push_back(15);
index_upper_bound_actions_pure.push_back(18);
index_upper_bound_actions_pure.push_back(21);
amount_req_actions_add_bases_pure = 3;
// Inside encodes if the CS has the cap retrieved in order to mount it with some subproduct.
inside_capstation["nothing"]=0;
inside_capstation["has_C1"]=1;
inside_capstation["has_C2"]=2;
// Prepare encodes if the CS is prepared for RETRIEVE or MOUNT
prepare_capstation["not"]=0;
prepare_capstation["retrieve"]=1;
prepare_capstation["mount"]=2;
// For each relevant machine we assign a group
machine_groups["BS"]=0;
machine_groups["RS1"]=1;
machine_groups["RS2"]=2;
machine_groups["CS1"]=3;
machine_groups["CS2"]=4;
machine_groups["DS"]=5;
// Products encodes the output of an station which can be any product (at the CS) and subproduct (at the BS and RS) OR the product a robot is holding
products["nothing"]=0;
products["BR"]=1;
products["BRC1"]=2;
products["BRC2"]=3;
unsigned ctr = 3;
// B1 ... B3
for(unsigned b=1; b<4; ++b){
std::string name = "B"+std::to_string(b);
ctr++;
products[name] = ctr;
}
// B1C1 ... B3C2
for(unsigned b=1; b<4; ++b){
for(unsigned c=1; c<3; ++c) {
std::string name = "B"+std::to_string(b)+"C"+std::to_string(c);
ctr++;
products[name] = ctr;
}
}
// B1R1 ... B3R4
for(unsigned b=1; b<4; ++b){
for(unsigned r1=1; r1<5; ++r1) {
std::string name = "B"+std::to_string(b)+"R"+std::to_string(r1);
ctr++;
products[name] = ctr;
}
}
// B1R1C1 ... B3R4C2
for(unsigned b=1; b<4; ++b){
for(unsigned r1=1; r1<5; ++r1) {
for(unsigned c=1; c<3; ++c) {
std::string name = "B"+std::to_string(b)+"R"+std::to_string(r1)+"C"+std::to_string(c);
ctr++;
products[name] = ctr;
}
}
}
// B1R1R1 ... B3R4R4
for(unsigned b=1; b<4; ++b){
for(unsigned r1=1; r1<5; ++r1) {
for(unsigned r2=1; r2<5; ++r2) {
std::string name = "B"+std::to_string(b)+"R"+std::to_string(r1)+"R"+std::to_string(r2);
ctr++;
products[name] = ctr;
}
}
}
// B1R1R1C1 ... B3R4R4C2
for(unsigned b=1; b<4; ++b){
for(unsigned r1=1; r1<5; ++r1) {
for(unsigned r2=1; r2<5; ++r2) {
for(unsigned c=1; c<3; ++c) {
std::string name = "B"+std::to_string(b)+"R"+std::to_string(r1)+"R"+std::to_string(r2)+"C"+std::to_string(c);
ctr++;
products[name] = ctr;
}
}
}
}
// B1R1R1R1 ... B3R4R4R4
for(unsigned b=1; b<4; ++b){
for(unsigned r1=1; r1<5; ++r1) {
for(unsigned r2=1; r2<5; ++r2) {
for(unsigned r3=1; r3<5; ++r3) {
std::string name = "B"+std::to_string(b)+"R"+std::to_string(r1)+"R"+std::to_string(r2)+"R"+std::to_string(r3);
ctr++;
products[name] = ctr;
}
}
}
}
// B1R1R1R1C1 ... B3R4R4R4C2
for(unsigned b=1; b<4; ++b){
for(unsigned r1=1; r1<5; ++r1) {
for(unsigned r2=1; r2<5; ++r2) {
for(unsigned r3=1; r3<5; ++r3) {
for(unsigned c=1; c<3; ++c) {
std::string name = "B"+std::to_string(b)+"R"+std::to_string(r1)+"R"+std::to_string(r2)+"R"+std::to_string(r3)+"C"+std::to_string(c);
ctr++;
products[name] = ctr;
}
}
}
}
}
}
/**
* init_game function matches relevant information from game file
*/
void SmtPlanner::init_game()
{
// Prepare boost regex matching
std::vector<std::string> game;
std::string line;
std::ifstream game_infile(game_file);
while(std::getline(game_infile, line)){
game.push_back(line);
}
boost::regex regex_order_c0("Order [0-9]: C0 \\((BASE_[A-Z]+)\\|\\|(CAP_[A-Z]+)\\) from ([0-9]+):([0-9]+) to ([0-9]+):([0-9]+).*?");
boost::regex regex_order_c1("Order [0-9]: C1 \\((BASE_[A-Z]+)\\|(RING_[A-Z]+)\\|(CAP_[A-Z]+)\\) from ([0-9]+):([0-9]+) to ([0-9]+):([0-9]+).*?");
boost::regex regex_order_c2("Order [0-9]: C2 \\((BASE_[A-Z]+)\\|(RING_[A-Z]+) (RING_[A-Z]+)\\|(CAP_[A-Z]+)\\) from ([0-9]+):([0-9]+) to ([0-9]+):([0-9]+).*?");
boost::regex regex_order_c3("Order [0-9]: C3 \\((BASE_[A-Z]+)\\|(RING_[A-Z]+) (RING_[A-Z]+) (RING_[A-Z]+)\\|(CAP_[A-Z]+)\\) from ([0-9]+):([0-9]+) to ([0-9]+):([0-9]+).*?");
boost::regex regex_rings_req_add_bases("Ring color (RING_[A-Z]+) requires ([0-3]) additional bases");
boost::regex regex_station_colors("RS C-(RS[1-2]) has colors \\((RING_[A-Z]+) (RING_[A-Z]+)\\)");
boost::cmatch match;
// Detect for each line if it holds information about order, rings_req_add_bases or station_colors
for(int i=0; i<game.size(); ++i) {
// Extract order details of c0
if(desired_complexity == 0 && boost::regex_match(game[i].c_str(), match, regex_order_c0)){
rings.clear();
for(int j=1; j<match.size(); ++j){
std::string string_match(match[j].first, match[j].second);
switch(j){
case 1:
base = order_colors[string_match];
break;
case 2:
cap = order_colors[string_match];
break;
case 3:
delivery_period_begin = std::stoi(string_match)*60; // Begin minutes
break;
case 4:
delivery_period_begin += std::stoi(string_match); // Begin seconds
break;
case 5:
delivery_period_end = std::stoi(string_match)*60; // Begin minutes
break;
case 6:
delivery_period_end += std::stoi(string_match); // Begin seconds
break;
default:
break;
}
}
rings.push_back(1); // DUMMY
rings.push_back(1); // DUMMY
rings.push_back(1); // DUMMY
}
// Extract order details of c1
else if(desired_complexity == 1 && boost::regex_match(game[i].c_str(), match, regex_order_c1)){
rings.clear();
for(int j=1; j<match.size(); ++j){
std::string string_match(match[j].first, match[j].second);
switch(j){
case 1:
base = order_colors[string_match];
break;
case 2:
rings.push_back(order_colors[string_match]);
break;
case 3:
cap = order_colors[string_match];
break;
case 4:
delivery_period_begin = std::stoi(string_match)*60; // Begin minutes
break;
case 5:
delivery_period_begin += std::stoi(string_match); // Begin seconds
break;
case 6:
delivery_period_end = std::stoi(string_match)*60; // Begin minutes
break;
case 7:
delivery_period_end += std::stoi(string_match); // Begin seconds
break;
default:
break;
}
}
rings.push_back(1); // DUMMY
rings.push_back(1); // DUMMY
}
// Extract order details of c2
else if(desired_complexity == 2 && boost::regex_match(game[i].c_str(), match, regex_order_c2)){
rings.clear();
for(int j=1; j<match.size(); ++j){
std::string string_match(match[j].first, match[j].second);
switch(j){
case 1:
base = order_colors[string_match];
break;
case 2:
rings.push_back(order_colors[string_match]);
break;
case 3:
rings.push_back(order_colors[string_match]);
break;
case 4:
cap = order_colors[string_match];
break;
case 5:
delivery_period_begin = std::stoi(string_match)*60; // Begin minutes
break;
case 6:
delivery_period_begin += std::stoi(string_match); // Begin seconds
break;
case 7:
delivery_period_end = std::stoi(string_match)*60; // Begin minutes
break;
case 8:
delivery_period_end += std::stoi(string_match); // Begin seconds
break;
default:
break;
}
}
rings.push_back(1); // DUMMY
}
// Extract order details of c3
else if(desired_complexity == 3 && boost::regex_match(game[i].c_str(), match, regex_order_c3)){
rings.clear();
for(int j=1; j<match.size(); ++j){
std::string string_match(match[j].first, match[j].second);
switch(j){
case 1:
base = order_colors[string_match];
break;
case 2:
rings.push_back(order_colors[string_match]);
break;
case 3:
rings.push_back(order_colors[string_match]);
break;
case 4:
rings.push_back(order_colors[string_match]);
break;
case 5:
cap = order_colors[string_match];
break;
case 6:
delivery_period_begin = std::stoi(string_match)*60; // Begin minutes
break;
case 7:
delivery_period_begin += std::stoi(string_match); // Begin seconds
break;
case 8:
delivery_period_end = std::stoi(string_match)*60; // Begin minutes
break;
case 9:
delivery_period_end += std::stoi(string_match); // Begin seconds
break;
default:
break;
}
}
}
// Extract how many additional bases a ring color requires
else if(boost::regex_match(game[i].c_str(), match, regex_rings_req_add_bases)){
int ring_color;
int r_req;
for(int j=1; j<match.size(); ++j){
std::string string_match(match[j].first, match[j].second);
switch(j){
case 1:
ring_color = order_colors[string_match];
break;
case 2:
r_req = std::stoi(string_match);
break;
default:
break;
}
}
rings_req_add_bases[ring_color] = r_req;
}
// Extract which ring station operates on which ring color
else if(boost::regex_match(game[i].c_str(), match, regex_station_colors)){
std::string ring_station;
int ring_color_1;
int ring_color_2;
for(int j=1; j<match.size(); ++j){
std::string string_match(match[j].first, match[j].second);
switch(j){
case 1:
ring_station = string_match;
break;
case 2:
ring_color_1 = order_colors[string_match];
break;
case 3:
ring_color_2 = order_colors[string_match];
break;
default:
break;
}
}
station_colors["R"+std::to_string(ring_color_1)] = ring_station;
station_colors["R"+std::to_string(ring_color_2)] = ring_station;
}
}
}
/**
* init_navgraph function matches relevant information from navgraph file
*/
void SmtPlanner::init_navgraph()
{
// Prepare boost regex matching
std::vector<std::string> navgraph;
std::string line;
std::ifstream navgraph_infile(navgraph_file);
while(std::getline(navgraph_infile, line)){
navgraph.push_back(line);
}
boost::regex regex_distance("(.*?);(.*?);(.*?)");
boost::cmatch match;
// Detect for each line in navgraph file the parts first_node, second_node and distance
for(int i=0; i<navgraph.size(); ++i) {
if(boost::regex_match(navgraph[i].c_str(), match, regex_distance)){
std::string first_node;
std::string second_node;
double distance;
for(int j=1; j<match.size(); ++j){
std::string string_match(match[j].first, match[j].second);
switch(j){
case 1:
first_node = string_match;
break;
case 2:
second_node = string_match;
break;
case 3:
distance = std::stod(string_match);
break;
default:
break;
}
}
// std::cout << "Add navgraph-entry (" << first_node << ";" << second_node << ";" << distance << ")" << std::endl;
std::pair<std::string, std::string> nodes_pair(first_node, second_node);
distances[nodes_pair] = distance;
}
}
}
/**
* init_post function sets maps after reading the input file
*/
void SmtPlanner::init_post()
{
// Set PlanHorizon
switch(desired_complexity) {
case 0:
plan_horizon_pure = amount_min_req_actions_pure[0];
plan_horizon_macro = amount_min_req_actions_macro[0];
break;
case 1:
plan_horizon_pure = amount_min_req_actions_pure[1]
+ amount_req_actions_add_bases_pure*rings_req_add_bases[rings[0]];
plan_horizon_macro = amount_min_req_actions_macro[1]
+ amount_req_actions_add_bases_macro*rings_req_add_bases[rings[0]];
break;
case 2:
plan_horizon_pure = amount_min_req_actions_pure[2]
+ amount_req_actions_add_bases_pure*rings_req_add_bases[rings[0]]
+ amount_req_actions_add_bases_pure*rings_req_add_bases[rings[1]];
plan_horizon_macro = amount_min_req_actions_macro[2]
+ amount_req_actions_add_bases_macro*rings_req_add_bases[rings[0]]
+ amount_req_actions_add_bases_macro*rings_req_add_bases[rings[1]];
break;
case 3:
plan_horizon_pure = amount_min_req_actions_pure[3]
+ amount_req_actions_add_bases_pure*rings_req_add_bases[rings[0]]
+ amount_req_actions_add_bases_pure*rings_req_add_bases[rings[1]]
+ amount_req_actions_add_bases_pure*rings_req_add_bases[rings[2]];
plan_horizon_macro = amount_min_req_actions_macro[3]
+ amount_req_actions_add_bases_macro*rings_req_add_bases[rings[0]]
+ amount_req_actions_add_bases_macro*rings_req_add_bases[rings[1]]
+ amount_req_actions_add_bases_macro*rings_req_add_bases[rings[2]];
break;
default:
std::cout << "Wrong desired_complexity " << desired_complexity << " for determining plan_horizon" << std::endl;
break;
}
}
/*
* Methods for encoding the given protobuf data in formulas
*/
z3::expr_vector
SmtPlanner::encoder_version_pure()
{
/*
* PRECOMPUTATION
*/
// Map collecting all variables
std::map<std::string, z3::expr> var;
// Vector collecting all constraints
z3::expr_vector constraints(_z3_context);
// Init variable true and false
z3::expr var_false(_z3_context.bool_val(false));
z3::expr var_true(_z3_context.bool_val(true));
/*
* VARIABLES
*/
// Variables initDist_i_j
for(int i = 0; i < amount_machines+1; ++i){
for(int j = i+1; j < amount_machines+1; ++j) {
var.insert(std::make_pair("initDist_" + std::to_string(i) + "_" + std::to_string(j), _z3_context.real_const(("initDist_" + std::to_string(i) + "_" + std::to_string(j)).c_str())));
}
}
// Variables initPos and initHold
for(int i = 1; i < amount_robots+1; ++i){
var.insert(std::make_pair("initPos_" + std::to_string(i), _z3_context.int_const(("initPos_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("initHold_" + std::to_string(i), _z3_context.int_const(("initHold_" + std::to_string(i)).c_str())));
}
// Variables initState1_i, initInside_i and initOutside_i
for(int i=min_machine_groups; i<max_machine_groups_pure+1; ++i){
var.insert(std::make_pair("initInside_" + std::to_string(i), _z3_context.int_const(("initInside_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("initOutside_" + std::to_string(i), _z3_context.int_const(("initOutside_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("initPrepare_" + std::to_string(i), _z3_context.int_const(("initPrepare_" + std::to_string(i)).c_str())));
}
// Variables depending on plan_horizon_pure
for(int i=1; i<plan_horizon_pure+1; ++i){
var.insert(std::make_pair("t_" + std::to_string(i), _z3_context.real_const(("t_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("rd_" + std::to_string(i), _z3_context.real_const(("rd_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("pos_" + std::to_string(i), _z3_context.int_const(("pos_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("md_" + std::to_string(i), _z3_context.real_const(("md_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("R_" + std::to_string(i), _z3_context.int_const(("R_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("A_" + std::to_string(i), _z3_context.int_const(("A_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("M_" + std::to_string(i), _z3_context.int_const(("M_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("holdA_" + std::to_string(i), _z3_context.int_const(("holdA_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("insideA_" + std::to_string(i), _z3_context.int_const(("insideA_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("outputA_" + std::to_string(i), _z3_context.int_const(("outputA_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("prepareA_" + std::to_string(i), _z3_context.int_const(("prepareA_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("holdB_" + std::to_string(i), _z3_context.int_const(("holdB_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("insideB_" + std::to_string(i), _z3_context.int_const(("insideB_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("outputB_" + std::to_string(i), _z3_context.int_const(("outputB_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("prepareB_" + std::to_string(i), _z3_context.int_const(("prepareB_" + std::to_string(i)).c_str())));
var.insert(std::make_pair("rew_" + std::to_string(i), _z3_context.real_const(("rew_" + std::to_string(i)).c_str())));
}
/*
* CONSTRAINTS
*/
// Constraints depending on plan_horizon_pure
for(int i = 1; i < plan_horizon_pure+1; ++i){
// VarStartTime
// General bound
constraints.push_back(0 <= getVar(var, "t_"+std::to_string(i)) && getVar(var, "t_"+std::to_string(i)) <= 900);
// Robot specifc bound
for(int j = 1; j < i; ++j){
constraints.push_back(!(getVar(var, "R_"+std::to_string(j)) == getVar(var, "R_"+std::to_string(i))) || getVar(var, "t_"+std::to_string(j)) <= getVar(var, "t_"+std::to_string(i)));
}
constraints.push_back(0 <= getVar(var, "rd_"+std::to_string(i))); // VarRobotDuration
constraints.push_back(1 <= getVar(var, "pos_"+std::to_string(i)) && getVar(var, "pos_"+std::to_string(i)) <= amount_machines); // VarRobotPosition
constraints.push_back(0 <= getVar(var, "md_"+std::to_string(i))); // VarMachineDuration
constraints.push_back(1 <= getVar(var, "R_"+std::to_string(i)) && getVar(var, "R_"+std::to_string(i)) <= amount_robots); // VarR
constraints.push_back(0 < getVar(var, "A_"+std::to_string(i)) && getVar(var, "A_"+std::to_string(i)) <= index_upper_bound_actions_pure[desired_complexity]); // VarA
constraints.push_back(min_machine_groups <= getVar(var, "M_"+std::to_string(i)) && getVar(var, "M_"+std::to_string(i)) <= max_machine_groups_pure); // VarM
constraints.push_back(min_products <= getVar(var, "holdA_"+std::to_string(i)) && getVar(var, "holdA_"+std::to_string(i)) <= max_products); // VarHoldA
constraints.push_back(0 <= getVar(var, "insideA_"+std::to_string(i)));
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["BS"]) || getVar(var, "insideA_"+std::to_string(i)) <= 0);
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
|| getVar(var, "insideA_"+std::to_string(i)) <= max_inside_capstation);
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["RS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["RS2"])
|| getVar(var, "insideA_"+std::to_string(i)) <= max_add_bases_ringstation);
constraints.push_back(min_products <= getVar(var, "outputA_"+std::to_string(i)) && getVar(var, "outputA_"+std::to_string(i)) <= max_products); // VarOutsideA
constraints.push_back(0 <= getVar(var, "prepareA_"+std::to_string(i)));
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["BS"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["RS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["RS2"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["DS"])
|| getVar(var, "prepareA_"+std::to_string(i)) <= 1); // Prepared (1) or not (0)
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
|| getVar(var, "prepareA_"+std::to_string(i)) <= max_prepare_capstation);
constraints.push_back(min_products <= getVar(var, "holdB_"+std::to_string(i)) && getVar(var, "holdB_"+std::to_string(i)) <= max_products); // VarHoldB
constraints.push_back(0 <= getVar(var, "insideB_"+std::to_string(i)));
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["BS"]) || getVar(var, "insideB_"+std::to_string(i)) <= 0);
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
|| getVar(var, "insideB_"+std::to_string(i)) <= max_inside_capstation);
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["RS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["RS2"])
|| getVar(var, "insideB_"+std::to_string(i)) <= max_add_bases_ringstation);
constraints.push_back(min_products <= getVar(var, "outputB_"+std::to_string(i)) && getVar(var, "outputB_"+std::to_string(i)) <= max_products); // VarOutsideB
constraints.push_back(0 <= getVar(var, "prepareB_"+std::to_string(i)));
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["BS"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["RS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["RS2"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["DS"])
|| getVar(var, "prepareB_"+std::to_string(i)) <= 1); // Prepared (1) or not (0)
constraints.push_back(!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
|| getVar(var, "prepareB_"+std::to_string(i)) <= max_prepare_capstation);
}
// Constraint: robot states are initially consistent
for(int i=1; i<amount_robots+1; ++i){
for(int ip=1; ip<plan_horizon_pure+1; ++ip){
z3::expr constraint1( !(getVar(var, "R_"+std::to_string(ip)) == i));
for(int ipp=1; ipp<ip; ++ipp){
constraint1 = constraint1 || getVar(var, "R_"+std::to_string(ipp))==i;
}
z3::expr constraint2(var_false);
for(int k=0; k<amount_machines+1; ++k){
for(int l=1; l<amount_machines+1; ++l){
if(k<l){
constraint2 = constraint2 || (getVar(var, "initPos_"+std::to_string(i))==k
&& getVar(var, "pos_"+std::to_string(ip))==l
&& getVar(var, "t_"+std::to_string(ip))>=
getVar(var, "initDist_"+std::to_string(k)+"_"+std::to_string(l)));
}
else if(l<k){
constraint2 = constraint2 || (getVar(var, "initPos_"+std::to_string(i))==k
&& getVar(var, "pos_"+std::to_string(ip))==l
&& getVar(var, "t_"+std::to_string(ip))>=
getVar(var, "initDist_"+std::to_string(l)+"_"+std::to_string(k)));
}
else {
constraint2 = constraint2 || (getVar(var, "initPos_"+std::to_string(i))==k
&& getVar(var, "pos_"+std::to_string(ip))==l
&& getVar(var, "t_"+std::to_string(ip))>=0);
}
}
}
constraints.push_back(constraint1 || (getVar(var, "holdA_"+std::to_string(ip))==getVar(var, "initHold_"+std::to_string(i)) && constraint2));
}
}
// Constraint: robot states are inductively consistent
for(int i=1; i<plan_horizon_pure+1; ++i){
for(int ip=i+1; ip<plan_horizon_pure+1; ++ip){
z3::expr constraint1( !(getVar(var, "R_"+std::to_string(ip)) == getVar(var, "R_"+std::to_string(i))));
for(int ipp=i+1; ipp<ip; ++ipp){
constraint1 = constraint1 || getVar(var, "R_"+std::to_string(ipp))==getVar(var, "R_"+std::to_string(i));
}
z3::expr constraint2(var_false);
for(int k=1; k<amount_machines+1; ++k){
for(int l=1; l<amount_machines+1; ++l){
if(k<l){
constraint2 = constraint2 || (getVar(var, "pos_"+std::to_string(i))==k
&& getVar(var, "pos_"+std::to_string(ip))==l
&& getVar(var, "t_"+std::to_string(ip))>=
getVar(var, "t_"+std::to_string(i))+getVar(var, "rd_"+std::to_string(ip))+getVar(var, "initDist_"+std::to_string(k)+"_"+std::to_string(l)));
}
else if(l<k){
constraint2 = constraint2 || (getVar(var, "pos_"+std::to_string(i))==k
&& getVar(var, "pos_"+std::to_string(ip))==l
&& getVar(var, "t_"+std::to_string(ip))>=
getVar(var, "t_"+std::to_string(i))+getVar(var, "rd_"+std::to_string(ip))+getVar(var, "initDist_"+std::to_string(l)+"_"+std::to_string(k)));
}
else {
constraint2 = constraint2 || (getVar(var, "pos_"+std::to_string(i))==k
&& getVar(var, "pos_"+std::to_string(ip))==l
&& getVar(var, "t_"+std::to_string(ip))>=
getVar(var, "t_"+std::to_string(i))+getVar(var, "rd_"+std::to_string(ip)));
}
}
}
constraints.push_back(constraint1 || (getVar(var, "holdA_"+std::to_string(ip))==getVar(var, "holdB_"+std::to_string(i)) && constraint2));
}
}
// Constraint: machine states are initially consistent
for(int i=min_machine_groups; i<max_machine_groups_pure+1; ++i){
for(int ip=1; ip<plan_horizon_pure+1; ++ip){
z3::expr constraint1( !(getVar(var, "M_"+std::to_string(ip)) == i));
for(int ipp=1; ipp<ip; ++ipp){
constraint1 = constraint1 || getVar(var, "M_"+std::to_string(ipp))==i;
}
z3::expr constraint2(getVar(var, "insideA_"+std::to_string(ip))==getVar(var, "initInside_"+std::to_string(i))
&& getVar(var, "outputA_"+std::to_string(ip))==getVar(var, "initOutside_"+std::to_string(i))
&& getVar(var, "prepareA_"+std::to_string(ip))==getVar(var, "initPrepare_"+std::to_string(i)));
constraints.push_back(constraint1 || constraint2);
}
}
// Constraint: machine states are inductively consistent
for(int i=1; i<plan_horizon_pure+1; ++i){
for(int ip=i+1; ip<plan_horizon_pure+1; ++ip){
z3::expr constraint1( !(getVar(var, "M_"+std::to_string(ip)) == getVar(var, "M_"+std::to_string(i))));
for(int ipp=i+1; ipp<ip; ++ipp){
constraint1 = constraint1 || (getVar(var, "M_"+std::to_string(ipp)) == getVar(var, "M_"+std::to_string(i)));
}
z3::expr constraint2(getVar(var, "t_"+std::to_string(ip))>=getVar(var, "t_"+std::to_string(i))+getVar(var, "md_"+std::to_string(i))
&& getVar(var, "insideB_"+std::to_string(i))==getVar(var, "insideA_"+std::to_string(ip))
&& getVar(var, "outputB_"+std::to_string(i))==getVar(var, "outputA_"+std::to_string(ip))
&& getVar(var, "prepareB_"+std::to_string(i))==getVar(var, "prepareA_"+std::to_string(ip)));
constraints.push_back(constraint1 || constraint2);
}
}
/**
* ADDITIONAL CONSTRAINTS
*/
// Constraints to fix robot order
// Start with R-1
constraints.push_back(getVar(var, "R_1") == 1);
// R-3 is chosen if R-2 has been chosen before
for(int i=2; i<plan_horizon_pure+1; ++i) {
z3::expr constraint_r2_used(var_false);
for(int j=2; j<i; ++j) {
constraint_r2_used = constraint_r2_used || getVar(var, "R_"+std::to_string(j)) == 2;
}
constraints.push_back(!(getVar(var, "R_"+std::to_string(i)) == 3) || constraint_r2_used);
}
// Constraint: every action is encoded for every order
// Save ids of order_colors as strings
std::string base_str = std::to_string(base);
std::string ring1_order_str = std::to_string(rings[0]);
std::string ring2_order_str = std::to_string(rings[1]);
std::string ring3_order_str = std::to_string(rings[2]);
std::string cap_str = std::to_string(cap);
// Init string identifiers for state maps
std::string bi = "B" + base_str;
std::string r1i = "R" + ring1_order_str;
std::string r2i = "R" + ring2_order_str;
std::string r3i = "R" + ring3_order_str;
std::string ci = "C" + cap_str;
// Construct combined string identifiers
std::string br_ci = "BR" + ci;
std::string bi_ci = bi + ci;
std::string bi_r1i = bi + r1i;
std::string bi_r1i_ci = bi_r1i + ci;
std::string bi_r1i_r2i = bi_r1i + r2i;
std::string bi_r1i_r2i_ci = bi_r1i_r2i + ci;
std::string bi_r1i_r2i_r3i = bi_r1i_r2i + r3i;
std::string bi_r1i_r2i_r3i_ci = bi_r1i_r2i_r3i + ci;
std::string has_ci = "has_" + ci;
std::string sub_product;
std::string product;
switch(desired_complexity) {
case 0:
sub_product = bi;
product = bi_ci;
break;
case 1:
sub_product = bi_r1i;
product = bi_r1i_ci;
break;
case 2:
sub_product = bi_r1i_r2i;
product = bi_r1i_r2i_ci;
break;
case 3:
sub_product = bi_r1i_r2i_r3i;
product = bi_r1i_r2i_r3i_ci;
break;
default:
std::cout << "Wrong desired_complexity " << desired_complexity << " to set sub_product and product" << std::endl;
break;
}
// For every step up to the plan_horizon_pure add all req actions depending on the order complexity
for(int i=1; i<plan_horizon_pure+1; ++i){
/*
* ----------------------------------------------------------------------------------------------------------------------------------------------
* Actions all complexities require (which correspond to complexity 0
* ----------------------------------------------------------------------------------------------------------------------------------------------
*/
// 1.Action: Retrieve cap_carrier_cap from CS-Shelf
z3::expr constraint_action1((getVar(var, "M_"+std::to_string(i)) == machine_groups[station_colors[ci]])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputB_"+std::to_string(i)) == getVar(var, "outputA_"+std::to_string(i)))
&& (getVar(var, "prepareB_"+std::to_string(i)) == getVar(var, "prepareA_"+std::to_string(i)))
&& (getVar(var, "md_"+std::to_string(i)) == time_to_fetch)
&& (getVar(var, "pos_"+std::to_string(i)) == node_names_inverted[team + "-" + station_colors[ci] + "-I"])
&& (getVar(var, "holdA_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "holdB_"+std::to_string(i)) == products[br_ci])
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 1) || constraint_action1);
// 2.Action: Prepare CS for RETRIEVE with cap_carrier
z3::expr constraint_action2((getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputB_"+std::to_string(i)) == getVar(var, "outputA_"+std::to_string(i)))
&& (getVar(var, "prepareA_"+std::to_string(i)) == prepare_capstation["not"])
&& (getVar(var, "prepareB_"+std::to_string(i)) == prepare_capstation["retrieve"])
&& (getVar(var, "md_"+std::to_string(i)) == time_to_prep)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"]) || getVar(var, "pos_"+std::to_string(i)) == 2)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"]) || getVar(var, "pos_"+std::to_string(i)) == 4)
&& (getVar(var, "holdB_"+std::to_string(i)) == getVar(var, "holdA_"+std::to_string(i)))
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 2) || constraint_action2);
// 3.Action: Feed cap_carrier into CS for RETRIEVE
z3::expr constraint_action3((getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
&& (getVar(var, "insideA_"+std::to_string(i)) == inside_capstation["nothing"])
&& (getVar(var, "insideB_"+std::to_string(i)) == inside_capstation[has_ci])
&& (getVar(var, "outputA_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "outputB_"+std::to_string(i)) == products["BR"])
&& (getVar(var, "prepareA_"+std::to_string(i)) == prepare_capstation["retrieve"])
&& (getVar(var, "prepareB_"+std::to_string(i)) == prepare_capstation["not"])
&& (getVar(var, "md_"+std::to_string(i)) == time_to_feed)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"]) || getVar(var, "pos_"+std::to_string(i)) == 2)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"]) || getVar(var, "pos_"+std::to_string(i)) == 4)
&& (getVar(var, "holdA_"+std::to_string(i)) == products[br_ci])
&& (getVar(var, "holdB_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 3) || constraint_action3);
// 4.Action: Prepare CS for MOUNT with subproduct
z3::expr constraint_action4((getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
&& (getVar(var, "insideA_"+std::to_string(i)) == inside_capstation[has_ci])
&& (getVar(var, "insideB_"+std::to_string(i)) == inside_capstation[has_ci])
&& (getVar(var, "outputB_"+std::to_string(i)) == getVar(var, "outputA_"+std::to_string(i)))
&& (getVar(var, "prepareA_"+std::to_string(i)) == prepare_capstation["not"])
&& (getVar(var, "prepareB_"+std::to_string(i)) == prepare_capstation["mount"])
&& (getVar(var, "md_"+std::to_string(i)) == time_to_prep)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"]) || getVar(var, "pos_"+std::to_string(i)) == 2)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"]) || getVar(var, "pos_"+std::to_string(i)) == 4)
&& (getVar(var, "holdB_"+std::to_string(i)) == getVar(var, "holdA_"+std::to_string(i)))
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 4) || constraint_action4);
// 5.Action: Feed subproduct into CS for MOUNT
z3::expr constraint_action5((getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
&& (getVar(var, "insideA_"+std::to_string(i)) == inside_capstation[has_ci])
&& (getVar(var, "insideB_"+std::to_string(i)) == inside_capstation["nothing"])
&& (getVar(var, "outputA_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "outputB_"+std::to_string(i)) == products[product])
&& (getVar(var, "prepareA_"+std::to_string(i)) == prepare_capstation["mount"])
&& (getVar(var, "prepareB_"+std::to_string(i)) == prepare_capstation["not"])
&& (getVar(var, "md_"+std::to_string(i)) == time_to_feed)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"]) || getVar(var, "pos_"+std::to_string(i)) == 2)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"]) || getVar(var, "pos_"+std::to_string(i)) == 4)
&& (getVar(var, "holdA_"+std::to_string(i)) == products[sub_product])
&& (getVar(var, "holdB_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 5) || constraint_action5);
// 6.Action: Prepare BS for RETRIEVE with base
z3::expr constraint_action6((getVar(var, "M_"+std::to_string(i)) == machine_groups["BS"])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputB_"+std::to_string(i)) == getVar(var, "outputA_"+std::to_string(i)))
&& (getVar(var, "prepareA_"+std::to_string(i)) == 0)
&& (getVar(var, "prepareB_"+std::to_string(i)) == 1)
&& (getVar(var, "md_"+std::to_string(i)) == time_to_prep)
&& (getVar(var, "pos_"+std::to_string(i)) == 1)
&& (getVar(var, "holdB_"+std::to_string(i)) == getVar(var, "holdA_"+std::to_string(i)))
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 6) || constraint_action6);
// 7.Action: Retrieve base from BS
z3::expr constraint_action7((getVar(var, "M_"+std::to_string(i)) == machine_groups["BS"])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputB_"+std::to_string(i)) == getVar(var, "outputA_"+std::to_string(i)))
&& (getVar(var, "prepareA_"+std::to_string(i)) == 1)
&& (getVar(var, "prepareB_"+std::to_string(i)) == 0)
&& (getVar(var, "md_"+std::to_string(i)) == time_to_fetch)
&& (getVar(var, "pos_"+std::to_string(i)) == 1)
&& (getVar(var, "holdA_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "holdB_"+std::to_string(i)) == products[bi])
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 7) || constraint_action7);
// 8.Action: Discard cap_carrier
z3::expr constraint_action8((getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputA_"+std::to_string(i)) == products["BR"])
&& (getVar(var, "outputB_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "prepareB_"+std::to_string(i)) == getVar(var, "prepareA_"+std::to_string(i)))
&& (getVar(var, "md_"+std::to_string(i)) == time_to_disc)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"]) || getVar(var, "pos_"+std::to_string(i)) == 3)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"]) || getVar(var, "pos_"+std::to_string(i)) == 5)
&& (getVar(var, "holdA_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "holdB_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 8) || constraint_action8);
// 9.Action: Retrieve product from CS
z3::expr constraint_action9((getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"] || getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputA_"+std::to_string(i)) == products[product])
&& (getVar(var, "outputB_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "prepareB_"+std::to_string(i)) == getVar(var, "prepareA_"+std::to_string(i)))
&& (getVar(var, "md_"+std::to_string(i)) == time_to_fetch)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS1"]) || getVar(var, "pos_"+std::to_string(i)) == 3)
&& (!(getVar(var, "M_"+std::to_string(i)) == machine_groups["CS2"]) || getVar(var, "pos_"+std::to_string(i)) == 5)
&& (getVar(var, "holdA_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "holdB_"+std::to_string(i)) == products[product])
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 9) || constraint_action9);
// 10.Action: Prepare DS for DELIVER with product
z3::expr constraint_action10((getVar(var, "M_"+std::to_string(i)) == machine_groups["DS"])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputB_"+std::to_string(i)) == getVar(var, "outputA_"+std::to_string(i)))
&& (getVar(var, "prepareA_"+std::to_string(i)) == 0)
&& (getVar(var, "prepareB_"+std::to_string(i)) == 1)
&& (getVar(var, "md_"+std::to_string(i)) == time_to_prep)
&& (getVar(var, "pos_"+std::to_string(i)) == 6)
&& (getVar(var, "holdB_"+std::to_string(i)) == getVar(var, "holdA_"+std::to_string(i)))
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 10) || constraint_action10);
// 11.Action: Feed product into DS for DELIVER
z3::expr constraint_action11((getVar(var, "M_"+std::to_string(i)) == machine_groups["DS"])
&& (getVar(var, "insideB_"+std::to_string(i)) == getVar(var, "insideA_"+std::to_string(i)))
&& (getVar(var, "outputB_"+std::to_string(i)) == getVar(var, "outputA_"+std::to_string(i)))
&& (getVar(var, "prepareA_"+std::to_string(i)) == 1)
&& (getVar(var, "prepareB_"+std::to_string(i)) == 0)
&& (getVar(var, "md_"+std::to_string(i)) == time_to_feed)
&& (getVar(var, "pos_"+std::to_string(i)) == 6)
&& (getVar(var, "holdA_"+std::to_string(i)) == products[product])
&& (getVar(var, "holdB_"+std::to_string(i)) == products["nothing"])
&& (getVar(var, "rd_"+std::to_string(i)) == 0));
constraints.push_back(!(getVar(var, "A_"+std::to_string(i)) == 11) || constraint_action11);
/*
* ----------------------------------------------------------------------------------------------------------------------------------------------
* Actions complexities 1,2 and 3 require