Answers for "How to formulate decision variables and constraints in matrix form in cplex?"
https://developer.ibm.com/answers/questions/514564/how-to-formulate-decision-variables-and-constraint.html
The latest answers for the question "How to formulate decision variables and constraints in matrix form in cplex?"Answer by DanielJunglas
https://developer.ibm.com/answers/answers/515118/view.html
Since you tagged the question "docplex" I assume you are using docplex and not the Python CPLEX API (which is more low level). In order to create a matrix of decision variables you can use functions `Model.binary_var_matrix()`, `Model.continous_var_matrix()`, or `Model.integer_var_matrix()`. These are all documented and you can look them up in the reference documentation (or via "info(Model)" in a Python shell).
For example
x = mdl.integer_var_dict(range(3), range(4))
will create a 3 by 4 matrix of integer decision variables. Constraints are added with the `add_constraint` function (check the reference documentation). Here is a small example that creates the variables and the constraint you listed:
with Model() as mdl:
rows = range(3)
cols = range(4)
da = mdl.integer_var_matrix(rows, cols)
dc = mdl.integer_var_matrix(rows, cols)
d = 1.0
for i in rows:
for j in cols:
mdl.add_constraint(da[i,j] + dc[i,j] == d)
Alternatively, the constraints can be added with a single line:
mdl.add_constraints(da[i,j] + dc[i,j] == d for i in rows for j in cols)Mon, 19 Aug 2019 08:02:57 GMTDanielJunglas