File: furniture.py

package info (click to toggle)
python-pulp 1.6.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,596 kB
  • sloc: python: 6,006; sh: 12; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
 The Furniture problem from EngSci391 for the PuLP Modeller
 Author: Dr Stuart Mitchell    2007
"""
from pulp import *
Chairs = ["A","B"]
costs = {"A":100,
         "B":150}
Resources = ["Lathe","Polisher"]
capacity = {"Lathe"    : 40,
              "Polisher" : 48}
activity = [  #Chairs
              #A  B
              [1, 2],  #Lathe
              [3, 1.5] #Polisher
              ]
activity = makeDict([Resources,Chairs],activity)
prob = LpProblem("Furniture Manufacturing Problem", LpMaximize)
vars = LpVariable.dicts("Number of Chairs",Chairs, lowBound = 0)
#objective
prob += lpSum([costs[c]*vars[c] for c in Chairs])
for r in Resources:
    prob += lpSum([activity[r][c]*vars[c] for c in Chairs]) <= capacity[r], \
     "capacity_of_%s"%r 
prob.writeLP("furniture.lp")
prob.solve()
# Each of the variables is printed with it's value
for v in prob.variables():
    print(v.name, "=", v.varValue)
# The optimised objective function value is printed to the screen    
print("Total Revenue from Production = ", value(prob.objective))