Skip to content
Snippets Groups Projects
Commit 23bdf8b0 authored by markn92's avatar markn92
Browse files

cleanup

parent 1223d498
No related branches found
No related tags found
No related merge requests found
from collections import namedtuple
import networkx as nx
from evrouting.T import Wh, ChargingCoefficient, Time, Node, NodeData, EdgeData
from evrouting.T import (
Wh,
ChargingCoefficient,
Time,
Node,
NodeData,
EdgeData,
ConsumptionFunction
)
TemplateEdge = namedtuple('Edge', ['u', 'v', 'distance', 'consumption'])
TemplateNode = namedtuple(
......@@ -41,3 +49,30 @@ def label(G: nx.Graph, u: Node) -> str:
def sum_weights(G, path, weight) -> float:
return sum(G[u][v][weight] for u, v in zip(path[:-1], path[1:]))
def consumption_function_distance_factory(consumption: float) -> ConsumptionFunction:
"""
:param consumption: in kWh/km
"""
def c(G, u, v):
"""Returns consumption in Wh from u to v."""
try:
return G[u][v][HAVERSINE_KEY] * consumption
except KeyError:
return G[u][v][CONSUMPTION_KEY]
return c
def consumption_function_time_factory(consumption: float) -> ConsumptionFunction:
"""
:param consumption: in kWh/s
"""
def c(G, u, v):
"""Returns consumption in Wh from u to v."""
return G[u][v][DISTANCE_KEY] * consumption * 1000
return c
......@@ -3,9 +3,9 @@ from math import radians, cos, sin, asin, sqrt
import networkx as nx
from evrouting.T import ConsumptionFunction, Result, EmptyResult
from evrouting.T import Result, EmptyResult
from evrouting.graph_tools import (
DISTANCE_KEY, HAVERSINE_KEY, CONSUMPTION_KEY, sum_weights
DISTANCE_KEY, sum_weights
)
from evrouting.osm.const import ms_to_kmh
......@@ -73,17 +73,3 @@ def to_coordinates(G, path):
return list(map(get_coordinates, path))
def consumption_function_factory(consumption: float) -> ConsumptionFunction:
"""
:param consumption: in kWh/km
:return: consi
"""
def c(G, u, v):
"""Returns consumption in Wh from u to v."""
try:
return G[u][v][HAVERSINE_KEY] * consumption
except KeyError:
return G[u][v][CONSUMPTION_KEY]
return c
......@@ -9,7 +9,11 @@ from evrouting.osm.imports import read_osm, OSMGraph
from evrouting.osm.profiles import car
from evrouting.osm.routing import shortest_path
from evrouting.graph_tools import (
CHARGING_COEFFICIENT_KEY, DISTANCE_KEY, CONSUMPTION_KEY, HAVERSINE_KEY
CHARGING_COEFFICIENT_KEY,
DISTANCE_KEY,
CONSUMPTION_KEY,
HAVERSINE_KEY,
consumption_function_distance_factory
)
......@@ -110,13 +114,7 @@ def test_charge_shortest_route_dimensions(map_graph):
consumption = 1 # kWh/km
cost_path = 6 * consumption * 1000 # distance * consumption in Wh
def c(G, u, v):
"""Returns consumption in Wh from u to v."""
try:
return G[u][v][HAVERSINE_KEY] * consumption
except KeyError:
return G[u][v][CONSUMPTION_KEY]
c = consumption_function_distance_factory(consumption)
result = charge.routing.shortest_path(
G=map_graph,
charging_stations=map_graph.charging_stations,
......@@ -144,12 +142,7 @@ def test_charge_shortest_route_stop(map_graph):
consumption = 1 # kWh/km
cost_path = 6 * consumption * 1000 # distance * consumption in Wh
def c(G, u, v):
"""Returns consumption in Wh from u to v."""
try:
return G[u][v][HAVERSINE_KEY] * consumption
except KeyError:
return G[u][v][CONSUMPTION_KEY]
c = consumption_function_distance_factory(consumption)
result = charge.routing.shortest_path(
G=map_graph,
......
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