简体   繁体   中英

CPLEX C++ get the index of variable by variable name

Is it possible in CPLEX optimizer, with c++ api, to get the index of a variable by the variable name? I couldn't find any suitable method to do that. Plz help.

I have [IloNumVarArray vars;] variable to store variables by name.

vars[i].getName(); // gives the name of the variable at index i

Is there any method like : vars.getIndex(name), which can give the index of the variable?

There isn't anything like that in CPLEX.

You can always iterate the array and compare the name to get back your variable. If you need better performance you can use a map.

If you are using the callable library C++ API, there is function for finding the column index, given a column name:

int CPXgetcolindex(CPXCENVptr env, CPXCLPptr lp, const char * lname_str, int * index_p)

See:

http://pic.dhe.ibm.com/infocenter/cosinfoc/v12r4/index.jsp?topic=%2Filog.odms.cplex.help%2Frefcallablelibrary%2Fhtml%2Ffunctions%2FCPXaddmipstarts.html

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