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 close merge delete

Sort by ยป oldest newest most voted

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

more

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.

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