-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathILP_alloc.py
More file actions
43 lines (39 loc) · 1.38 KB
/
ILP_alloc.py
File metadata and controls
43 lines (39 loc) · 1.38 KB
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
from pulp import *
import sys
def main(argv):
if len(argv) != 3:
print("Usage: python3 " + argv[0] + " <input filename> <total num of tables>")
sys.exit(1)
input_file = argv[1]
num = int(argv[2])
table_per_stage = 2
f = open(input_file, 'r')
prob = LpProblem("Scheduling Problem", LpMinimize)
cost = LpVariable("Obj cost", lowBound=0, cat=LpInteger)
for i in range(num):
program = 'T' + str(i) + '= LpVariable(' + '\"' + 'T' + str(i) + '\"' + ', lowBound=0, cat=LpInteger)'
# print(program)
exec(program)
# Objective function
prob += cost, 'Objective function'
# Constraints
for i in range(num):
prob += cost >= locals()['T' + str(i)]
f = open(input_file, 'r')
for line in f:
if line == "\n":
continue
line = line.split('\n')[0]
src = line.split(' ')[0]
dst = line.split(' ')[1]
prob += locals()[dst] - locals()[src] >= 1
#for i in range(num):
# prob += lpSum(locals()['T' + str(j)] for j in range(num)) <= table_per_stage
# prob += abs(locals()['T' + str(i) for i in range()] - locals()['T' + str(j)]) >= 1
# print("prob =", prob)
prob.solve()
#for i in range(num):
# print("T"+str(i)+" value:", locals()['T'+str(i)].varValue)
print("cost value:", cost.varValue)
if __name__ == '__main__':
main(sys.argv)