Topic
  • 4 replies
  • Latest Post - ‏2014-03-11T19:25:22Z by Trust20092009
Trust20092009
Trust20092009
3 Posts

Pinned topic IlcCount Or IlcExpr

‏2014-03-11T00:05:43Z |

Hi,

I have a vector of integers  x ={ x1, ... ,xn } and i want to express that at least one component of x must be set to "k" (I.e IloCount(x,k) >0 in a model).

I'm looking for similar functionnality of a IloCount or IloExpr to add this constraint to a cp during search (IlcCount doesn't exist ).

Best regards,

S.S

  • ol
    ol
    62 Posts

    Re: IlcCount Or IlcExpr

    ‏2014-03-11T13:36:23Z  

    Hello,

    you could use:

       IlcConstraint IlcCardIntEqCst(const IlcIntExp var, IlcInt val, const IlcIntVarArray vars)

    In your specific case, you could add instead a constraint like

        x1==k || x2==k || ...

    Or:

       (x1==k) + (x2==k) +  ... > 0

    in some cases they may be more efficient.

    Finally, if you have several such constraints to add which share the same variables x, it may be more efficient to add a IlcDistribute constraint grouping these constraints together.

    Regards,

    Olivier

     

  • Trust20092009
    Trust20092009
    3 Posts

    Re: IlcCount Or IlcExpr

    ‏2014-03-11T16:14:31Z  
    • ol
    • ‏2014-03-11T13:36:23Z

    Hello,

    you could use:

       IlcConstraint IlcCardIntEqCst(const IlcIntExp var, IlcInt val, const IlcIntVarArray vars)

    In your specific case, you could add instead a constraint like

        x1==k || x2==k || ...

    Or:

       (x1==k) + (x2==k) +  ... > 0

    in some cases they may be more efficient.

    Finally, if you have several such constraints to add which share the same variables x, it may be more efficient to add a IlcDistribute constraint grouping these constraints together.

    Regards,

    Olivier

     

    Hello Olivier,

    Thank you for your quick reply. Effectively IlcDistribute could meet my needs.

    But i do not understand the functionning of IlcCardIntEqCst I don't find it anywhere in the cp manuel can you explain more please?

    To use x1==k || x2==k || ...  Or:    (x1==k) + (x2==k) +  ... > 0 I need an expression. that's why I'm looking for a similar functionnality of IloExpr ( i.e IlcExpr).  am I right or I may be missing something important?

    Regards,

    S.S

  • ol
    ol
    62 Posts

    Re: IlcCount Or IlcExpr

    ‏2014-03-11T17:17:12Z  

    Hello Olivier,

    Thank you for your quick reply. Effectively IlcDistribute could meet my needs.

    But i do not understand the functionning of IlcCardIntEqCst I don't find it anywhere in the cp manuel can you explain more please?

    To use x1==k || x2==k || ...  Or:    (x1==k) + (x2==k) +  ... > 0 I need an expression. that's why I'm looking for a similar functionnality of IloExpr ( i.e IlcExpr).  am I right or I may be missing something important?

    Regards,

    S.S

     IlcConstraint IlcCardIntEqCst(const IlcIntExp var, IlcInt val, const IlcIntVarArray vars) returns a constraint that ensures that val appears var times in the array vars.

    For building an expression at the Ilc level, you are right, this is exactly as at the Ilo Level, but with IlcIntExp, for example:

    IlcIntVarArray x(m,3,1,2);

    IlcIntVar xx(m,1,3,"xx");

    IlcIntExp e = IlcIntExp(x[0]==1);

    for(IlcInt i = 1;i<3;i++) {

    e = e + (x[i]==1);

    }

     

    Regards,

    Olivier

     

  • Trust20092009
    Trust20092009
    3 Posts

    Re: IlcCount Or IlcExpr

    ‏2014-03-11T19:25:22Z  
    • ol
    • ‏2014-03-11T17:17:12Z

     IlcConstraint IlcCardIntEqCst(const IlcIntExp var, IlcInt val, const IlcIntVarArray vars) returns a constraint that ensures that val appears var times in the array vars.

    For building an expression at the Ilc level, you are right, this is exactly as at the Ilo Level, but with IlcIntExp, for example:

    IlcIntVarArray x(m,3,1,2);

    IlcIntVar xx(m,1,3,"xx");

    IlcIntExp e = IlcIntExp(x[0]==1);

    for(IlcInt i = 1;i<3;i++) {

    e = e + (x[i]==1);

    }

     

    Regards,

    Olivier

     

    That's  exactly what i need. Thank's a lot Olivier. Have a good day :)

    Regards,

    S.S