Originally posted by: gioker
The documentation for the python interface to Cplex states:
>>>
import cplex
>>> c = cplex.Cplex()
>>> c.variables.add(names = [
"x1",
"x2",
"x3"])
>>> c.linear_constraints.add(lin_expr = [cplex.SparsePair(ind = [
"x1",
"x3"], val = [1.0, -1.0]),
cplex.SparsePair(ind = ["x1", "x2"], val = [1.0, 1.0]),
cplex.SparsePair(ind = ["x1", "x2", "x3"], val = [-1.0] * 3),
cplex.SparsePair(ind = ["x2", "x3"], val = [10.0, -2.0])],
senses = ["E", "L", "G", "R"],
rhs = [0.0, 1.0, -1.0, 2.0],
range_values = [0.0, 0.0, 0.0, -10.0],
names = ["c0", "c1", "c2", "c3"],)
>>> c.linear_constraints.get_rhs()
[0.0, 1.0, -1.0, 2.0]
but it returns the following error:
File "findsol.py", line 98, in <module>
findsol(n_sol)
File "findsol.py", line 50, in findsol
names = ["c0", "c1", "c2", "c3"],)
File "/Library/Python/2.7/site-packages/cplex/_internal/_subinterfaces.py", line 1187, in add
rmat = _C_HBMatrix(lin_expr, self._cplex._env_lp_ptr, 0, self._env.parameters.read.apiencoding.get())
File "/Library/Python/2.7/site-packages/cplex/_internal/_matrices.py", line 74, in __init__
raise TypeError(" invalid matrix input type -- ", self._mat[0])
TypeError: (' invalid matrix input type -- ', u'x1')
I have a Mac with the latest releases of both Python and Cplex.
Thanks.
#CPLEXOptimizers#DecisionOptimization