File: SpongeRollProblem5.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 (44 lines) | stat: -rw-r--r-- 1,139 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
33
34
35
36
37
38
39
40
41
42
43
44
"""
The Sponge Roll Problem with Column Generation for the PuLP Modeller

Authors: Antony Phillips,  Dr Stuart Mitchell  2008
"""

# Import Column Generation functions
from .CG import *

# The roll data is created
rollData = {  # Length Demand SalePrice
    "5": [150, 0.25],
    "7": [200, 0.33],
    "9": [300, 0.40],
}

# The boolean variable morePatterns is set to True to test for more patterns
morePatterns = True

# A list of starting patterns is created
patternslist = [[4, 0, 0], [0, 2, 0], [0, 0, 2]]

# The starting patterns are instantiated with the Pattern class
Patterns = []
for i in patternslist:
    Patterns += [Pattern("P" + str(len(Patterns)), i)]

# This loop will be repeated until morePatterns is set to False
while morePatterns == True:

    # Solve the problem as a Relaxed LP
    duals = masterSolve(Patterns, rollData)

    # Find another pattern
    Patterns, morePatterns = subSolve(Patterns, duals)

# Re-solve as an Integer Problem
solution, varsdict = masterSolve(Patterns, rollData, relax=False)

# Display Solution
for i, j in list(varsdict.items()):
    print(i, "=", j)

print("objective = ", solution)