-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43e00e1
commit 6de58b8
Showing
4 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |