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

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
    AlexFleischer
    1074 Posts
    ACCEPTED ANSWER

    Re: Logical OR between Constraints

    ‏2013-07-22T19:30:48Z  in response to özgür_ak

    Hi,

    the constraint

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

    is allowed and could help you

     

    • özgür_ak
      özgür_ak
      7 Posts
      ACCEPTED ANSWER

      Re: Logical OR between Constraints

      ‏2013-07-22T19:46:50Z  in response to AlexFleischer

      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
        AlexFleischer
        1074 Posts
        ACCEPTED ANSWER

        Re: Logical OR between Constraints

        ‏2013-07-23T06:31:19Z  in response to özgür_ak

        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