GowriHari commited on
Commit
b3c4b99
·
1 Parent(s): 3a5998c

Delete MIP.py

Browse files
Files changed (1) hide show
  1. MIP.py +0 -133
MIP.py DELETED
@@ -1,133 +0,0 @@
1
- # importing required modules
2
- import pandas as pd
3
- import numpy as np
4
- import matplotlib.pyplot as plt
5
- import pandas as pd
6
- import chart_studio.plotly as py
7
- import plotly.figure_factory as ff
8
- import datetime
9
- from datetime import timedelta
10
- import time
11
- import copy
12
-
13
- #importing PuLP solver
14
- import pulp
15
- from itertools import product
16
-
17
- def gantt_for_MIP(df,method):
18
- title_chart = 'Job shop Schedule - using '+ method
19
- fig = ff.create_gantt(df, index_col='Resource', show_colorbar=True, group_tasks=True, showgrid_x=True, title=title_chart)
20
- return fig
21
-
22
-
23
- def MIP_fn(input_file):
24
- xls = pd.ExcelFile(input_file)
25
- df1 = pd.read_excel(xls, 'Machines Sequence',index_col = 0)
26
- df2 = pd.read_excel(xls, 'Processing Time',index_col = 0)
27
-
28
- times =[]
29
- machines = []
30
-
31
-
32
- for ind in df1.index:
33
- list_m = []
34
- list_t = []
35
- for col in df1:
36
- list_m.append(df1[col][ind]-1) # for MIP formulation
37
- list_t.append(df2[col][ind])
38
- times.append(list_t)
39
- machines.append(list_m)
40
-
41
-
42
- pt = df2.values
43
- mo = df1.values-1 # for the numbering the machines from 0 to 9
44
-
45
- m=n=len(pt[0])
46
- print("The number of machines and jobs in the given input data is - ",m)
47
-
48
- #Max time possible for all the jobs - summation of all the process time
49
- M = sum(times[i][j] for i in range(n) for j in range(m))
50
-
51
- model = pulp.LpProblem("MIN_makespan", pulp.LpMinimize)
52
-
53
- dv = pulp.LpVariable.dicts("start_time",
54
- ((i, j) for i in range(m) for j in range(n)),
55
- lowBound=0,
56
- cat='Continuous')
57
- #print(dv)
58
- b = pulp.LpVariable.dicts("binary_var",
59
- ((j, k, i) for i in range(m) for k in range(n) for j in range(n)),
60
- lowBound=0,
61
- cat='Binary')
62
- # print(b)
63
- Cmax = pulp.LpVariable('Cmax',lowBound = 0, cat='Continuous')
64
-
65
-
66
- # (1) operation sequence inside a job
67
- model += Cmax
68
- for j in range(m):
69
- for i in range(n-1):
70
- I = mo[j,i]
71
- K = mo[j,i+1]
72
- J = j
73
-
74
- model += (dv[J,K] - dv[J,I]) >= pt[J][list(mo[J]).index(I)]
75
- # print((dv[J,K] - dv[J,I]) >= pt[J][list(mo[J]).index(I)])
76
-
77
- # (2) the max start time
78
- for j in range(m):
79
- for i in range(n):
80
-
81
- I = mo[j,i]
82
- J = j
83
- model += (Cmax - dv[J,I]) >= pt[J][list(mo[J]).index(I)]
84
- #print((Cmax - dv[J,I]) >= pt[J][list(mo[J]).index(I)])
85
-
86
- # (3) no overlap for operations assigned to same machine
87
- for (j, k) in product(range(n), range(n)):
88
- if k != j:
89
- for i in range(m):
90
- model += dv[j,i] - dv[k,i] + M*b[j,k,i] >= pt[k][list(mo[k]).index(i)]
91
- model += -dv[j,i] + dv[k,i] - M*b[j,k,i] >= pt[j][list(mo[j]).index(i)] - M
92
-
93
- start_time = time.time()
94
- model.solve(pulp.PULP_CBC_CMD(timeLimit=200))
95
- print("Solution status : ",pulp.LpStatus[model.status])
96
-
97
- # for var in dv:
98
- # var_value = dv[var].varValue
99
- # print( var[0],'-',var[1] ,var_value)
100
-
101
- tota_time = pulp.value(model.objective)
102
- print ('Optimal time:',tota_time)
103
- print('Solver processing time:%s'% (time.time() - start_time))
104
- op = "Optimal Schedule Length :"+ str(tota_time)
105
-
106
- m_keys=[j for j in range(m)]
107
- j_keys=[j for j in range(n)]
108
- key_count={key:0 for key in j_keys}
109
- j_count={key:0 for key in j_keys}
110
- m_count={key:0 for key in m_keys}
111
- j_record={}
112
-
113
- for var in dv:
114
- var_value = dv[var].varValue
115
-
116
- start_time=str(datetime.timedelta(seconds=var_value)) # convert seconds to hours, minutes and seconds
117
- end_time=str(datetime.timedelta(seconds=var_value+pt[var[1]][list(mo[var[1]]).index(var[0])]))
118
-
119
- j_record[(var[1],var[0])]=[start_time,end_time]
120
-
121
- key_count[i]=key_count[i]+1
122
-
123
-
124
- df=[]
125
- for m in m_keys:
126
- for j in j_keys:
127
- df.append(dict(Task='Machine %s'%(m), Start='2020-02-01 %s'%(str(j_record[(j,m)][0])), Finish='2020-02-01 %s'%(str(j_record[(j,m)][1])),Resource='Job %s'%(j)))
128
-
129
- method = 'PuLP - CBC Solver'
130
- df_data = pd.DataFrame(df)
131
-
132
- return op,gantt_for_MIP(df,method),df_data
133
-