-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate.py
219 lines (207 loc) · 7.68 KB
/
calculate.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#This is the process calculate final route and activities for dating
import numpy as np
import random
from tkinter import *
from get_map import get_distance
from PIL import Image, ImageTk
import re
from get_map import get_transport
from threading import Thread
import time
def get_handwork_name(temp_number1):
f = open("handwork.txt")
for i in range(temp_number1):
str = f.readline()
p = r'[\u4e00-\u9fa5]+\w+|[\u4e00-\u9fa5]+\s'
pattern = re.compile(p)
find = pattern.findall(str)
#print(find[1])
return find[1]
def get_room(temp_number1):
f = open("address_array.txt")
for i in range(temp_number1):
str = f.readline()
p = r'[\u4e00-\u9fa5]+\w+|[\u4e00-\u9fa5]+|\w+[\u4e00-\u9fa5]+\s'
pattern = re.compile(p)
find = pattern.findall(str)
#print(find[0])
return find[0]
#Build a new thread to show two parellel images
class MyThread(Thread):
def __init__(self, name,root,movie_name,route_new):
super().__init__()
self.name = name
print("in show_movie")
self.movie_name = movie_name
self.route_new = route_new
self.root = root
self.frame = Frame(root)
self.frame.pack()
def run(self):
img = Image.open('5.jpg') # 打开图片
photo = ImageTk.PhotoImage(img)
print("finish photo")
x = 0
width = 600
dx = 10
self.canvas = Canvas(self.root,width=900,height=600,bg="pink")
self.canvas.pack()
self.canvas.create_text(x, 700, text="点击你想的电影,和你的TA",font=("楷体",20),tag="text")
self.canvas.create_image(100,100,anchor=NW,image=photo)
first_time = time.time()
while True:
self.canvas.after(100)
if time.time()-first_time>5:
break;
self.canvas.move("text",dx,0)
self.canvas.update()
if x<width:
x += dx
else:
x=0
self.canvas.delete("text")
self.canvas.create_text(x,700,"点击你想的电影,和你的TA",font=("楷体",20),tag="text")
print("finish show")
BButton = []
for i in range(10):
BButton.append(" ")
BButton[i] = Button(self.frame,text=str(self.movie_name[i]),command=lambda:self.play)
#print(i)
BButton[i].pack()
Button11 = Button(self.frame,text="确定",command=self.change)
Button11.pack()
#mainloop()
def change(self,):
print("in change")
self.frame.destroy()
self.canvas.pack_forget()
face(self.root,self.route_new)
def play(self,):
print("in self")
return
class face():
def __init__(self,master,route_new):
print("in face")
self.master = master
self.route_new = route_new
frame = Frame(self.master)
frame.pack()
img = Image.open('6.jpg') # 打开图片
photo = ImageTk.PhotoImage(img)
theLable = Label(frame,text=self.route_new,justify=LEFT,image=photo,compound=CENTER,font=("楷体",23),fg="blue")
theLable.pack()
mainloop()
#This class use floyd algorithm to calculate shortest path
class floyd():
def __init__(self,adjust_matrix,order,raw,price_raw,root,movie,movie_we):
self.adjust_matrix = adjust_matrix
self.order = order
self.raw = raw
self.price_raw = price_raw
self.master = root
self.movie =movie
self.movie_we = movie_we
self.ffloyd()
def ffloyd(self,):
movie_name = self.movie_we
print("开始寻找最短路径")
d = np.array(self.adjust_matrix)
inf = int(1e9)
n = len(self.adjust_matrix)
for i in range(0, n):
for j in range(0,n):
d[i][j] = inf if d[i][j] == 0 else d[i][j]
for i in range(0,n): d[i][i] = 0
for k in range(0,n):
for i in range(0,n):
for j in range(0,n):
d[i][j] = min(d[i][j],d[i][k]+d[k][j])
size = len(self.order)
route = []
name = []
price = []
addr = []
#price分别在"Temp_Dazhong.txt" "movie.txt" "free" "handwork.txt" "address_array.txt"
for i in range(size-1):
temp_number1 = int(random.uniform(1,9))
temp_number2 = int(random.uniform(1,9))
first = int(self.order[i])*10 + temp_number1
second = int(self.order[i+1])*10 + temp_number2
try:
addr.append(self.raw[first])
if int(self.order[i])==3:
distance = get_distance(self.raw[first],self.raw[second])
name = get_handwork_name(temp_number1)
route.append(name)
price.append(price_self.raw[first])
else :
if int(self.order[i]==4):
distance = get_distance(self.raw[first],self.raw[second])
name = get_room(temp_number1)
route.append(name)
price.append(self.price_raw[first])
else:
distance = get_distance(self.raw[first],self.raw[second])
route.append(self.raw[first])
price.append(self.price_raw[first])
except:
addr.append(self.raw[first+1])
if int(self.order[i])==3:
name = get_handwork_name(temp_number1+1)
route.append(name)
price.append(self.price_raw[first+1])
else:
if int(self.order[i])==4:
name = get_rom(temp_number1+1)
route.append(name)
price.append(self.price_raw[first+1])
else:
route.append(self.raw[first+1])
price.append(self.price_raw[first+1])
addr.append(self.raw[second])
if int(self.order[i+1])==3:
name = get_handwork_name(temp_number2)
route.append(name)
price.append(self.price_raw[second])
elif int(self.order[i+1])==4:
name = get_room(temp_number2)
route.append(name)
price.append(self.price_raw[second])
else:
route.append(self.raw[second])
price.append(self.price_raw[second])
print("打印找到的约会路线")
print(route)
route_new = ""
for i in range(len(route)):
if(i!=0):
route_new = route_new +"->"+ str(route[i])
else:
route_new = route_new + str(route[i])
print("打印各项目花费")
print(price)
for i in range(len(route)-1):
print(route[i],route[i+1])
try:
get_transport(addr[i],addr[i+1])
except:
get_transport(addr[i],addr[i+1])
flag = False
for i in range(len(self.order)):
if int(self.order[i]==1):
flag = True
if flag==True:
t = MyThread('show_result',self.master,movie_name,route_new)
print(route_new)
print("进程创建完毕")
t.start()
#time.sleep(5)
else:
#self.route_new = route_new
frame = Frame(self.master)
frame.pack()
img = Image.open('/Users/macbook/Desktop/6.jpg') # 打开图片
photo = ImageTk.PhotoImage(img)
theLable = Label(frame,text=self.route_new,justify=LEFT,image=photo,compound=CENTER,font=("楷体",23),fg="pink")
theLable.pack()
mainloop()