4 It solves the same instance as lo_wines_simple.py:
6 maximize 15x + 18y + 30z
7 subject to 2x + y + z <= 60
11 Variables correspond to the production of three types of wine blends,
12 made from pure-grape wines.
13 Constraints correspond to the inventory of pure-grape wines.
15 Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
17 from pyscipopt
import Model, quicksum, SCIP_PARAMSETTING
20 model = Model(
"Wine blending")
21 model.setPresolve(SCIP_PARAMSETTING.OFF)
23 Inventory = {
"Alfrocheiro": 60,
"Baga": 60,
"Castelao": 30}
24 Grapes = Inventory.keys()
26 Profit = {
"Dry": 15,
"Medium": 18,
"Sweet": 30}
27 Blends = Profit.keys()
30 (
"Alfrocheiro",
"Dry"): 2,
31 (
"Alfrocheiro",
"Medium"): 1,
32 (
"Alfrocheiro",
"Sweet"): 1,
34 (
"Baga",
"Medium"): 2,
36 (
"Castelao",
"Dry"): 0,
37 (
"Castelao",
"Medium"): 0,
38 (
"Castelao",
"Sweet"): 1
44 x[j] = model.addVar(vtype=
"C", name=
"x(%s)" % j)
49 c[i] = model.addCons(
quicksum(Use[i, j] * x[j]
for j
in Blends) <= Inventory[i], name=
"Use(%s)" % i)
52 model.setObjective(
quicksum(Profit[j] * x[j]
for j
in Blends),
"maximize")
56 if model.getStatus() ==
"optimal":
57 print(
"Optimal value:", model.getObjVal())
60 print(x[j].name,
"=", model.getVal(x[j]),
" (red. cost: ", model.getVarRedcost(x[j]),
")")
63 dual = model.getDualsolLinear(c[i])
66 print(
"dual of", c[i].name,
":", dual)
68 print(
"Problem could not be solved to optimality")