First time here? Check out the FAQ!

Ask Your Question
0

add matrix as a contraint

asked 9 years ago

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 9 years ago

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)
Preview: (hide)
link

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 ( 9 years ago )

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: 9 years ago

Seen: 416 times

Last updated: Jul 08 '15