File: furniture.py

package info (click to toggle)
python-pulp 2.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,720 kB
  • sloc: python: 7,505; makefile: 16; sh: 16
file content (32 lines) | stat: -rw-r--r-- 1,004 bytes parent folder | download | duplicates (2)
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
32
"""
 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))