0

I have written this code to find the sum

int sum=0;

for (i = 0u; i < n[k]; i++)
        {
            sum = sum + include[k][i];
        }

definition for include is as follows:

IloArray<IloNumVarArray> include(env, N_CONSIGNMENTS);

for (k = 0; k < N_CONSIGNMENTS; k++)
{
    include[k] = IloNumVarArray(env, n[k]);

    for (i = 0; i < n[k]; i++)
    {
        //if (i == k)continue;
        include[k][i] = IloNumVar(env, 0, 1, ILOBOOL);

    }
}

error I am getting is:

no suitable conversion function from "IloNumExprArg" to "int" esists

How to rectify this?

Prarup
  • 7
  • 3

1 Answers1

0

After you have solved your model you can ask CPLEX for the value of your IloNumVars, something like:

sum = sum + cplex.getValue(include[k][i]);

but I can't be sure that I remembered the syntax correctly. There should be plenty of examples out there.

TimChippingtonDerrick
  • 2,042
  • 1
  • 12
  • 13
  • the sum is a part of the constraints though...so can't evaluate it after the model has been solved – Prarup May 22 '21 at 16:46
  • But the sum cannot then be an int because the IloNumVars will not yet have a value until the model is solved. You will have to use something like an expression (IloNumExpr) to model the sum of those variables. – TimChippingtonDerrick May 22 '21 at 20:20