-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeLp.py
69 lines (68 loc) · 1.93 KB
/
writeLp.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def writeLp (FOOD, C, filename):
wr=open(filename, 'w')
#write objective function
wr.write('MINIMIZE\n')
wr.write('Objective: ')
for i in range(0,len(FOOD)):
if i>0:
wr.write('+')
wr.write(str(FOOD[i].R))
wr.write('x'+str(i+1))
#write constraints
wr.write('\nSubject To:\n')
#write the Subject_D
wr.write('C1: ')
for i in range(0,len(FOOD)):
if i>0:
wr.write('+')
wr.write(str(FOOD[i].D))
wr.write('x'+str(i+1))
wr.write('>=' + str(45) + '\n')
#write the Subject_S
wr.write('C2: ')
for i in range(0,len(FOOD)):
if i>0:
wr.write('+')
wr.write(str(FOOD[i].S))
wr.write('x'+str(i+1))
wr.write('>=' + str(30) + '\n')
#write the Subject_W
wr.write('C3: ')
for i in range(0,len(FOOD)):
if i>0:
wr.write('+')
wr.write(str(FOOD[i].W))
wr.write('x'+str(i+1))
wr.write('>=' + str(1000) + '\n')
#write the Subject_N
wr.write('C4: ')
for i in range(0,len(FOOD)):
if i>0:
wr.write('+')
wr.write(str(FOOD[i].N))
wr.write('x'+str(i+1))
wr.write('>=' + str(2500) + '\n')
#write the Subject_G
wr.write('C5: ')
for i in range(0,len(FOOD)):
if i>0:
wr.write('+')
wr.write(str(FOOD[i].G))
wr.write('x'+str(i+1))
wr.write('>=' + str(1000) + '\n')
#write the Subject_R
wr.write('C6: ')
for i in range(0,len(FOOD)):
if i>0:
wr.write('+')
wr.write(str(FOOD[i].R))
wr.write('x'+str(i+1))
wr.write('>=' + str(C) + '\n')
#write variables
wr.write('GENERAL\n')
for i in range(0,len(FOOD)):
wr.write(' x'+str(i+1)+' ')
if (i+1)>=20 and ((i+1)%20)==0:
wr.write('\n')
wr.write('\nEND\n')
wr.close()