Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Sum multidimensional array

    Posted Thu September 17, 2020 05:17 PM

    Hello ,

    I have a small question. How can I translate this constraint to C++ code, I could not be sure about forall parts ?

    the constraint :

    sum(m in nbMachines) X[p][m][t] = quantity[p][t], forall p and for all t

    What I did :

    for (IloInt p = 0; p < nbProducts; ++p) {

    for (IloInt t = 0; t < nbPeriods; ++t)

    IloExpr v(env);

    for (IloInt m = 0; m < nbMachines; ++m)

    v += X[p][m][t];

    model.add(v == quantity[p][t]);

    v.end();

    }

    is it correct ? If not, how can we fix it ?

    Thank you in advance ;






    #DecisionOptimization
    #Support
    #SupportMigration


  • 2.  RE: Sum multidimensional array

    Posted Mon September 21, 2020 10:59 AM

    Hello Milena,

    Your code looks pretty good only {} are missing.

    for (IloInt p = 0; p < nbProducts; ++p) { for (IloInt t = 0; t < nbPeriods; ++t) { IloExpr v(env); for (IloInt m = 0; m < nbMachines; ++m) v += X[p][m][t]; model.add(v == quantity[p][t]); v.end(); } }

    I hope this helps,

    Chris.






    #DecisionOptimization
    #Support
    #SupportMigration


  • 3.  RE: Sum multidimensional array

    Posted Mon September 21, 2020 12:01 PM

    Hello Chris ,


    Thank you for your reply; After I asked the question, I raelised that I forgot "}" and I modified the code. However, there is somethng I do not understand: I export the model and write the constrainton lp file like this:


     IloCplex cplex(env);

     cplex.extract(model);

     cplex.exportModel("Source.lp");


    Btw;


    NbProducts:3

    Nbmachines:5

    NbPeriods:6


    What I expect :

    X[1][1][1]+X[1][2][1]+X[1][3][1]+X[1][4][1]+X[1][5][1]=quantity[1][1]


    However,

    I get:

    c1: x1 + x2 + x3 + x4 + x5 = quantity

    c2: x6 + x7 + x8 + x9 + x10 = quantity

    c3: x11 + x12 + x13 + x14 + x15 = quantity

    …...………………………………..……...

    ………………...……......………..….

     c18: x86 + x87 + x88 + x89 + x90 = quantity


    Why it is like that? How can I solve this problem ?

    Thank you in advance









    #DecisionOptimization
    #Support
    #SupportMigration