forked from sanggu-park/blaft_simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.py
77 lines (58 loc) · 2.51 KB
/
Parser.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import numpy as np
import traci
import networkx as nx
from Router import extractPoints
def geo_info(net_file):
"""net_file contains edge, node, and lane info"""
"""This method transforms SUMO's geographic information to Graph (nodes and edges)."""
tree = ET.parse(net_file)
root = tree.getroot()
C = nx.DiGraph() # SUMO Road Connection Information
G = nx.DiGraph() # Map Location Information
pntID = int(0)
for conn in root.findall('connection'):
fromLane = conn.attrib['from'] + '_' + conn.attrib['fromLane']
if ":n" in fromLane:
toLane = conn.attrib['to'] + '_' + conn.attrib['toLane']
elif "to" in fromLane:
toLane = conn.attrib['via']
C.add_edge(fromLane, toLane)
for conn in root.findall('connection'):
fromEdge = conn.attrib['from']
if ":n" in fromEdge:
toEdge = conn.attrib['to']
elif "to" in fromEdge:
toEdge = conn.attrib['via'][:-2]
C.add_edge(fromEdge, toEdge)
for edge in root.findall('edge'):
fromEdge = edge.attrib['id']
# print('fromEdge_test: ', fromEdge)
for lane in edge.findall('lane'):
laneID = lane.attrib['id']
shape = lane.attrib['shape']
shape_split = shape.split(' ')
for k in range(len(shape_split)):
shape_split[k] = shape_split[k].split(',')
shape = np.array(shape_split, dtype=float)
G, pntID = extractPoints(G, fromEdge, laneID, pntID, shape)
return G, C
def vehicle_info(routefile, vehID):
"""This method returns one vehicle instance"""
tree = ET.parse(routefile)
root = tree.getroot()
xpos, ypos = traci.vehicle.getPosition(vehID)
vel = traci.vehicle.getSpeed(vehID)
angle = traci.vehicle.getAngle(vehID)
# Put Values In
for vtype in root.findall('vType'):
# if veh.attrib['type'] == vtype.attrib['id']:
acc_max = vtype.attrib['accel'] # accel
dec_min = vtype.attrib['decel'] # decel
dec_max = vtype.attrib['emergencyDecel'] # emergencyDecel
length = vtype.attrib['length']
width = vtype.attrib['width']
height = vtype.attrib['height']
return xpos, ypos, vel, angle, acc_max, dec_min, dec_max, length, width, height