Skip to content

Commit

Permalink
integer optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopedroso committed Jun 16, 2017
1 parent 43e00e1 commit 6de58b8
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion STRIPPED/lo_simple.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pyscipopt import Model

model = Model("Wine blending (simple version)")
model = Model("Simple linear optimization")

x1 = model.addVar(vtype="C", name="x1")
x2 = model.addVar(vtype="C", name="x2")
Expand Down
22 changes: 22 additions & 0 deletions STRIPPED/puzzle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pyscipopt import Model

model = Model("Simple linear optimization")

x = model.addVar(vtype="I", name="x")
y = model.addVar(vtype="I", name="y")
z = model.addVar(vtype="I", name="x")

model.addCons(x + y + z == 32,"Heads")
model.addCons(2*x + 4*y + 8*z == 80,"Legs")
model.setObjective(y + z, "minimize")

model.optimize()

if model.getStatus() == "optimal":
print("Optimal value:", model.getObjVal())
print("Solution:")
print(" x = ", model.getVal(x))
print(" y = ", model.getVal(y))
print(" z = ", model.getVal(z))
else:
print("Problem could not be solved to optimality")
4 changes: 2 additions & 2 deletions src/lo_simple.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
lo-wines-simple.py: Simple SCIP example of linear programming:
lo_simple.py: Simple SCIP example of linear programming:
maximize 15x + 18y + 30z
subject to 2x + y + z <= 60
Expand All @@ -11,7 +11,7 @@
"""
from pyscipopt import Model

model = Model("Wine blending (simple version)")
model = Model("Simple linear optimization")

x1 = model.addVar(vtype="C", name="x1")
x2 = model.addVar(vtype="C", name="x2")
Expand Down
32 changes: 32 additions & 0 deletions src/puzzle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
puzzle.py: Simple SCIP example of integer programming:
maximize y + z
subject to x + y + z = 32
2x + 4y + 8z = 80
x,y,z >= 0 and integer
Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2015
"""
from pyscipopt import Model

model = Model("Simple linear optimization")

x = model.addVar(vtype="I", name="x")
y = model.addVar(vtype="I", name="y")
z = model.addVar(vtype="I", name="x")

model.addCons(x + y + z == 32,"Heads")
model.addCons(2*x + 4*y + 8*z == 80,"Legs")
model.setObjective(y + z, "minimize")

model.optimize()

if model.getStatus() == "optimal":
print("Optimal value:", model.getObjVal())
print("Solution:")
print(" x = ", model.getVal(x))
print(" y = ", model.getVal(y))
print(" z = ", model.getVal(z))
else:
print("Problem could not be solved to optimality")

0 comments on commit 6de58b8

Please sign in to comment.