Answers for "How can I work with matrix with DOCplex?"
https://developer.ibm.com/answers/questions/247096/how-can-i-work-with-matrix-with-docplex.html
The latest answers for the question "How can I work with matrix with DOCplex?"Answer by p_couronne
https://developer.ibm.com/answers/answers/247663/view.html
I concur with Daniel's answer. DOcplex variable creation methods return Python collections (dict, lists).
The xxx_var_matrix methods return dictionaries indexed by two-element tuples as in:
<pre>
im = integet_var_matrix(2, 3, name='x')\n
x11 = m[1,1] # prints: docplex.mp.linear.Var[x_1_1]
</pre>
But DOcplex will not build numpy structures. You have to fill numpy arrays yourself, either from single variables
(as in Daniel's example) or using the lists returned by DOcplex:
<pre>
ll = mm.integer_var_list(3, 2, name="ii")
nll = np.array(ll)
nll[1] # print docplex.mp.linear.Var[ii_1]
</pre>
Numpy array multiplication will be supported in the next drop released end of January.Tue, 12 Jan 2016 09:33:05 GMTp_couronneAnswer by DanielJunglas
https://developer.ibm.com/answers/answers/247444/view.html
The following works for me (I am not a numpy expert):
var_new_pattern = numpy.matrix([[ model.integer_var(name='x[%d,%d]' % (i,j)) for i in range(0,3)] for j in range(0,4)])
items = numpy.matrix([(i + 1) for i in range(0,3)]).transpose()
product = var_new_pattern * items
print product[0,0] # Prints x[0,0]+2x[1,0]+3x[2,0]Mon, 11 Jan 2016 06:31:12 GMTDanielJunglas