Topic
3 replies Latest Post - ‏2013-01-27T11:02:23Z by SystemAdmin
SystemAdmin
SystemAdmin
2130 Posts
ACCEPTED ANSWER

Pinned topic using "logical or - ||" between each constraint

‏2013-01-11T15:19:51Z |
is there a way using "logical or - ||" between each constraint which are constructed by forall stament. for example:
x[1]=1 ||
x[2]=1 ||
x[3]=1 ||
x[4]=1 ||

how can i write these logical constraints by using forall?

forall(i in 1..4)x[i]==1|| doesn't works...
Updated on 2013-01-27T11:02:23Z at 2013-01-27T11:02:23Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    2130 Posts
    ACCEPTED ANSWER

    Re: using "logical or - ||" between each constraint

    ‏2013-01-14T09:56:29Z  in response to SystemAdmin
    You could use the sum operator to do specify that the sum of variables x in 1..4 that have value 1 should be at least one:

    sum(i in 1..4) (x[i] == 1) >= 1
    


    Since (x[i] == 1) is a boolean variable in 0..1 (0 meaning false, and 1 meaning true), this sum has an equivalent semantic to the disjunction of your example.

    Regards,
    Stefano
    Updated on 2014-03-26T05:51:18Z at 2014-03-26T05:51:18Z by iron-man
    • davidoff
      davidoff
      35 Posts
      ACCEPTED ANSWER

      Re: using "logical or - ||" between each constraint

      ‏2013-01-16T13:31:02Z  in response to SystemAdmin
      If you are in a CP context, it is valid to write
      using CP;
      ...
      or(i in 1..4) x[i]==1
      


      And using CPLEX as the engine, the formulation of the previous post is valid. Note that if your variables are boolean, you have a native linear simplification :

      sum(i in 1..4) x[i] >=1
      


      David
      Updated on 2014-03-26T05:51:13Z at 2014-03-26T05:51:13Z by iron-man
      • SystemAdmin
        SystemAdmin
        2130 Posts
        ACCEPTED ANSWER

        Re: using "logical or - ||" between each constraint

        ‏2013-01-27T11:02:23Z  in response to davidoff
        if i change the constraints like:

        x[1][3][1]+x[3][2][1]=2||
        x[1][4][1]+x[4][2][1]=2||
        x[1][3][2]+x[3][2][2]=2||
        x[1][4][2]+x[4][2][2]=2||
        .
        .
        .
        how can i make these logical constraints in closed form?