I have a code sample below , Can someone help me explain why the results are different
int : m=3;
int : n=2;
array[1..m,1..n] of int: va=[|1,2|
3,4|
5,6|];
array [1..m,1..n] of var int : val;
constraint forall(i in 1..m,j in 1..n )( i<2->val[i,j]=va[i,j]+1 );
constraint forall(i in 1..m,j in 1..n )( i>=2->val[i,j]=va[i,j]+3 );
output [ show(val) ];
int : m=3;
int : n=2;
array[1..m,1..n] of int: va=[|1,2|
3,4|
5,6|];
array [1..m,1..n] of var int : val;
constraint forall(i in 1..m,j in 1..n )( i>=2->val[i,j]=va[i,j]+3 /\ i<2->val[i,j]=va[i,j]+1 );
output [ show(val) ];
if i can write this logic in one constraint?
In your second model the two implications (->
) and the conjunction (/\
) bind different then using two constraint
sections.
The following give the same result as model 1. Note the parenthesis around the implications:
int : m=3;
int : n=2;
array[1..m,1..n] of int: va=[|1,2|
3,4|
5,6|];
array [1..m,1..n] of var int : val;
constraint forall(i in 1..m,j in 1..n )( (i>=2->val[i,j]=va[i,j]+3) /\
(i<2->val[i,j]=va[i,j]+1) );
output [ show(val) ];
Now both models outputs:
[2, 3, 6, 7, 8, 9]
----------
==========