Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only

How to multiply an integer decision variable and a second decision variable

  • 1.  How to multiply an integer decision variable and a second decision variable

    Posted 09/27/17 02:55 PM

    Hi,

     

    recently I wrote some posts about multiply:

    - multiply two binary decision variables : https://www.ibm.com/developerworks/community/forums/html/topic?id=d234cf8b-e13f-43ca-9a53-f9fb96b7709c&ps=25

    - How to multiply a decision variable with a boolean decision variable : https://www.ibm.com/developerworks/community/forums/html/topic?id=aa9aa3db-4fbc-4209-a767-5b5e54902cbd&ps=25

    - How to multiply two float decision variables : https://www.ibm.com/developerworks/community/forums/html/topic?id=f48c280e-144b-46aa-abb9-906a4eb4219f&ps=25

    But this was not enough. And I was asked what to do for products of two integer decision variables, which also works for product of integer decision variable and float decision variable.

    Let me give you a few options:

    1) Simply rely on CPO

    using CP;

    range r=1..100;
    dvar int x in r;;
    dvar int y in r;

    subject to
    {
    x*y==169;
    }

    2)  Use CPLEX and logical constraints

    range r=1..100;
    dvar int x in r;;
    dvar int y in r;
    dvar int xy;

    subject to
    {
    xy==169;

    forall(pos in r) (x==pos) => (xy==pos*y);
    }

    This way leads to 200 variables in the CPLEX matrix

    3) Use logical constraints and dichotomy

    range r=1..100;

    dvar boolean b[0..6];
    dvar int by[0..6];
    dvar int x in r;;
    dvar int y in r;
    dvar int xy;

    subject to
    {
    xy==169;

    x==sum(i in 0..6) ftoi(pow(2,i))*b[i];

    forall(i in 0..6)
    {
    b[i]==1 => by[i]==y*ftoi(pow(2,i));
    b[i]==0 => by[i]==0;
    }

    xy==sum(i in 0..6) by[i];
    }

    This way leads to 45 variables in the CPLEX matrix

    4) Linearize and dichotomy

    int n=100;
    range r=1..n;

    dvar boolean b[0..6];
    dvar int by[0..6];
    dvar int x in r;;
    dvar int y in r;
    dvar int xy;

    subject to
    {
    xy==169;

     

    x==sum(i in 0..6) ftoi(pow(2,i))*b[i];

    forall(i in 0..6)
    {


    //by[i]==y*b[i]*ftoi(pow(2,i));

     b[i]*ftoi(pow(2,i))<=by[i];
    by[i]<=n*b[i]*ftoi(pow(2,i));

    by[i]<=y*ftoi(pow(2,i));
    by[i]>=ftoi(pow(2,i))*(y-n*(1-b[i]));

    }

    This way leads to 17 variables in the CPLEX matrix

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer