4 Copyright (c) by Joao Pedro PEDROSO, Masahiro MURAMATSU and Mikio KUBO, 2012
6 from pyscipopt
import Model, quicksum, multidict
10 """prodmix: robust production planning using soco
14 a[i][k] - coef. matrix
15 p[i] - price of material i
16 LB[k] - amount needed for k
17 Returns a model, ready to be solved.
20 model = Model(
"robust product mix")
24 x[i] = model.addVar(vtype=
"C", name=
"x(%s)" % i)
26 rhs[k] = model.addVar(vtype=
"C", name=
"rhs(%s)" % k)
28 model.addCons(
quicksum(x[i]
for i
in I) == 1)
30 model.addCons(rhs[k] == -LB[k] +
quicksum(a[i, k] * x[i]
for i
in I))
31 model.addCons(
quicksum(epsilon * epsilon * x[i] * x[i]
for i
in I) <= rhs[k] * rhs[k])
33 model.setObjective(
quicksum(p[i] * x[i]
for i
in I),
"minimize")
40 """creates example data set"""
41 a = {(1, 1): .25, (1, 2): .15, (1, 3): .2,
42 (2, 1): .3, (2, 2): .3, (2, 3): .1,
43 (3, 1): .15, (3, 2): .65, (3, 3): .05,
44 (4, 1): .1, (4, 2): .05, (4, 3): .8
47 I, p =
multidict({1: 5, 2: 6, 3: 8, 4: 20})
49 return I, K, a, p, epsilon, LB
52 if __name__ ==
"__main__":
56 print(
"Objective value:", model.getObjVal())
59 print(i,
": ", model.getVal(x[i]))