Cplex c++ multidimensional decision variable

后端 未结 2 999
感动是毒
感动是毒 2021-01-22 12:49

I\'m new using cplex and I try to find some information on internet but didn\'t find clear stuff to help me in my problem.

I have P[k] k will be equal to 1 to 4

2条回答
  •  旧时难觅i
    2021-01-22 13:42

    You probably want to use an IloNumExpr

    for(int k = 0; k < 4; k++){
       IloNumExpr sum_over_i(env);
       for(int i = 0; i < 5; i++){
            sum_over_i += x[i][k];
       }
       model.add(sum_over_i >= 2 * p[k]; );
    }
    

    You also need to declare x as a 2-dimensional array.

    IloArray x(env, 4);
    for (int k = 0; k < 4; ++k)
          x[k] = IloIntVarArray(env, 5, 0, 1);
    

    Also, in c++, array indices are from 0 to size-1, not 1 to size. Your objective should be written

    model.add(IloMaximize(env, 1000 * p[0] + 2000 * p[1] + 500 * p[2] + 1500 * p[3]));
    

提交回复
热议问题