-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (50 loc) · 1.41 KB
/
main.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
import mysql.connector
import numpy as np
time_range = 30
def build_graph(trip, current_trips):
vertices = []
for st in current_trips:
if st[1] == trip[1]:
vertices.append(st)
l = len(vertices)
edges = np.zeros([l, l + 1])
for i in range(l):
for j in range(l):
if i != j:
edges[i, j] = googleAPI.getDistance(vertices[i][0], vertices[j][0])
edges[i, l] = googleAPI.getDistance(vertices[i][0], vertices[i][1])
return {
'v' : vertices,
'e' : edges
}
cnx = mysql.connector.connect(user='user', password="password", database='database')
cursor = cnx.cursor()
query = "SELECT capacity, location FROM cars "
cursor.execute(query)
locations = []
capacities = []
cars = []
for (capacity, location) in cursor:
locations.append(location)
capacities.append(capacity)
for i in range(16):
cars.append(locations)
query = "SELECT start, end, appt FROM trips"
cursor.execute(query)
trips = []
for (start, end, appt) in cursor:
trips.append([start, end, appt])
timelist = []
# make timelist
current_trips = []
for t in timelist:
current_trips.clear()
for trip in trips:
if t - time_range < trip[2] <= t:
current_trips.append(trip)
for trip in current_trips:
graph = build_graph(trip, current_trips)
car_weight = []
for car in cars:
cursor.close()
cnx.close()