7
$\begingroup$

I am coding a MIP problem in docplex and I would like to ask for some tips.

I would like to input a binary parameter that states a compatibility relation:

I have a set of characteristics $H$ to be satisfied in a product. The product is made by a set of components $C$ and each component can have many variants $V$. For stating the compatibility between variant of component and required characteristics, I stated the following binary parameter:

  • $G_h{_{c}}_{v}=1$ if the characteristic $c$ can be accomplished by variant $v$ of component $c$, and zero otherwise

I was wandering to use a 3D numpy array to state this relation. But I if I'm not wrong, I did not find examples using 3D numpy array. Instead, I saw namedTuple, that I guess was used to state similar relation for string elements.

How can I code binary parameters in docplex keeping the index of each element, by accessing the value of each parameter and also its key ?

If someone could help me, I will be very grateful.

$\endgroup$
4
$\begingroup$

One thing I would personally do is stick to dictionaries as accessing each key is easier and faster (Its complexity is $O(1)$). If you have three collections for your keys, namely your $H$, $C$, and $V$, then, as you probably know, you can use binary_var_cube where you can see, from the documentation linked:

Creates a dictionary of binary decision variables, indexed by triplets.

Using dictionaries will help you tremendously especially in cases where you have a sparse matrix. e.g. only a handful of variants $V$ are present in each component $C$. That way, rather than having a 3D numpy array or list of list of list, you can have only those indices for your variables that exist. Of course, you can achieve that with tuple or namedTuple, but as I mentioned, accessing dictionaries is faster (you can read more about some of Python data types here)

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ thanks for your reply and explanations, I appreciated it! $\endgroup$ – campioni Oct 19 '19 at 19:13

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.