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

IloNumVarArray x(env);
x.add(IloNumVar);

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

Buxley
5641414
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)

or

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");
link

answered 30 Sep '10, 15:21

Venky's gravatar image

Venky
7681219
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
1

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);
                     x.add(IloBoolVar(env,VarName));
                     sprintf_s( VarName, "s_%d",i);
                     s.add(IloIntVar(env,0,IloIntMax,VarName));
}

These are the examples for boolean variables and integer variables.

link

answered 04 Oct '10, 05:01

Buxley's gravatar image

Buxley
5641414
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

By RSS:

Answers

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

Tags:

×191

Asked: 30 Sep '10, 12:17

Seen: 10,154 times

Last updated: 10 Aug '11, 14:45

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