-
Notifications
You must be signed in to change notification settings - Fork 0
/
certificate.cpp
1830 lines (1566 loc) · 45.4 KB
/
certificate.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
#include "certificate.h"
#include "file_helper.h"
#include <cmath>
using std::string;
Number zero("0");
//////////////////////////
// Operator definitions //
//////////////////////////
#define LAMBDA(CODE) [&]() -> void { CODE; }
#define LITERAL(VAR) (LAMBDA(write_output(#VAR)))
constexpr int OP_ASSERT = 0;
constexpr int OP_NOT = 1;
constexpr int OP_AND = 2;
constexpr int OP_OR = 3;
constexpr int OP_EQ = 4;
constexpr int OP_NEQ = 5;
constexpr int OP_PLUS = 6;
constexpr int OP_MINUS = 7;
constexpr int OP_TIMES = 8;
constexpr int OP_DIVIDE = 9;
constexpr int OP_LEQ = 10;
constexpr int OP_GEQ = 11;
constexpr int OP_L = 12;
constexpr int OP_G = 13;
constexpr int OP_INTEGRAL = 14;
constexpr int OP_RND_DOWN = 15;
constexpr int OP_ITE = 16;
constexpr int OP_IMPLICATION = 17;
constexpr const char *OP_STRINGS[] = {
"assert",
"not",
"and",
"or",
"=",
"distinct",
"+",
"-",
"*",
"/",
"<=",
">=",
"<",
">",
"is_int",
"to_int",
"ite",
"=>"
};
//////////////////////////
// Precomputation tasks //
//////////////////////////
void Certificate::precompute() {
number_total_constraints = number_problem_constraints + number_derived_constraints;
for(unsigned long i = 0; i < number_variables; i++) {
if(variable_integral_flags[i] == true) {
variable_integral_vector.push_back(i);
}
else {
variable_non_integral_vector.push_back(i);
}
}
calculate_dependencies();
}
void Certificate::calculate_dependencies() {
dependencies.resize(number_total_constraints);
for(unsigned long i = number_problem_constraints; i < number_total_constraints; i++) {
dependencies[i] = new unordered_set<unsigned long>();
switch(get_derivation_from_offset(i).reason.type) {
case ReasonType::TypeASM:
dependencies[i]->insert(i);
break;
case ReasonType::TypeLIN:
case ReasonType::TypeRND:
for(unsigned long dependency_index: get_derivation_from_offset(i).reason.constraint_indexes) {
// If it is one of the problem constraints, there are no assumptions
if(dependency_index < number_problem_constraints) {
continue;
}
// If the dependency has index bigger than or equal to the current one
if(dependency_index >= i) {
throw runtime_error(format("Constraint {} has dependency {} with index bigger than or equal to itself\n", i, dependency_index));
}
auto &other_dependency = dependencies[dependency_index];
dependencies[i]->insert(other_dependency->begin(), other_dependency->end());
}
break;
case ReasonType::TypeUNS:
for(unsigned long dependency_index: get_derivation_from_offset(i).reason.constraint_indexes) {
// If the dependency has index bigger than or equal to the current one
if(dependency_index >= i) {
throw runtime_error(format("Constraint {} has dependency {} with index bigger than or equal to itself\n", i, dependency_index));
}
}
unsigned long dependency_index1 = get_derivation_from_offset(i).reason.get_i1();
if(dependency_index1 >= number_problem_constraints) {
auto &other_dependency1 = dependencies[dependency_index1];
unsigned long exclusion1 = get_derivation_from_offset(i).reason.get_l1();
dependencies[i]->insert(other_dependency1->begin(), other_dependency1->end());
dependencies[i]->erase(exclusion1);
}
unsigned long dependency_index2 = get_derivation_from_offset(i).reason.get_i2();
if(dependency_index2 >= number_problem_constraints) {
auto &other_dependency2 = dependencies[dependency_index2];
unsigned long exclusion2 = get_derivation_from_offset(i).reason.get_l2();
// Only exclude if exclusion2 was not added twice
bool exclude = !(dependencies[i]->contains(exclusion2));
dependencies[i]->insert(other_dependency2->begin(), other_dependency2->end());
if(exclude) {
dependencies[i]->erase(exclusion2);
}
}
break;
// case ReasonType::TypeSOL:
// No action
// break;
}
}
}
//////////////////////////////
// Basic printing functions //
//////////////////////////////
// Space for the 64-bit decimal digits
constexpr size_t BUFFER_LONG_STRING_SIZE = 32;
thread_local FileHelper file_helper;
inline void open_output(string filename) {
file_helper.open_output(filename.c_str());
}
inline void write_output(const char *message) {
file_helper.write_output(message);
}
inline void close_output() {
file_helper.close_output();
}
inline void print_bool(bool variable) {
write_output(variable ? "true" : "false");
}
inline void print_unsigned_long(unsigned long variable) {
char buffer[BUFFER_LONG_STRING_SIZE];
snprintf(buffer, BUFFER_LONG_STRING_SIZE, "%lu", variable);
write_output(buffer);
}
inline void print_integral_string(char *number) {
if(number[0] == '-') {
write_output("(- ");
write_output(number + 1);
write_output(")");
}
else {
write_output(number);
}
}
inline void print_number(Number &number) {
if(number.is_integral) {
print_integral_string(number.numerator);
}
else {
write_output("(/ ");
print_integral_string(number.numerator);
write_output(" ");
print_integral_string(number.denominator);
write_output(")");
}
}
////////////////////////
// Generate functions //
////////////////////////
inline void generate(bool variable) {
print_bool(variable);
}
inline void generate(unsigned long variable) {
print_unsigned_long(variable);
}
template<typename F>
inline void generate(F &&function) {
function();
}
template<>
inline void generate(bool &variable) {
print_bool(variable);
}
template<>
inline void generate(unsigned long &variable) {
print_unsigned_long(variable);
}
template<>
inline void generate(Number &variable) {
print_number(variable);
}
template<>
inline void generate(const char *&literal) {
write_output(literal);
}
template<typename T, typename U, typename W>
inline void ensure_minimum(T count, U minimum, W &&function) {
for(auto i = count + 1; i <= minimum; i++) {
function();
write_output(" ");
}
}
// For handling minimum arguments
#define MIN_SET(val) unsigned long __count = 0; unsigned long __minimum = val;
#define MIN_COUNT __count++;
#define MIN_ENSURE(CODE) ensure_minimum(__count, __minimum, CODE);
#define MIN_ENSURE_ZERO MIN_ENSURE(LAMBDA(print_integral_string("0")))
#define MIN_ENSURE_TRUE MIN_ENSURE(LAMBDA(print_bool(true)));
#define MIN_ENSURE_FALSE MIN_ENSURE(LAMBDA(print_bool(false)));
//////////////////////////////////////////////////
// Generating operators and logical constraints //
//////////////////////////////////////////////////
template<int OP_INDEX, typename T>
inline void print_op1(T &&variable) {
write_output("(");
write_output(OP_STRINGS[OP_INDEX]); // TODO: Construct at compile time?
write_output(" ");
generate<T>(std::forward<T>(variable));
write_output(")");
}
template<int OP_INDEX, typename T, typename U>
inline void print_op2(T &&variable1, U &&variable2) {
write_output("(");
write_output(OP_STRINGS[OP_INDEX]); // TODO: Construct at compile time?
write_output(" ");
generate<T>(std::forward<T>(variable1));
write_output(" ");
generate<U>(std::forward<U>(variable2));
write_output(")");
}
template<typename T, typename U>
inline void print_direction_op2(Direction direction, T &&variable1, U &&variable2) {
write_output("(");
switch(direction) {
case Direction::SmallerEqual:
write_output(OP_STRINGS[OP_LEQ]);
break;
case Direction::Equal:
write_output(OP_STRINGS[OP_EQ]);
break;
case Direction::GreaterEqual:
write_output(OP_STRINGS[OP_GEQ]);
break;
}
write_output(" ");
generate<T>(std::forward<T>(variable1));
write_output(" ");
generate<U>(std::forward<U>(variable2));
write_output(")");
}
template<typename T, typename U, typename W>
inline void print_ifelse(T &&test, U &&if_value, W &&else_value) {
print_op1<OP_ITE>(
[&test, &if_value, &else_value] {
generate<T>(std::forward<T>(test));
write_output(" ");
generate<U>(std::forward<U>(if_value));
write_output(" ");
generate<W>(std::forward<W>(else_value));
}
);
}
template<typename T>
inline void print_ceil(T &¶meter) {
print_op1<OP_MINUS>(
[¶meter] {
print_op1<OP_RND_DOWN>(
[¶meter] { print_op1<OP_MINUS>(parameter); }
);
}
);
}
inline void print_s(Direction direction) {
switch(direction) {
case Direction::SmallerEqual:
print_op1<OP_MINUS>(
LITERAL(1)
);
break;
case Direction::Equal:
print_integral_string("0");
break;
case Direction::GreaterEqual:
print_integral_string("1");
break;
}
}
///////////////////////////
// Print header & footer //
///////////////////////////
void print_header() {
write_output("(set-info :smt-lib-version 2.6)\n");
write_output("(set-logic QF_LIRA)\n");
write_output("(set-info :source \"Transformed from a VIPR certificate\")\n");
write_output("; --- END HEADER --- \n\n");
}
void print_footer() {
write_output("(check-sat)\n");
}
/////////////////////////////
// Print model constraints //
/////////////////////////////
bool Certificate::get_PUB() {
return (feasible && !feasible_upper_bound.is_positive_infinity);
}
bool Certificate::get_PLB() {
return (feasible && !feasible_lower_bound.is_negative_infinity);
}
Number &Certificate::get_U() {
return (get_PUB() ? feasible_upper_bound : zero);
}
Number &Certificate::get_L() {
return (get_PLB() ? feasible_lower_bound : zero);
}
void Certificate::print_pub() {
print_op2<OP_AND>(
feasible,
LAMBDA(print_bool(!(feasible_upper_bound.is_positive_infinity)))
);
}
void Certificate::print_plb() {
print_op2<OP_AND>(
feasible,
LAMBDA(print_bool(!(feasible_lower_bound.is_negative_infinity)))
);
}
void Certificate::print_respect_bound(vector<Number> &coefficients, vector<Number> &assignments, Direction direction, Number &target) {
print_direction_op2(
direction,
LAMBDA(
print_op1<OP_PLUS>(LAMBDA(
#ifndef FULL_MODEL
MIN_SET(2);
#endif /* !FULL_MODEL */
for(unsigned long i = 0; i < number_variables; i++) {
#ifndef FULL_MODEL
auto &coefficient = coefficients[i];
auto &assignment = assignments[i];
if(coefficient.is_zero() || assignment.is_zero()) {
continue;
}
MIN_COUNT;
#endif /* !FULL_MODEL */
print_op2<OP_TIMES>(
LAMBDA(print_number(coefficient)),
LAMBDA(print_number(assignment))
);
// Space between multiplicative terms on the left-hand side
write_output(" ");
}
#ifndef FULL_MODEL
MIN_ENSURE_ZERO;
#endif /* !FULL_MODEL */
));
),
LAMBDA(print_number(target))
);
}
// TODO: This function is too similar to the one above. Consider creating one function that handles both
void Certificate::print_respect_bound(Constraint &constraint, vector<Number> &assignments, Direction direction, Number &target) {
print_direction_op2(
direction,
LAMBDA(
print_op1<OP_PLUS>(LAMBDA(
#ifndef FULL_MODEL
MIN_SET(2);
#endif /* !FULL_MODEL */
for(unsigned long i = 0; i < number_variables; i++) {
#ifndef FULL_MODEL
auto &coefficient = constraint.coefficients_at(i);
auto &assignment = assignments[i];
if(coefficient.is_zero() || assignment.is_zero()) {
continue;
}
MIN_COUNT;
#endif /* !FULL_MODEL */
print_op2<OP_TIMES>(
LAMBDA(print_number(coefficient)),
LAMBDA(print_number(assignment))
);
// Space between multiplicative terms on the left-hand side
write_output(" ");
}
#ifndef FULL_MODEL
MIN_ENSURE_ZERO;
#endif /* !FULL_MODEL */
));
),
LAMBDA(print_number(target))
);
}
void Certificate::print_one_solution_within_bound(Direction direction, Number &bound) {
print_op1<OP_OR>(LAMBDA(
MIN_SET(2);
for(Solution &solution: solutions) {
print_respect_bound(objective_coefficients, solution.assignments, direction, bound);
// Space between terms
write_output(" ");
MIN_COUNT;
}
MIN_ENSURE_FALSE;
));
}
void Certificate::print_all_solutions_within_bound(Direction direction, Number &bound) {
print_op1<OP_AND>(LAMBDA(
MIN_SET(2);
for(Solution &solution: solutions) {
print_respect_bound(objective_coefficients, solution.assignments, direction, bound);
// Space between terms
write_output(" ");
MIN_COUNT;
}
MIN_ENSURE_TRUE;
));
}
void Certificate::print_feas_individual(Solution &solution) {
// TODO: Check: Note that I check for solution integrals only once. Can we reflect in the model?
print_op1<OP_AND>(LAMBDA(
MIN_SET(2);
for(unsigned long i: variable_integral_vector) {
print_bool(solution.assignments[i].is_integral);
// Space between terms
write_output(" ");
MIN_COUNT;
}
for(int constraint_index = 0; constraint_index < number_problem_constraints; constraint_index++) {
Constraint &constraint = constraints[constraint_index];
print_op2<OP_IMPLICATION>(
LAMBDA(print_op2<OP_GEQ>(
LAMBDA(print_s(constraint.direction)),
LITERAL(0)
)),
LAMBDA(
print_respect_bound(constraint, solution.assignments, Direction::GreaterEqual, constraint.target);
)
);
MIN_COUNT;
print_op2<OP_IMPLICATION>(
LAMBDA(print_op2<OP_LEQ>(
LAMBDA(print_s(constraint.direction)),
LITERAL(0)
)),
LAMBDA(
print_respect_bound(constraint, solution.assignments, Direction::SmallerEqual, constraint.target);
)
);
MIN_COUNT;
// Space between terms
write_output(" ");
}
MIN_ENSURE_TRUE;
));
}
void Certificate::print_feas() {
print_op1<OP_AND>(LAMBDA(
MIN_SET(2);
for(Solution &solution: solutions) {
print_feas_individual(solution);
// Space between terms
write_output(" ");
MIN_COUNT;
}
MIN_ENSURE_TRUE;
));
}
void Certificate::print_pubimplication() {
print_op2<OP_IMPLICATION>(
LAMBDA(print_pub()),
LAMBDA(print_one_solution_within_bound(Direction::SmallerEqual, get_U()))
);
}
void Certificate::print_plbimplication() {
print_op2<OP_IMPLICATION>(
LAMBDA(print_plb()),
LAMBDA(print_one_solution_within_bound(Direction::GreaterEqual, get_L()))
);
}
void Certificate::print_sol() {
auto task_print_sol = [&, this] {
write_output("; Begin SOL\n");
print_op1<OP_ASSERT>(LAMBDA(
print_ifelse(
LAMBDA(print_op1<OP_NOT>(feasible)),
LAMBDA(print_op2<OP_EQ>(number_solutions, LITERAL(0))),
LAMBDA(print_op2<OP_AND>(
LAMBDA(print_feas()),
LAMBDA(print_ifelse(
minimization,
LAMBDA(print_pubimplication()),
LAMBDA(print_plbimplication())
))
))
)
));
};
#ifdef PARALLEL
threads.emplace_back([&, this] {
// Open the file for SOL and print header
string section_output_filename = output_filename + ".SOL";
open_output(section_output_filename);
print_header();
task_print_sol();
// Print footer and close the file for block number
print_footer();
close_output();
// Dispatches the work to the execution manager
remote_execution_manager.dispatch(section_output_filename, 0);
});
#else
task_print_sol();
#endif /* PARALLEL */
}
bool Certificate::calculate_Aij(unsigned long i, unsigned long j) {
if(dependencies[i] == nullptr) {
return false;
}
return (dependencies[i]->contains(j));
}
void Certificate::print_ASM(unsigned long k, Derivation &derivation) {
#ifndef AIJ_SMT
bool result = true;
#endif /* AIJ_SMT */
for(unsigned long j = k + 1; j < number_total_constraints; j++) {
if(get_derivation_from_offset(j).reason.type == ReasonType::TypeASM) {
#ifndef AIJ_SMT
result &= !calculate_Aij(k, j);
#else
print_op1<OP_NOT>(LAMBDA(print_bool(calculate_Aij(k, j))));
#endif /* AIJ_SMT */
}
}
#ifndef AIJ_SMT
print_bool(result);
write_output(" ");
#endif /* AIJ_SMT */
switch(derivation.reason.type) {
case ReasonType::TypeASM:
print_op2<OP_AND>(
LAMBDA(print_bool(calculate_Aij(k, k))),
LAMBDA(print_op1<OP_AND>(
LAMBDA(
MIN_SET(2);
#ifndef AIJ_SMT
bool result = true;
#endif /* AIJ_SMT */
for(unsigned long j = number_problem_constraints; j < k; j++) {
if(get_derivation_from_offset(j).reason.type == ReasonType::TypeASM) {
#ifndef AIJ_SMT
result &= (!calculate_Aij(k, j));
#else
print_op1<OP_NOT>(LAMBDA(print_bool(calculate_Aij(k, j))));
MIN_COUNT;
#endif /* AIJ_SMT */
}
}
#ifndef AIJ_SMT
print_bool(result);
write_output(" ");
MIN_COUNT;
#endif /* AIJ_SMT */
MIN_ENSURE_TRUE;
)
))
);
break;
case ReasonType::TypeLIN:
case ReasonType::TypeRND:
print_op1<OP_AND>(LAMBDA(
MIN_SET(2);
#ifndef AIJ_SMT
bool result = true;
#endif /* AIJ_SMT */
for(unsigned long j = number_problem_constraints; j < k; j++) {
if(get_derivation_from_offset(j).reason.type == ReasonType::TypeASM) {
#ifndef AIJ_SMT
bool inner1 = calculate_Aij(k, j);
bool inner2 = false;
for(unsigned long &i: derivation.reason.constraint_indexes) {
if(j <= i && i < k) {
inner2 |= calculate_Aij(i, j);
}
}
result &= (inner1 == inner2);
continue;
#endif /* AIJ_SMT */
print_op2<OP_EQ>(
LAMBDA(print_bool(calculate_Aij(k, j))),
LAMBDA(print_op1<OP_OR>(
LAMBDA(
MIN_SET(2);
for(unsigned long &i: derivation.reason.constraint_indexes) {
if(j <= i && i < k) {
print_bool(calculate_Aij(i, j));
// Space between terms
write_output(" ");
MIN_COUNT;
}
}
MIN_ENSURE_FALSE;
)
))
);
MIN_COUNT;
}
}
#ifndef AIJ_SMT
print_bool(result);
write_output(" ");
MIN_COUNT;
#endif /* AIJ_SMT */
MIN_ENSURE_TRUE;
));
break;
case ReasonType::TypeUNS:
print_op1<OP_AND>(LAMBDA(
MIN_SET(2);
#ifndef AIJ_SMT
bool result = true;
#endif /* AIJ_SMT */
for(unsigned long j = number_problem_constraints; j < k; j++) {
if(get_derivation_from_offset(j).reason.type == ReasonType::TypeASM) {
#ifndef AIJ_SMT
bool inner1 = calculate_Aij(k, j);
bool inner1a = calculate_Aij(derivation.reason.get_i1(), j) && (j != derivation.reason.get_l1());
bool inner1b = calculate_Aij(derivation.reason.get_i2(), j) && (j != derivation.reason.get_l2());
result &= (inner1 == (inner1a || inner1b));
continue;
#endif /* AIJ_SMT */
print_op2<OP_EQ>(
LAMBDA(print_bool(calculate_Aij(k, j))),
LAMBDA(print_op2<OP_OR>(
LAMBDA(print_op2<OP_AND>(
LAMBDA(print_bool(calculate_Aij(derivation.reason.get_i1(), j))),
LAMBDA(print_op2<OP_NEQ>(j, derivation.reason.get_l1()))
)),
LAMBDA(print_op2<OP_AND>(
LAMBDA(print_bool(calculate_Aij(derivation.reason.get_i2(), j))),
LAMBDA(print_op2<OP_NEQ>(j, derivation.reason.get_l2()))
))
))
);
MIN_COUNT;
}
}
#ifndef AIJ_SMT
print_bool(result);
write_output(" ");
MIN_COUNT;
#endif /* AIJ_SMT */
MIN_ENSURE_TRUE;
));
break;
case ReasonType::TypeSOL:
print_op1<OP_AND>(LAMBDA(
MIN_SET(2);
#ifndef AIJ_SMT
bool result = true;
for(unsigned long j = number_problem_constraints; j < k; j++) {
if(get_derivation_from_offset(j).reason.type == ReasonType::TypeASM) {
result &= !calculate_Aij(k, j);
}
}
print_bool(result);
write_output(" ");
MIN_COUNT;
return;
#endif /* AIJ_SMT */
for(unsigned long j = number_problem_constraints; j < k; j++) {
if(get_derivation_from_offset(j).reason.type == ReasonType::TypeASM) {
print_op1<OP_NOT>(
LAMBDA(print_bool(calculate_Aij(k, j)))
);
MIN_COUNT;
}
}
MIN_ENSURE_TRUE;
));
break;
}
}
void Certificate::print_PRV(unsigned long k, Derivation &derivation) {
print_op1<OP_AND>(LAMBDA(
MIN_SET(2);
for(unsigned long &j: derivation.reason.constraint_indexes) {
print_op2<OP_AND>(
LAMBDA(
print_op2<OP_L>(j, k)
),
LAMBDA(
print_op2<OP_GEQ>(j, LITERAL(0))
)
);
MIN_COUNT;
}
MIN_ENSURE_TRUE;
));
}
template<typename PQ, typename PQP, typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
void Certificate::print_DOM(PQ &&a, P0 &&b, P1 &&eq, P2 &&geq, P3 &&leq, PQP &&aP, P4 &&bP, P5 &&eqP, P6 &&geqP, P7 &&leqP) {
print_op2<OP_OR>(
LAMBDA(
print_op2<OP_AND>(
LAMBDA(
for(unsigned long j = 0; j < number_variables; j++) {
print_op2<OP_EQ>(LAMBDA(a(j)), LITERAL(0));
}
),
LAMBDA(
print_ifelse(
eq,
LAMBDA(
print_op2<OP_NEQ>(b, LITERAL(0))
),
LAMBDA(print_ifelse(
geq,
LAMBDA(print_op2<OP_G>(b, LITERAL(0))),
LAMBDA(print_ifelse(
leq,
LAMBDA(print_op2<OP_L>(b, LITERAL(0))),
LAMBDA(print_bool(false))
))
))
)
)
)
),
LAMBDA(
print_op2<OP_AND>(
LAMBDA(
for(unsigned long j = 0; j < number_variables; j++) {
print_op2<OP_EQ>(LAMBDA(a(j)), LAMBDA(aP(j)));
}
),
LAMBDA(
print_ifelse(
eqP,
LAMBDA(
print_op2<OP_AND>(
eq,
LAMBDA(print_op2<OP_EQ>(b, bP))
)
),
LAMBDA(print_ifelse(
geqP,
LAMBDA(
print_op2<OP_AND>(
geq,
LAMBDA(print_op2<OP_GEQ>(b, bP))
)
),
LAMBDA(print_ifelse(
leqP,
LAMBDA(
print_op2<OP_AND>(
leq,
LAMBDA(print_op2<OP_LEQ>(b, bP))
)
),
LAMBDA(print_bool(false))
))
))
)
)
)
)
);
}
template<typename P0, typename P1, typename P2, typename P3, typename P4, typename P5>
void Certificate::print_DOM(P0 &&print_coefficientA, P1 &&print_directionA, P2 &&print_targetA, P3 &&print_coefficientB, P4 &&print_directionB, P5 &&print_targetB) {
print_DOM(
print_coefficientA,
print_targetA,
LAMBDA(print_op2<OP_EQ>(
print_directionA,
LITERAL(0)
)),
LAMBDA(print_op2<OP_GEQ>(
print_directionA,
LITERAL(0)
)),
LAMBDA(print_op2<OP_LEQ>(
print_directionA,
LITERAL(0)
)),
print_coefficientB,
print_targetB,
LAMBDA(print_op2<OP_EQ>(
print_directionB,
LITERAL(0)
)),
LAMBDA(print_op2<OP_GEQ>(
print_directionB,
LITERAL(0)
)),
LAMBDA(print_op2<OP_LEQ>(
print_directionB,
LITERAL(0)
))
);
}
void Certificate::print_DOM(Constraint &constraint1, Constraint &constraint2) {
print_DOM(
[&] (unsigned long j) {
print_number(constraint1.coefficients_at(j));
},
LAMBDA(print_number(constraint1.target)),
LAMBDA(print_op2<OP_EQ>(
LAMBDA(print_s(constraint1.direction)),
LITERAL(0)
)),
LAMBDA(print_op2<OP_GEQ>(
LAMBDA(print_s(constraint1.direction)),
LITERAL(0)
)),
LAMBDA(print_op2<OP_LEQ>(
LAMBDA(print_s(constraint1.direction)),
LITERAL(0)
)),
[&] (unsigned long j) {
print_number(constraint2.coefficients_at(j));
},
LAMBDA(print_number(constraint2.target)),
LAMBDA(print_op2<OP_EQ>(
LAMBDA(print_s(constraint2.direction)),
LITERAL(0)
)),
LAMBDA(print_op2<OP_GEQ>(
LAMBDA(print_s(constraint2.direction)),
LITERAL(0)
)),
LAMBDA(print_op2<OP_LEQ>(
LAMBDA(print_s(constraint2.direction)),
LITERAL(0)
))
);
}
template<typename P0, typename P1>
void Certificate::print_RND(const function<void(unsigned long)> &a, P0 &&b, P1 &&eq) {
print_op1<OP_AND>(
LAMBDA(
MIN_SET(2);
for(unsigned long j: variable_integral_vector) {
print_op1<OP_INTEGRAL>(LAMBDA(a(j)));
MIN_COUNT;
}
for(unsigned long j: variable_non_integral_vector) {
print_op2<OP_EQ>(LAMBDA(a(j)), LITERAL(0));
MIN_COUNT;
}
print_op1<OP_NOT>(eq);
MIN_COUNT;