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 <module>
    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's gravatar image

crypto
6727
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 ♦

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], ... ).

link

answered 28 May '14, 12:21

fbahr's gravatar image

fbahr ♦
4.6k716
accept rate: 13%

edited 30 May '14, 06:03

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
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • 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

Asked: 28 May '14, 08:39

Seen: 3,994 times

Last updated: 30 May '14, 18:51

OR-Exchange! Your site for questions, answers, and announcements about operations research.