# Not able to figure out ' invalid matrix input type -- ', u'1' in CPLEX

 0 Hello Everyone, I am currently working on Cplex using Python API. I have a problem when I rune the code. I keep getting this error about the invalid matrix input but I'm not able to figure out what it is. I would be grateful if any of you could help. My function is as below def add_constraint(self, variables, coefficients, sense, rhs, name): self.prob.linear_constraints.add( lin_expr = [[ variables, coefficients ]], senses = [sense], rhs = [rhs], names = [name] )  This is the traceback Traceback (most recent call last): File "RW10.py", line 569, in main(sys.argv[1:]) File "RW10.py", line 562, in main solveVNEProblem( phy_network, demands, args.output) File "RW10.py", line 116, in solveVNEProblem solver.add_constraint( varNames, varCoeffs, "E", 1.0, "Location_Constraints1{}".format( demand.demandID ) ) File "RW10.py", line 26, in add_constraint names = [name] ) File "/opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/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 "/opt/ibm/ILOG/CPLEX_Studio125/cplex/python/x86-64_sles10_4.1/cplex/_internal/_matrices.py", line 74, in __init__ raise TypeError(" invalid matrix input type -- ", self._mat[0]) TypeError: (' invalid matrix input type -- ', u'1')  Thanks a lot Varun asked 28 May '14, 08:39 crypto 67●2●7 accept rate: 0% 2 For the sake of others' time, please let them know that you've cross-posted your question in other forums (here, here, and here). (28 May '14, 09:23) Ehsan ♦ I was seriously not aware that I'm supposed to do it. Sorry. But I posted this question only over here and in IBM ILog and not in the permalink and marshut (28 May '14, 09:31) crypto No problem at all. Just keep this unofficial rule in mind for the next time. (28 May '14, 12:08) Ehsan ♦

 1 Without having the actual code at hand ...a bit of guesswork here: u'1' probably is supposed to be 1.0 (i. e., self._mat contains unicode representations of the coefficients of your model's variables), so: casting might help, e.g. self.prob.linear_constraints.add( lin_expr = [[ variables, [float(c) for c in coefficients], ... ). answered 28 May '14, 12:21 fbahr ♦ 4.6k●7●16 accept rate: 13% I'm sorry that I asked such a lame question. I kind of figured it out later that I should have asked something better. Thanks a lot @fbahr (30 May '14, 05:02) crypto
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags:

×191
×16
×3