diff --git a/.gitignore b/.gitignore index 16c26a0f1ef30533d30358b424276dc2850360cc..04c99d14122ccf07027a0b3ed3768a0973232047 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ dist *.osm mapcache evaluation/results +stats*.csv diff --git a/debug/debug.py b/debug/debug.py index 7c5cfcdeef2ab6c4b73e846f6dcda7c35ad0fe18..b50a09b75417e3d2355869081a2930e7d29cbfd7 100644 --- a/debug/debug.py +++ b/debug/debug.py @@ -1,5 +1,7 @@ import json +import logging.config import pickle +import os from time import perf_counter from evrouting.osm.imports import OSMGraph from evrouting import charge @@ -29,23 +31,58 @@ def main(): mu_s = 40000 mu_t = 0 capacity = 40000 - s = '274939401' - t = '299642186' - - print(f'Solving {s} to {t}..') - start = perf_counter() - charge.routing.shortest_path( - G=G, - charging_stations=G.charging_stations, - s=s, - t=t, - initial_soc=mu_s, - final_soc=mu_t, - capacity=capacity, - c=c - ) - runtime = perf_counter() - start + tasks = [ + ('2600400888', '2364151130'), + ('274939401', '299642186') + ] + + for i, (s, t) in enumerate(tasks): + print(f'Solving {s} to {t}..') + start = perf_counter() + charge.routing.shortest_path( + G=G, + charging_stations=G.charging_stations, + s=s, + t=t, + initial_soc=mu_s, + final_soc=mu_t, + 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__': + logging.config.dictConfig(get_logging_config()) main() diff --git a/evaluation/configs/rank.yaml b/evaluation/configs/rank.yaml index 2affcd758868dce966e8f2a61631a3c33b1f17bc..7e93e44f3679f15ec6a2af24d6649aa2f8756239 100644 --- a/evaluation/configs/rank.yaml +++ b/evaluation/configs/rank.yaml @@ -5,8 +5,8 @@ description: > paths: charging_stations: charging_stations.json map: medium_nurnberg.osm -queries_per_rank: 20 -ranks: [6, 8, 10, 12, 14, 18] +queries_per_rank: 1 +ranks: [6, 8, 10, 12, 14, 18, 20, 22] algorithms: [charge] mu_s: 40 # Start and Target Soc mu_t: 0 diff --git a/evrouting/charge/routing.py b/evrouting/charge/routing.py index 9549ab039aacddd7a08cfb0b5b5649fa6ab3baeb..1eafd0f570d177b6e3e34f032d67b754a03292dd 100644 --- a/evrouting/charge/routing.py +++ b/evrouting/charge/routing.py @@ -7,6 +7,7 @@ Implementation of the CHArge algorithm [0] with two further constraints: [0] https://dl.acm.org/doi/10.1145/2820783.2820826 """ +import logging from typing import Dict, List, Tuple, Set from math import inf @@ -22,6 +23,8 @@ from evrouting.charge.factories import ( SoCProfileFactory ) +logger = logging.getLogger('stats') + 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: @@ -60,11 +63,13 @@ def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node, # Shortcut for key function keys = LabelPriorityQueue.keys - + logger.debug('t_min,soc_min') while prio_queue: node_min: Node = prio_queue.peak_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) if node_min == t: @@ -131,6 +136,8 @@ def shortest_path(G: nx.DiGraph, charging_stations: Set[Node], s: Node, t: Node, try: is_new_min: bool = label_neighbour == l_uns[n].peak_min() except KeyError: + # Hasn't been inserted into l_uns because it was dominated + # by a label in l_set continue if is_new_min: