简体   繁体   中英

How to create an array of integers without the bounds?

I need an array for the integer variables of an optimization problem. When I use

IloNumVarArray x = CreateNumVarArray (env, 100, "x");

I have x1 to x100 but they are not integers.

Changed the code to

IloIntVarArray x = CreateIntVarArray (env, 100, "x");

and I tried to add an objective function using these variables with

IloObjective obj = IloMinimize(env, IloSum(x));
model.add(obj);

The objective function is fine, all my variables are integers too, but now i have bounds like

x1=0
x2=0
...
x100=0

Any help on how to get those integer variables in an array without the bounds?

but which status do you get for cplex? Unbounded?

Let me replicate your model in OPL:

range r=1..100;

dvar int x[r];

minimize sum(i in r) x[i];
subject to
{
  
}

execute
{
  writeln(x[1].LB);
  writeln(cplex.status);
}

which gives

-2147483647
2

The status 2 means unbounded. And you see the Lower Bound of x[1] is very low So what you did is fine and does not set any bounds

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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