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

debugging

parent 4d5e4167
No related branches found
No related tags found
No related merge requests found
...@@ -8,3 +8,4 @@ dist ...@@ -8,3 +8,4 @@ dist
*.osm *.osm
mapcache mapcache
evaluation/results evaluation/results
stats*.csv
import json import json
import logging.config
import pickle import pickle
import os
from time import perf_counter from time import perf_counter
from evrouting.osm.imports import OSMGraph from evrouting.osm.imports import OSMGraph
from evrouting import charge from evrouting import charge
...@@ -29,23 +31,58 @@ def main(): ...@@ -29,23 +31,58 @@ def main():
mu_s = 40000 mu_s = 40000
mu_t = 0 mu_t = 0
capacity = 40000 capacity = 40000
s = '274939401' tasks = [
t = '299642186' ('2600400888', '2364151130'),
('274939401', '299642186')
print(f'Solving {s} to {t}..') ]
start = perf_counter()
charge.routing.shortest_path( for i, (s, t) in enumerate(tasks):
G=G, print(f'Solving {s} to {t}..')
charging_stations=G.charging_stations, start = perf_counter()
s=s, charge.routing.shortest_path(
t=t, G=G,
initial_soc=mu_s, charging_stations=G.charging_stations,
final_soc=mu_t, s=s,
capacity=capacity, t=t,
c=c initial_soc=mu_s,
) final_soc=mu_t,
runtime = perf_counter() - start capacity=capacity,
c=c
)
runtime = perf_counter() - start
try:
os.rename('stats.csv', f'stats{i}.csv')
except FileExistsError:
os.remove('fstats{i}.csv')
os.rename('stats.csv', f'stats{i}.csv')
def get_logging_config():
return {
'version': 1,
'formatters': {
'plain': {
'fmt': '%(message)s'
}
},
'handlers': {
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'plain',
'mode': 'w',
'filename': 'stats.csv'
}
},
'loggers': {
'stats': {
'level': 'DEBUG',
'propagate': 0,
'handlers': ['file']
}
}
}
if __name__ == '__main__': if __name__ == '__main__':
logging.config.dictConfig(get_logging_config())
main() main()
...@@ -5,8 +5,8 @@ description: > ...@@ -5,8 +5,8 @@ description: >
paths: paths:
charging_stations: charging_stations.json charging_stations: charging_stations.json
map: medium_nurnberg.osm map: medium_nurnberg.osm
queries_per_rank: 20 queries_per_rank: 1
ranks: [6, 8, 10, 12, 14, 18] ranks: [6, 8, 10, 12, 14, 18, 20, 22]
algorithms: [charge] algorithms: [charge]
mu_s: 40 # Start and Target Soc mu_s: 40 # Start and Target Soc
mu_t: 0 mu_t: 0
......
...@@ -7,6 +7,7 @@ Implementation of the CHArge algorithm [0] with two further constraints: ...@@ -7,6 +7,7 @@ Implementation of the CHArge algorithm [0] with two further constraints:
[0] https://dl.acm.org/doi/10.1145/2820783.2820826 [0] https://dl.acm.org/doi/10.1145/2820783.2820826
""" """
import logging
from typing import Dict, List, Tuple, Set from typing import Dict, List, Tuple, Set
from math import inf from math import inf
...@@ -22,6 +23,8 @@ from evrouting.charge.factories import ( ...@@ -22,6 +23,8 @@ from evrouting.charge.factories import (
SoCProfileFactory SoCProfileFactory
) )
logger = logging.getLogger('stats')
def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node, def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node,
initial_soc: SoC, final_soc: SoC, capacity: SoC, c=consumption) -> Result: initial_soc: SoC, final_soc: SoC, capacity: SoC, c=consumption) -> Result:
...@@ -60,11 +63,13 @@ def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node, ...@@ -60,11 +63,13 @@ def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node,
# Shortcut for key function # Shortcut for key function
keys = LabelPriorityQueue.keys keys = LabelPriorityQueue.keys
logger.debug('t_min,soc_min')
while prio_queue: while prio_queue:
node_min: Node = prio_queue.peak_min() node_min: Node = prio_queue.peak_min()
label_node_min: Label = l_uns[node_min].delete_min() label_node_min: Label = l_uns[node_min].delete_min()
logger.debug('{priority},{count}'.format(
**keys(f_soc_factory(label_node_min))))
l_set[node_min].append(label_node_min) l_set[node_min].append(label_node_min)
if node_min == t: if node_min == t:
...@@ -131,6 +136,8 @@ def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node, ...@@ -131,6 +136,8 @@ def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node,
try: try:
is_new_min: bool = label_neighbour == l_uns[n].peak_min() is_new_min: bool = label_neighbour == l_uns[n].peak_min()
except KeyError: except KeyError:
# Hasn't been inserted into l_uns because it was dominated
# by a label in l_set
continue continue
if is_new_min: if is_new_min:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment