4
$\begingroup$

I'm new to Cplex and I'm working with the python API. I have a variable $w^t_{iksm}$ and I could just find the binary_var_cube function which only accepts 3 indices. I'm then using this $w$ to define $X^z_{ij}$ and $Y_{im}$ which are my decision variables. My question is, how should I code this variable with more than 3 indices?

I'm sorry if this is a basic one, but if you had any useful resources for beginners, please don't hesitate to share them with me.

Thanks

$\endgroup$
1
  • $\begingroup$ I don't understand your question. It seems that you are asking 'how to define a decision variable with more than 3 indices in Cplex+python API'? I don't get what w_iksm^t and X_ij^z are in your question. $\endgroup$ Feb 2 at 1:06
2
$\begingroup$

You can create a binary decision variable as:

from docplex.mp.model import Model
m = Model(...)
my_var = m.binary_var("name_of_this_var")

The variable is just an object and does not know how many indices it has. You can then maintain your own variable dictionary. So if you have a variable defined for the indices i,k,s,m,t, you could create a dictionary that maps keys defined as tuples to their corresponding variables:

var_dict[(i,k,s,m,t)]=m.binary_var("name_of_this_var")

To create a large number of variables simultaneously, and to produce a dict or a list, consider using the factory methods binary_var_dict or binary_var_list. I recommend that you study the examples provided with docplex.

$\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.