-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput Code for Bosch_MP.py
72 lines (68 loc) · 1.63 KB
/
Input Code for Bosch_MP.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
70
71
72
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 14 14:40:02 2019
@author: Karnika
"""
import os
import xlrd
import xlsxwriter
Places=[]
book = xlrd.open_workbook(os.path.join("a.xlsx"))
sh = book.sheet_by_name("Sheet1")
i = 0
while True:
try:
sp = sh.cell_value(i,0)
Places.append(sp)
i = i + 1
except IndexError:
break
UP=list(set(Places))
Uni={}
for i in Places:
if i not in Uni:
Uni[i]=1
else:
Uni[i]=Uni[i]+1
distance_matrix={}
time_matrix={}
for i in range(len(UP)):
for j in range(len(UP)):
if i==j:
distance_matrix[UP[i],UP[j]]=0
time_matrix[UP[i],UP[j]]=0
elif i>j :
distance_matrix[UP[i],UP[j]]=10
time_matrix[UP[i],UP[j]]=10
distance_matrix[UP[j],UP[i]]=distance_matrix[UP[i],UP[j]]
time_matrix[UP[j],UP[i]]=time_matrix[UP[i],UP[j]]
workbook=xlsxwriter.Workbook('Input Data.xlsx')
worksheet=workbook.add_worksheet('distance')
P=1
for i in UP:
Q=1
for j in UP:
a=distance_matrix[i,j]
worksheet.write(P,Q,a)
worksheet.write(0,Q,UP[Q-1])
Q=Q+1
worksheet.write(P,0,UP[P-1])
P=P+1
worksheet=workbook.add_worksheet('time')
P=1
for i in UP:
Q=1
for j in UP:
a=time_matrix[i,j]
worksheet.write(P,Q,a)
worksheet.write(0,Q,UP[Q-1])
Q=Q+1
worksheet.write(P,0,UP[P-1])
P=P+1
worksheet=workbook.add_worksheet('demand')
P=1
for i in Uni:
worksheet.write(P,0,i)
worksheet.write(P,1,Uni[i])
P=P+1
workbook.close()