PySCIPOpt  5.1.1
Python Interface for the SCIP Optimization Suite
prodmix_soco.py
Go to the documentation of this file.
1 
3 """
4 Copyright (c) by Joao Pedro PEDROSO, Masahiro MURAMATSU and Mikio KUBO, 2012
5 """
6 from pyscipopt import Model, quicksum, multidict
7 
8 
9 def prodmix(I, K, a, p, epsilon, LB):
10  """prodmix: robust production planning using soco
11  Parameters:
12  I - set of materials
13  K - set of components
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.
18  """
19 
20  model = Model("robust product mix")
21 
22  x, rhs = {}, {}
23  for i in I:
24  x[i] = model.addVar(vtype="C", name="x(%s)" % i)
25  for k in K:
26  rhs[k] = model.addVar(vtype="C", name="rhs(%s)" % k)
27 
28  model.addCons(quicksum(x[i] for i in I) == 1)
29  for k in K:
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])
32 
33  model.setObjective(quicksum(p[i] * x[i] for i in I), "minimize")
34 
35  model.data = x, rhs
36  return model
37 
38 
39 def make_data():
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
45  }
46  epsilon = 0.01
47  I, p = multidict({1: 5, 2: 6, 3: 8, 4: 20})
48  K, LB = multidict({1: .2, 2: .3, 3: .2})
49  return I, K, a, p, epsilon, LB
50 
51 
52 if __name__ == "__main__":
53  I, K, a, p, epsilon, LB = make_data()
54  model = prodmix(I, K, a, p, epsilon, LB)
55  model.optimize()
56  print("Objective value:", model.getObjVal())
57  x, rhs = model.data
58  for i in I:
59  print(i, ": ", model.getVal(x[i]))
pyscipopt.expr.quicksum
def quicksum(termlist)
Definition: expr.pxi:357
prodmix_soco.prodmix
def prodmix(I, K, a, p, epsilon, LB)
Definition: prodmix_soco.py:9
pyscipopt.Multidict.multidict
def multidict(D)
Definition: Multidict.py:3
prodmix_soco.make_data
def make_data()
Definition: prodmix_soco.py:39