简体   繁体   English

如何在 CPLEX(音乐会 C++)中找到这个数组的总和?

[英]How to find the sum of this array in CPLEX (concert C++)?

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?如何纠正这种情况?

After you have solved your model you can ask CPLEX for the value of your IloNumVars, something like:在您解决了 model 之后,您可以向 CPLEX 询问您的 IloNumVars 的值,例如:

sum = sum + cplex.getValue(include[k][i]); 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.应该有很多例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM