diff --git a/evaluation/configs/example.yaml b/evaluation/configs/example.yaml index 44dceb7f0dce2a2b6066dd3b9dea77daabd703f8..6e0f93b7f5a6b3c30f7a0a47c9895550052500ab 100644 --- a/evaluation/configs/example.yaml +++ b/evaluation/configs/example.yaml @@ -5,12 +5,12 @@ type: query charging_stations: charging_stations.json maps: - map.osm -querys_per_setup: 10 +queries_per_setup: 10 setups: - - mu_s: capacity # Start and Target Soc + - mu_s: 85 # Start and Target Soc mu_t: 0 charging_stations: 10 # Max Number of charging Stations to be inserted. - capactiy: 85 # kWh + capacity: 85 # kWh consumption: type: gasstation consumption_coefficient: 100 # kWh/s diff --git a/evaluation/export.py b/evaluation/export.py index 2ccaace4e2c460ee9f0b71a612f026ad0eeb2404..0f49436b5977c4e56b122c9e96cb641439a5dc09 100644 --- a/evaluation/export.py +++ b/evaluation/export.py @@ -12,4 +12,4 @@ def write_head(f: TextIO, row_class: QueryRow): def write_row(f: TextIO, row: QueryRow): - f.write(SEP.join(asdict(row).values()) + "\n") + f.write(SEP.join([str(i) for i in asdict(row).values()]) + "\n") diff --git a/evaluation/queries.py b/evaluation/queries.py index a4460b28d997513a5f991a0c925770519bf9d265..1ea254d1c00f13d44940637c35d8bcb054ebb674 100644 --- a/evaluation/queries.py +++ b/evaluation/queries.py @@ -1,3 +1,5 @@ +from time import perf_counter + from evaluation.export import write_row from evaluation.T import ( GasstationQueryRow, @@ -6,23 +8,70 @@ from evaluation.T import ( AStarQueryRow ) +from evrouting.T import Result from evrouting import gasstation, charge from evrouting.osm.routing import GasstationAccessFunctions __all__ = ['gasstation_query', 'charge_query', 'classic_query', 'astar_query'] -def gasstation_query(graph, conf, file): - pass +def gasstation_query(graph, conf, s, t, file): + f = GasstationAccessFunctions(conf['consumption']['consumption_coefficient']) + + start = perf_counter() + contracted_graph = gasstation.routing.contract_graph( + G=graph, + charging_stations=graph.charging_stations, + capacity=conf['capacity'], + f=f + ) + contraction_time = perf_counter() - start + + start = perf_counter() + state_graph = gasstation.routing.state_graph( + contracted_graph, + conf['capacity'], + f + ) + state_graph_time = perf_counter() - start + + start = perf_counter() + result = gasstation.routing.shortest_path( + G=graph, + charging_stations=graph.charging_stations, + s=s, + t=t, + initial_soc=conf['mu_s'], + final_soc=conf['mu_t'], + capacity=conf['capacity'], + f=f, + extended_graph=state_graph, + contracted_graph=contracted_graph + ) + query_time = perf_counter() - start + + row = GasstationQueryRow( + start_node=s, + target_node=t, + query_time=query_time, + trip_time=result.trip_time if type(result) == Result else None, + nodes=len(graph.nodes), + edges=len(graph.edges), + charging_stations=len(graph.charging_stations), + time_contracted_graph=contraction_time, + time_state_graph=state_graph_time + ) + + write_row(file, row) -def charge_query(graph, conf, file): +def charge_query(graph, conf, s, t, file): pass -def classic_query(graph, conf, file): +def classic_query(graph, conf, s, t, file): pass -def astar_query(graph, conf, file): +def astar_query(graph, conf, s, t, file): pass diff --git a/evaluation/results/example/queries/gasstation.csv b/evaluation/results/example/queries/gasstation.csv index e0eab29be90dfcd179f5096540ab88b1f5af22ad..f7b0681e8666319522863b8bc831d61a55659942 100644 --- a/evaluation/results/example/queries/gasstation.csv +++ b/evaluation/results/example/queries/gasstation.csv @@ -1 +1,11 @@ start_node,target_node,query_time,trip_time,nodes,edges,charging_stations,time_contracted_graph,time_state_graph +549931430,3273201464,0.02408712999749696,None,2827,5691,3,0.014958268002374098,3.0371003958862275e-05 +2729891690,6603016874,0.02328153499547625,None,2827,5691,3,0.01450053900043713,3.0627001251559705e-05 +34053773,408478843,0.03271863699774258,None,2827,5691,3,0.014691472999402322,1.9122999219689518e-05 +292981057,4955446070,0.029121861000021454,None,2827,5691,3,0.01552509299654048,2.008400042541325e-05 +1254599554,360747579,0.017258337000384927,None,2827,5691,3,0.014459179998084437,1.8801998521666974e-05 +6389441586,508824243,0.016824515005282592,None,2827,5691,3,0.015478776003874373,1.987600262509659e-05 +7042580410,1929118248,0.04107918299996527,None,2827,5691,3,0.01451436200295575,1.9384002371225506e-05 +7074500856,7140363786,0.03340997399936896,None,2827,5691,3,0.014721665997058153,1.9647995941340923e-05 +360747732,4955446065,0.026879377001023386,None,2827,5691,3,0.016268585000943858,1.9888000679202378e-05 +600866946,4016874580,0.02424645799328573,None,2827,5691,3,0.0144769019971136,2.0027000573463738e-05 diff --git a/evaluation/run.py b/evaluation/run.py index 3d7b4a6207577c73c36ae2014e5af45057e6843c..828864c2aed43e01b23a63a53df101be90bfbde4 100644 --- a/evaluation/run.py +++ b/evaluation/run.py @@ -1,5 +1,6 @@ import argparse import json +import random from pathlib import Path import yaml @@ -14,7 +15,7 @@ from evaluation.queries import * def query_benchmark(graphs, conf, result_dir): - QUERIES = [ + query_conf = [ Query(query_function=gasstation_query, filename='gasstation.csv', row_dataclass=GasstationQueryRow), @@ -24,10 +25,16 @@ def query_benchmark(graphs, ] for G in graphs: - for func, filename, row_class in QUERIES: - with result_dir.joinpath(filename).open('w') as f: - write_head(f, row_class) - func(G, conf, f) + nodes = random.choices(list(G.nodes), k=2 * conf['queries_per_setup']) + for setup in conf['setups']: + start_nodes = nodes[:int(len(nodes) / 2)] + target_nodes = nodes[int(len(nodes) / 2):] + + for func, filename, row_class in query_conf: + with result_dir.joinpath(filename).open('w') as f: + write_head(f, row_class) + for s, t in zip(start_nodes, target_nodes): + func(G, setup, s, t, f) def get_map(osm_path: Path, cs_path: Path):