-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathArcFlagsPreProcess.py
94 lines (76 loc) · 3.63 KB
/
ArcFlagsPreProcess.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
from Node import get_correct_nodes
from DijkstrasAlgorithm import DijkstrasAlgorithm
import csv
import timeit
from Map import Map
from db_functions import db_arc_flags
from db_functions import db_main
from datetime import datetime
from traffic_estimation import plot_estimates
import cluster_kd
# Pre-process the map with arc flags.
class ArcFlagsPreProcess:
# Resets the arcflag set in dijkstras algorithm
# Converts an arcflag binary string to hexadecimal so that it can be stored
# in text easier
@staticmethod
def convert_to_hex(list_of_arcs):
final_string = ""
for i in range(0, len(list_of_arcs), 4):
value_to_hex = 8 * list_of_arcs[i] + 4 * list_of_arcs[i + 1] + (
2 * list_of_arcs[i + 2] + list_of_arcs[i + 3])
final_string += str(hex(value_to_hex))[-1:]
return final_string
@staticmethod
def run(region_size = 250):
# nyc_map = Map("nyc_map4/nodes.csv", "nyc_map4/links.csv",
# lookup_kd_size=1, region_kd_size=region_size,
# limit_bbox=Map.reasonable_nyc_bbox)
# nyc_map.assign_node_regions()
nyc_map = cluster_kd.createMap(region_size)
nyc_map.assign_link_arc_flags()
#nyc_map.save_region("../nyc_map4/region.csv")
#get_correct_nodes(nyc_map, "../speeds_per_hour/" + map_file, None)
i = 0
print nyc_map.total_region_count
for region_id in range(nyc_map.total_region_count):
# print "Next Region!"
boundary_nodes = nyc_map.get_region_boundary_nodes(region_id)
# Does a multi-origin bidirectional dijkstra search to get an
# arcflag tree
warmstart = True
use_domination_value = False
DijkstrasAlgorithm.bidirectional_dijkstra(boundary_nodes,
nyc_map,
warmstart,
use_domination_value)
#####################################################################
# DRAW ARC_FLAGS USING THIS
# pace_dict = {}
# for link in nyc_map.links:
# if link.backward_arc_flags_vector[i] == True:
# pace_dict[(link.origin_node_id, link.connecting_node_id)] = 5
# else:
# pace_dict[(link.origin_node_id, link.connecting_node_id)] = -5
# plot_estimates.plot_speed(nyc_map, "Backward Arc Flags Region: " + str(i), "Backward"+str(i), pace_dict)
# pace_dict = {}
# for link in nyc_map.links:
# if link.forward_arc_flags_vector[i] == True:
# pace_dict[(link.origin_node_id, link.connecting_node_id)] = 5
# else:
# pace_dict[(link.origin_node_id, link.connecting_node_id)] = -5
# plot_estimates.plot_speed(nyc_map, "Forward Arc Flags Region: " + str(i), "Forward"+str(i), pace_dict)
#####################################################################
i += 1
d = datetime(2012,3,5,2)
db_main.connect("db_functions/database.conf")
db_arc_flags.create_arc_flag_table()
db_arc_flags.save_arc_flags(nyc_map, d)
db_main.close()
# This is a hexadecimal string that converts region to true or false
# RegionNumber = 0, 1, 2, 3, 4, 5, 6, 7
# is_forward_arc_flags = 0, 1, 1, 0, 1, 1, 0, 1
# HexString = 6D
# TODO: print backward arc flags
if __name__ == '__main__':
ArcFlagsPreProcess.run("0_0")