PySCIPOpt
5.1.1
Python Interface for the SCIP Optimization Suite
puzzle.py
Go to the documentation of this file.
1
3
"""
4
On a beach there are octopuses, turtles and cranes.
5
The total number of legs of all animals is 80, while the number of heads is 32.
6
What are the minimum numbers of turtles and octopuses, respectively?
7
8
Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
9
"""
10
from
pyscipopt
import
Model
11
12
model = Model(
"puzzle"
)
13
x = model.addVar(vtype=
"I"
, name=
"octopusses"
)
14
y = model.addVar(vtype=
"I"
, name=
"turtles"
)
15
z = model.addVar(vtype=
"I"
, name=
"cranes"
)
16
17
# Set up constraint for number of heads
18
model.addCons(x + y + z == 32, name=
"Heads"
)
19
20
# Set up constraint for number of legs
21
model.addCons(8 * x + 4 * y + 2 * z == 80, name=
"Legs"
)
22
23
# Set objective function
24
model.setObjective(x + y,
"minimize"
)
25
26
model.hideOutput()
27
model.optimize()
28
29
# solution = model.getBestSol()
30
31
print(
"Optimal value:"
, model.getObjVal())
32
print((x.name, y.name, z.name),
" = "
, (model.getVal(x), model.getVal(y), model.getVal(z)))
examples
tutorial
puzzle.py
Generated on Fri Aug 2 2024 15:02:13 for PySCIPOpt by
1.8.17