Ask Your Question
0

add matrix as a contraint

asked 2015-07-08 10:41:30 +0200

sujata gravatar image

Is there anyway where we can add a constraint as a matrix. For example I have my matrix C=matrix(5,6) I want to add a constraint p.add_constraint(C[i,j]>=1) If I do this sagemath I get value error.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2015-07-08 13:46:09 +0200

Nathann gravatar image

What about this?

sage: m = Matrix([[1,2,3],[4,5,6],[7,8,9]])
sage: p = MixedIntegerLinearProgram()
sage: x = p.new_variable(real=True, nonnegative=True)
sage: p.add_constraint(m*x <= 1)
sage: p.show()
Maximization:

Constraints:
  x_0 + 2.0 x_1 + 3.0 x_2 <= 1.0
  4.0 x_0 + 5.0 x_1 + 6.0 x_2 <= 1.0
  7.0 x_0 + 8.0 x_1 + 9.0 x_2 <= 1.0
Variables:
  x_0 is a continuous variable (min=0.0, max=+oo)
  x_1 is a continuous variable (min=0.0, max=+oo)
  x_2 is a continuous variable (min=0.0, max=+oo)
edit flag offensive delete link more

Comments

Thanks for the response, But what I am facing now is as below, C=Matrix(6,5) for i in range(0,6): for j in range(0,5): p.add_constraint(1>=C[i,j]>=0)

But it gives error , raise ValueError('argument must be a linear function or constraint, got '+str(linear_function)) ValueError: argument must be a linear function or constraint, got True

Any idea how to do this.

sujata gravatar imagesujata ( 2015-07-08 20:25:41 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-07-08 10:41:30 +0200

Seen: 323 times

Last updated: Jul 08 '15