Ask Your Question
1

Linear programing variable dependancy

asked 2016-05-17 13:46:41 +0100

anonymous user

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

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-05-17 15:35:48 +0100

calc314 gravatar image

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[0]+x[1]<=2)
p.add_constraint(x[1]<=11)
p.add_constraint(x[0]-x[1]<=3)
p.add_constraint(x[0]<=6)
p.set_objective(x[0]+2*x[1])

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[0]+2*x[1])
p.add_constraint(A*x<=b)
edit flag offensive delete link 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()?

Johan gravatar imageJohan ( 2016-05-18 08:14:40 +0100 )edit

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

calc314 gravatar imagecalc314 ( 2016-05-18 22:13:36 +0100 )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

1 follower

Stats

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

Seen: 307 times

Last updated: May 17 '16