Skip to content
Snippets Groups Projects
Commit 61d226f9 authored by markn92's avatar markn92
Browse files

minor

parent 6c7725ab
No related branches found
No related tags found
No related merge requests found
......@@ -76,15 +76,20 @@ if __name__ == '__main__':
type=float,
nargs=4,
metavar=('lat_nw', 'lon_nw', 'lat_se', 'lon_se'),
default=[None, None, None, None],
help='Use only those charging stations that are located with in a '
'rectangle defined by the north-west and south-east coordinates.'
)
args = parser.parse_args()
nw_corner = None
se_corner = None
if args.cut:
nw_corner = args.cut[:2]
se_corner = args.cut[2:]
parse_charging_stations_csv(
args.input_path,
nw_corner=args.cut[:2],
se_corner=args.cut[2:]
nw_corner=nw_corner,
se_corner=se_corner
).to_json(args.dest_path, orient='records')
......@@ -101,6 +101,9 @@ def contract_graph(G: nx.Graph, charging_stations: Set[Node], capacity: SoC,
"""
H: nx.Graph = nx.Graph()
if not charging_stations:
return H
all_cs = list(charging_stations)
for i in range(len(all_cs) - 1):
cs = all_cs[i]
......
......@@ -39,13 +39,17 @@ def query_url(service, coordinates, osrm_config: OsrmConf):
def insert_charging_stations(G, charging_stations):
"""Insert Charging Stations"""
S = set()
for s in charging_stations:
lon = s['lon']
lat = s['lat']
n = find_nearest(G, (lat, lon))
G.nodes[n][CHARGING_COEFFICIENT_KEY] = s['power']
n = find_nearest(G, (lat, lon), distance_limit=500)
if n:
G.nodes[n][CHARGING_COEFFICIENT_KEY] = s['power']
S.add(n)
return G
return S
class OsrmDistance:
......
......@@ -30,7 +30,11 @@ def haversine_distance(lon1, lat1, lon2, lat2, unit_m=True):
return c * r
def find_nearest(G, v: point):
def find_nearest(G, v: point, distance_limit=None):
"""
Find nearest point to location v within radius
of distance_limit.
"""
min_dist = None
closest_node = None
......@@ -48,7 +52,10 @@ def find_nearest(G, v: point):
closest_node = n
min_dist = d
return closest_node
if distance_limit:
return closest_node if min_dist <= distance_limit else None
else:
return closest_node
def shortest_path(G, s: point, t: point, profile):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment