Hi, Im adding variables to a problem using IloNumVarArrays, i.e.

IloNumVarArray x(env);

when I use the cplex.exportModel("solver.lp") to write to file all the variables are named id### in the resulting lp file.

Is there any way I can get the x variables to be called x1,x2,x3... in the lp file?

asked 30 Sep '10, 12:17

Buxley's gravatar image

accept rate: 9%

I think it depends on which constructor definition of IloNumVar you are using, when u are defining the variable.

You can use the following to state the name explicitly.

    IloNumVar(const IloEnv env, IloNum lb=0, IloNum ub=IloInfinity, IloNumVar::Type type=Float, const char * name=0)


If you are using cplex.numVar method, you can use the definition like in the following example,

    IloNumVar x = cplex.numVar(lb, ub, IloNumVarType.Float, "xname");

answered 30 Sep '10, 15:21

Venky's gravatar image

accept rate: 15%

Thanks, this has been bugging me for months...

(01 Oct '10, 07:12) Buxley

Is there a way to name them using a for loop and the setname method?

(01 Oct '10, 15:15) Berk Ustun

Yes you can.

Check the below link, [in the purpose column, check for "Changes name of a variable or constraint"] http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/index.jsp?topic=/ilog.odms.cplex.help/Content/Optimization/Documentation/CPLEX/_pubskel/CPLEX1093.html

(01 Oct '10, 18:43) Venky

Just if somebody else wants to name them using a for loop, here is one example!

IloBoolVarArray x(env);
IloNumVarArray s(env);

    int i;
        char VarName[24];

      for(i= 0; i <n; i++){
                     sprintf_s( VarName, "x_%d",i);
                     sprintf_s( VarName, "s_%d",i);

These are the examples for boolean variables and integer variables.


answered 04 Oct '10, 05:01

Buxley's gravatar image

accept rate: 9%

edited 04 Oct '10, 10:00

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 30 Sep '10, 12:17

Seen: 10,358 times

Last updated: 10 Aug '11, 14:45

OR-Exchange! Your site for questions, answers, and announcements about operations research.