Topic
• 4 replies
• Latest Post - ‏2013-07-26T10:35:42Z by özgür_ak
özgür_ak
9 Posts

Pinned topic Logical OR between Constraints

‏2013-07-20T11:22:32Z |

X[i][j][k] is boolean.

x[1][3][1]+x[1][3][2]=2||
x[1][4][2]+x[1][4][2]=2||

x[2][3][1]+x[2][3][2]=2||
x[2][4][2]+x[2][4][2]=2||
.
.
.

i wanna write these constraint in closed format. Wtihout logical OR we can write

"  forall(i in 1..2, j in 3..4)        sum(k in 1..2) x[i][j][k] "

with logical OR  how can i do that? Any idea?

Updated on 2013-07-24T04:24:45Z at 2013-07-24T04:24:45Z by özgür_ak
• AlexFleischer
2823 Posts

Re: Logical OR between Constraints

‏2013-07-23T06:31:19Z

Thanks for your answer but my point is i am not able to write in closed format. your suggestion is not in closed format. if you have other ideas please tell me i am stuck with that.

Hi

if you use constraint programming you can write

``````
using CP;
int n = 5;
range R = 1..n;
dvar int x[R] in R;
maximize sum(i in R)x[i];
subject to
{
or(i in 1..5:i % 2==1) x[i]==1;
or(i in 1..5:i % 2==0) x[i]==2;
}```
```

`without constraint programming this can be rewritten into`

int n = 5;

range R = 1..n;
dvar int x[R] in R;

maximize sum(i in R)x[i];

subject to {
sum(i in 1..5:i % 2==1) (x[i]==1)>=1;
sum(i in 1..5:i % 2==0) (x[i]==2)>=1;
}

Regards

Alex Fleischer

Updated on 2013-07-23T06:32:16Z at 2013-07-23T06:32:16Z by AlexFleischer
• AlexFleischer
2823 Posts

Re: Logical OR between Constraints

‏2013-07-22T19:30:48Z

Hi,

the constraint

(x[1][3][1]+x[1][3][1]==2) ||
(x[1][3][1]+x[1][3][2]==2)

• özgür_ak
9 Posts

Re: Logical OR between Constraints

‏2013-07-22T19:46:50Z

Hi,

the constraint

(x[1][3][1]+x[1][3][1]==2) ||
(x[1][3][1]+x[1][3][2]==2)

Thanks for your answer but my point is i am not able to write in closed format. your suggestion is not in closed format. if you have other ideas please tell me i am stuck with that.

• AlexFleischer
2823 Posts

Re: Logical OR between Constraints

‏2013-07-23T06:31:19Z

Thanks for your answer but my point is i am not able to write in closed format. your suggestion is not in closed format. if you have other ideas please tell me i am stuck with that.

Hi

if you use constraint programming you can write

``````
using CP;
int n = 5;
range R = 1..n;
dvar int x[R] in R;
maximize sum(i in R)x[i];
subject to
{
or(i in 1..5:i % 2==1) x[i]==1;
or(i in 1..5:i % 2==0) x[i]==2;
}```
```

`without constraint programming this can be rewritten into`

int n = 5;

range R = 1..n;
dvar int x[R] in R;

maximize sum(i in R)x[i];

subject to {
sum(i in 1..5:i % 2==1) (x[i]==1)>=1;
sum(i in 1..5:i % 2==0) (x[i]==2)>=1;
}

Regards

Alex Fleischer

Updated on 2013-07-23T06:32:16Z at 2013-07-23T06:32:16Z by AlexFleischer
• özgür_ak
9 Posts

Re: Logical OR between Constraints

‏2013-07-26T10:35:42Z

Hi

if you use constraint programming you can write

<pre class="pre codeblock" dir="ltr">``` using CP; int n = 5; range R = 1..n; dvar int x[R] in R; maximize sum(i in R)x[i]; subject to { or(i in 1..5:i % 2==1) x[i]==1; or(i in 1..5:i % 2==0) x[i]==2; }``` </pre>

`without constraint programming this can be rewritten into`

int n = 5;

range R = 1..n;
dvar int x[R] in R;

maximize sum(i in R)x[i];

subject to {
sum(i in 1..5:i % 2==1) (x[i]==1)>=1;
sum(i in 1..5:i % 2==0) (x[i]==2)>=1;
}

Regards

Alex Fleischer

Thanks Alex it worked :)