-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalytical_Model.py
executable file
·43 lines (38 loc) · 1.83 KB
/
Analytical_Model.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
# This is the analytical model that is going to inherit from the Traffic_Model
import numpy as np
import csv
from Traffic_Model import Traffic_Model_class
class Analytical_Model_class(Traffic_Model_class):
def __init__(self, type, name):
Traffic_Model_class.__init__(self, type)
# The folder locations of all the input files
graphLocation = 'data/' + name + '_net.csv'
demandLocation = 'data/' + name + '_od.csv'
nodeLocation = 'data/' + name + '_node.csv'
featureLocation = 'data/' + name + '_net.txt'
self.graph = np.loadtxt(graphLocation, delimiter=',', skiprows=1)
self.demand = np.loadtxt(demandLocation, delimiter=',', skiprows=1)
self.features = extract_features(featureLocation)
# LA network has a different way of processing the nodes file
if (name == "LA"):
self.node = np.loadtxt(nodeLocation, delimiter=',')
self.features[10787, 0] = self.features[10787, 0] * 1.5
self.graph[10787, -1] = self.graph[10787, -1] / (1.5 ** 4)
self.features[3348, :] = self.features[3348, :] * 1.2
self.graph[3348, -1] = self.graph[3348, -1] / (1.2 ** 4)
else:
self.node = np.loadtxt(nodeLocation, delimiter=',', skiprows=1)
#Function useful to extract features used in loading other graph data
def extract_features(input):
# features = table in the format [[capacity, length, FreeFlowTime]]
flag = False
out = []
with open(input, 'rb') as f:
reader = csv.reader(f)
for row in reader:
if len(row) > 0:
if flag == False:
if row[0].split()[0] == '~': flag = True
else:
out.append([float(e) for e in row[0].split()[2:5]])
return np.array(out)