-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_degree.sql
50 lines (40 loc) · 1.89 KB
/
route_degree.sql
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
-- We can calculate the degree of each node
-- DAYTIME--------------------------------------------------------------------------------------------------------------
SELECT DISTINCT route_1, (SELECT SUM(weight) FROM route_w_links_daytime t2 WHERE t2.route_1=t1.route_1) AS degree
INTO route_degree_daytime
FROM route_w_links_daytime t1
ORDER BY route_1;
-- We can turn this into a histogram by calculating p_k=N_k/N for each k
SELECT DISTINCT t1.degree, (SELECT count(t2.degree) FROM route_degree_daytime t2 WHERE t2.degree=t1.degree) AS pk
INTO tmp
FROM route_degree_daytime t1
ORDER BY t1.degree;
SELECT degree, pk/(SELECT SUM(t2.pk) FROM tmp t2) AS pk
INTO route_degree_distr_daytime
FROM tmp;
DROP TABLE tmp;
-- The average degree:
-- SELECT AVG(t3.degree)
-- FROM (SELECT DISTINCT route_1, (SELECT SUM(weight) FROM route_w_links_daytime t2 WHERE t2.route_1=t1.route_1) AS degree
-- FROM route_w_links_daytime t1
-- ORDER BY route_1) t3;
-- RESULT: 55.77
-- NIGHTTIME------------------------------------------------------------------------------------------------------------
SELECT DISTINCT route_1, (SELECT SUM(weight) FROM route_w_links_nighttime t2 WHERE t2.route_1=t1.route_1) AS degree
INTO route_degree_nighttime
FROM route_w_links_nighttime t1
ORDER BY route_1;
SELECT DISTINCT t1.degree, (SELECT count(t2.degree) FROM route_degree_nighttime t2 WHERE t2.degree=t1.degree) AS pk
INTO tmp
FROM route_degree_nighttime t1
ORDER BY t1.degree;
SELECT degree, pk/(SELECT SUM(t2.pk) FROM tmp t2) AS pk
INTO route_degree_distr_nighttime
FROM tmp;
DROP TABLE tmp;
-- The average degree:
-- SELECT AVG(t3.degree)
-- FROM (SELECT DISTINCT route_1, (SELECT SUM(weight) FROM route_w_links_nighttime t2 WHERE t2.route_1=t1.route_1) AS degree
-- FROM route_w_links_nighttime t1
-- ORDER BY route_1) t3;
-- RESULT: 17.03