Topic
2 replies Latest Post - ‏2013-04-05T07:59:05Z by ol
SystemAdmin
SystemAdmin
554 Posts
ACCEPTED ANSWER

Pinned topic Consecutive logical and constraints

‏2013-04-03T22:23:17Z |
Hi,

Could you please tell me how I can model the following in CP optimizer?

W is the array of variables.
n is a constant value

for each 1<=p<=n-1
if W[p]=0 then [all wj]s must be equal to 0 for (p+1<=j<=n)
I know that I can easily present the constraint as follows:

for (p = 1; p < n; i++)
{
for (j = p; p <= n; j++)
model.add(IloIfThen(env, W[p] == 0, W[j] == 0));
}

but to have a stronger propagation I wanna present the "Then" conditional section using consecutive logical and expressions as follows:
model.add(IloIfThen(env, W[p] == 0, (Wp+1 == 0)&&(Wp+2 == 0)&&(Wp+3 == 0)&& .... (W[n] == 0)));
Updated on 2013-04-05T07:59:05Z at 2013-04-05T07:59:05Z by ol
  • SystemAdmin
    SystemAdmin
    554 Posts
    ACCEPTED ANSWER

    Re: Consecutive logical and constraints

    ‏2013-04-04T20:27:56Z  in response to SystemAdmin
    No body has any idea how to present the following constraint?

    model.add(IloIfThen(env, W[p] == 0, (Wp+1 == 0)&&(Wp+2 == 0)&&(Wp+3 == 0)&& .... (W[n] == 0)));
  • ol
    ol
    53 Posts
    ACCEPTED ANSWER

    Re: Consecutive logical and constraints

    ‏2013-04-05T07:59:05Z  in response to SystemAdmin
    Hello,
    you cannot have a stronger propagation, both formulations give the best possible propagation.
    Nevertheless you can use only O(n) instead of O(n*n) constraints, for example:
    
    
    
    for (p = 1; p < n-1; i++) model.add(IloIfThen(env, W[p] == 0, W[p+1] == 0)); 
    }
    


    Regards,
    Olivier