Topic
  • 3 replies
  • Latest Post - ‏2013-01-27T11:02:23Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

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
    1883 Posts

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

    ‏2013-01-14T09:56:29Z  
    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
    55 Posts

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

    ‏2013-01-16T13:31:02Z  
    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:

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">sum(i in 1..4) (x[i] == 1) >= 1 </pre>

    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
    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
    1883 Posts

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

    ‏2013-01-27T11:02:23Z  
    • davidoff
    • ‏2013-01-16T13:31:02Z
    If you are in a CP context, it is valid to write
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">using CP; ... or(i in 1..4) x[i]==1 </pre>

    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 :

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">sum(i in 1..4) x[i] >=1 </pre>

    David
    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?