PySCIPOpt  5.1.1
Python Interface for the SCIP Optimization Suite
eoq_en.py
Go to the documentation of this file.
1 
3 """
4 Approach: use a convex combination formulation.
5 
6 Copyright (c) by Joao Pedro PEDROSO and Mikio KUBO, 2012
7 """
8 from pyscipopt import Model, quicksum, multidict
9 
10 
11 def eoq(I, F, h, d, w, W, a0, aK, K):
12  """eoq -- multi-item capacitated economic ordering quantity model
13  Parameters:
14  - I: set of items
15  - F[i]: ordering cost for item i
16  - h[i]: holding cost for item i
17  - d[i]: demand for item i
18  - w[i]: unit weight for item i
19  - W: capacity (limit on order quantity)
20  - a0: lower bound on the cycle time (x axis)
21  - aK: upper bound on the cycle time (x axis)
22  - K: number of linear pieces to use in the approximation
23  Returns a model, ready to be solved.
24  """
25 
26  # construct points for piecewise-linear relation, store in a,b
27  a, b = {}, {}
28  delta = float(aK - a0) / K
29  for i in I:
30  for k in range(K):
31  T = a0 + delta * k
32  a[i, k] = T # abscissa: cycle time
33  b[i, k] = F[i] / T + h[i] * d[i] * T / 2. # ordinate: (convex) cost for this cycle time
34 
35  model = Model("multi-item, capacitated EOQ")
36 
37  x, c, w_ = {}, {}, {}
38  for i in I:
39  x[i] = model.addVar(vtype="C", name="x(%s)" % i) # cycle time for item i
40  c[i] = model.addVar(vtype="C", name="c(%s)" % i) # total cost for item i
41  for k in range(K):
42  w_[i, k] = model.addVar(ub=1, vtype="C", name="w(%s,%s)" % (i, k)) # todo ??
43 
44  for i in I:
45  model.addCons(quicksum(w_[i, k] for k in range(K)) == 1)
46  model.addCons(quicksum(a[i, k] * w_[i, k] for k in range(K)) == x[i])
47  model.addCons(quicksum(b[i, k] * w_[i, k] for k in range(K)) == c[i])
48 
49  model.addCons(quicksum(w[i] * d[i] * x[i] for i in I) <= W)
50 
51  model.setObjective(quicksum(c[i] for i in I), "minimize")
52 
53  model.data = x, w
54  return model
55 
56 
57 if __name__ == "__main__":
58  # multiple item EOQ
59  I, F, h, d, w = multidict(
60  {1: [300, 10, 10, 20],
61  2: [300, 10, 30, 40],
62  3: [300, 10, 50, 10]}
63  )
64  W = 2000
65  K = 1000
66  a0, aK = 0.1, 10
67  model = eoq(I, F, h, d, w, W, a0, aK, K)
68  model.optimize()
69 
70  x, w = model.data
71  EPS = 1.e-6
72  for v in x:
73  if model.getVal(x[v]) >= EPS:
74  print(x[v].name, "=", model.getVal(x[v]))
75 
76  print("Optimal value:", model.getObjVal())
pyscipopt.expr.quicksum
def quicksum(termlist)
Definition: expr.pxi:357
pyscipopt.Multidict.multidict
def multidict(D)
Definition: Multidict.py:3
eoq_en.eoq
def eoq(I, F, h, d, w, W, a0, aK, K)
Definition: eoq_en.py:11