Ask Your Question

# Linear programing variable dependancy Anonymous

Solving a linear programming problem there input constrains and addition constraints my be generated during solving the problem.

I am only interested in constrains of the form x <= y.

Does sage provide a method to the all the constrains between the variables? How easy is it to represent the constrain visually?

edit retag close merge delete

## 1 Answer

Sort by » oldest newest most voted

I'm not entirely sure what you are looking for due to the vagueness of your question, but here is a response that might help.

One way to encode a linear programming problem is:

p=MixedIntegerLinearProgram()
x=p.new_variable()
p.add_constraint(-3*x+x<=2)
p.add_constraint(x<=11)
p.add_constraint(x-x<=3)
p.add_constraint(x<=6)
p.set_objective(x+2*x)


To display the objective function and constraints, use:

p.show()


To solve the LP problem, use:

p.solve()
p.get_values(x)


To display the feasible region in the 2d case, use:

p.polyhedron().show()


You can also enter the LP constraints using a matrix formulation as follows:

A=matrix([[-3,1],[0,1],[1,-1],[1,0]])
b=vector([2,11,3,6])
p=MixedIntegerLinearProgram()
x=p.new_variable()
p.set_objective(x+2*x)
p.add_constraint(A*x<=b)

more

## Comments

If the system p is 3D, can I fix one parameter to get a 2D system without start a new instance of MixedIntegerLinearProgram()?

You can add a constraint: p.add_constraint(x == 75)

## Your Answer

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

Add Answer

## Stats

Asked: 2016-05-17 13:46:41 +0200

Seen: 143 times

Last updated: May 17 '16