3
$\begingroup$

I am new to CPLEX. I am using CPLEX with Xcode in macOS.

I have three arrays (known parameters used in optimisation) which I define as

  IloNumArray capacity(env), fixedCost(env);
  FloatMatrix cost(env);

I then assign values to this arrays as

   fixedCost=[480, 200, 320, 340, 300];
   cost=[[ 24, 74, 31, 51, 84],
    [ 57, 54, 86, 61, 68],
    [ 57, 67, 29, 91, 71],
    [ 54, 54, 65, 82, 94],
    [ 98, 81, 16, 61, 27],
    [ 13, 92, 34, 94, 87],
    [ 54, 72, 41, 12, 78],
    [ 54, 64, 65, 89, 89]];
   capacity=[ 3, 1, 2, 4, 1];

But, I am getting the following error:

    Expected variable name or 'this' in lambda capture list

How can I get rid of this?

$\endgroup$
5
$\begingroup$

According to the docs, IloNumArrays constructor signature is

public IloNumArray(const IloEnv env, IloInt n, IloNum f0, IloNum f1, ...)

which creates an array of n floating point objects for use in a model. Note that the constructor is a C-Style variadic function due to the ... parameter. Thus, you can assign your values while calling the constructor, i.e.

IloNumArray capacity(env, 5, 3, 1, 2, 4, 1);
IloNumArray fixedCost(env, 5, 480, 200, 320, 340, 300);

For the second one it's not clear what FloatMatrix should be. I assume you use the (C++11) alias

using FloatMatrix = IloArray<IloNumArray>; 
// C++98: typedef IloArray<IloNumArray> FloatMatrix; 

Then you could do it like this

FloatMatrix cost(env);

cost.add(IloNumArray(env, 5, 24, 74, 31, 51, 84));
cost.add(IloNumArray(env, 5, 57, 54, 86, 61, 68));
cost.add(IloNumArray(env, 5, 54, 54, 65, 82, 94));
cost.add(IloNumArray(env, 5, 98, 81, 16, 61, 27));
cost.add(IloNumArray(env, 5, 13, 92, 34, 94, 87));
cost.add(IloNumArray(env, 5, 54, 72, 41, 12, 78));
cost.add(IloNumArray(env, 5, 54, 64, 65, 89, 89));

To access the arrays, you simply call capacity[i] and cost[i][j].

New contributor
joni is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.