Decision Optimization

Decision Optimization

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

 View Only
  • 1.  c++ cplex IloNumVarArray problem

    Posted Thu July 04, 2013 09:41 AM

    Originally posted by: babyvera


    Hi all. I am the beginner of the c++ cplex. I have a qusetion about the IloNumVarArray. I spend 5 days on this question,but failed.
    First  I use  'IloNumVarArray' to set up a array with 5 elements, named f. Then use 'add' to make 5 arrays become a 5*5 matrix named fij. Third I want to row sum. Except use fij[1]+ fij[2]+ fij[3]+ fij[4]+ fij[5] , Are there any other way to solve this problem? Because the model have 1047*1047 matrix,  I will write down  fij[1]+ fij[2]...........fij[1047]. That maybe a hard work.
    Thank you!!!

    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: c++ cplex IloNumVarArray problem

    Posted Thu July 04, 2013 11:33 AM

    Originally posted by: Philippe_Refalo


    You need to sum up the variables in an expression using a for loop:
     
    for(IloInt r = 0; r < fij.getSize(); r++){
      IloExpr sr = IloSum(fij[r]); // sr the sum expression of variables in array fij[r]
    }
     
    If you want to create the sum of a column, you need to loop on all the elements:
     
    IloInt c = // column to sum
    IloExpr sc(env)
    for(IloInt r = 0; r < fij.getSize(); r++){
      sc += fij[r][c];
    }
     
    // Here sc is the sum of variables in column c
     
    Cheers, 
     
    Philippe

    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: c++ cplex IloNumVarArray problem

    Posted Thu July 04, 2013 09:24 PM

    Originally posted by: babyvera


    thank you for your help.thank you very much.

      for (j = 0; j < nodenum; j++)
      {
        for(v=0;v<nodenum;v++)
        {
         sr +=  fij[j*nodenum+v]; // sr the sum expression of variables in array fij[r]
         cout<<fij[j*nodenum+v]<<endl;
        }
        for(v=0;v<nodenum;v++)
        {
         sl += fij[v*nodenum+j]; // sr the sum expression of variables in array fij[c]
         cout<<fij[v*nodenum+j]<<endl;
        }

       //model.add(fij[j]+fij[1*5+j]+fij[2*5+j]+fij[3*5+j]+fij[4*5+j]-fij[j*5]-fij[j*5+1]-fij[j*5+2]-fij[j*5+3]-fij[j*5+4]+G[j]==Load[j]);
       model.add(sl-sr+G[j]==Load[j]);
      }

    but when I use model.add(fij[j]+fij[1*5+j]+fij[2*5+j]+fij[3*5+j]+fij[4*5+j]-fij[j*5]-fij[j*5+1]-fij[j*5+2]-fij[j*5+3]-fij[j*5+4]+G[j]==Load[j]);
    there has Solution;when I use model.add(sl-sr+G[j]==Load[j]); there is no Solution; 
     


    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: c++ cplex IloNumVarArray problem

    Posted Fri July 05, 2013 12:29 AM

    Originally posted by: babyvera


    I realise that

     
    for(IloInt r = 0; r < 5;r++){
      IloExpr sr += fij[r];
    }

    do not equal to 'sr= fij[1]+ fij[2]+ fij[3]+ fij[4]+ fij[5]';

    so there is no solution;How can I make it equal to each other;

    thank you!


    #ConstraintProgramming-General
    #DecisionOptimization


  • 5.  Re: c++ cplex IloNumVarArray problem

    Posted Fri July 05, 2013 01:42 AM

    Originally posted by: babyvera


    thank you Philippe,I have already solve this problem.thank you very much~


    #ConstraintProgramming-General
    #DecisionOptimization