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

hell of boilerplate haha

parent 30422ef9
No related branches found
No related tags found
No related merge requests found
from collections import namedtuple
from dataclasses import dataclass
@dataclass
class QueryRow:
start_node: str
target_node: str
query_time: float
trip_time: float
nodes: int
edges: int
charging_stations: int
@dataclass
class GasstationQueryRow(QueryRow):
time_contracted_graph: float
time_state_graph: float
@dataclass
class ChargeQueryRow(QueryRow):
time_contracted_graph: float
time_state_graph: float
@dataclass
class ClassicQueryRow(QueryRow):
dijkstra_rank: int
@dataclass
class AStarQueryRow(QueryRow):
pass
Query = namedtuple('Query',
field_names=['query_function', 'filename', 'row_dataclass'])
File moved
description: >
Compare charge and gasstation problem by assuming for the charge
algorithm also an consumption proportional to driving time
algorithm also an consumption proportional to driving time.
type: query
charging_stations: charging_stations.json
maps:
- map.osm
querys_per_setup: 10
......@@ -10,7 +12,5 @@ setups:
charging_stations: 10 # Max Number of charging Stations to be inserted.
capactiy: 85 # kWh
consumption:
gasstation:
consumption_coefficient: 100 # kWh/s
charge:
type: gasstation # Use the same
type: gasstation
consumption_coefficient: 100 # kWh/s
from typing import TextIO
from dataclasses import asdict, fields
from evaluation.T import QueryRow
SEP = ','
def write_head(f: TextIO, row_class: QueryRow):
head = SEP.join([field.name for field in fields(row_class)])
f.write(head + '\n')
def write_row(f: TextIO, row: QueryRow):
f.write(SEP.join(asdict(row).values()) + "\n")
from evaluation.export import write_row
from evaluation.T import (
GasstationQueryRow,
ChargeQueryRow,
ClassicQueryRow,
AStarQueryRow
)
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 charge_query(graph, conf, file):
pass
def classic_query(graph, conf, file):
pass
def astar_query(graph, conf, file):
pass
start_node,target_node,query_time,trip_time,nodes,edges,charging_stations
start_node,target_node,query_time,trip_time,nodes,edges,charging_stations,time_contracted_graph,time_state_graph
start_node,target_node,query_time,trip_time,nodes,edges,charging_stations,dijkstra_rank
start_node,target_node,query_time,trip_time,nodes,edges,charging_stations,time_contracted_graph,time_state_graph
import logging.config
import argparse
import json
from pathlib import Path
import yaml
from evrouting import gasstation, charge
def get_logging_config(gasstation_results: str, charging_results: str):
gasstation_path = str(Path(__file__).parent.joinpath('results/' + gasstation_results))
charging_path = str(Path(__file__).parent.joinpath('results/' + charging_results))
return {
'version': 1,
'formatters': {
'query': {
'fmt': '{s},{t},{time}',
'style': '{'
}
},
'handlers': {
'gasstation': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'query',
'filename': gasstation_path
},
'charge': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'query',
'filename': charging_path
}
},
'loggers': {
'benchmark.gasstation': {
'handlers': ['gasstation'],
'level': 'INFO'
},
'benchmark.charge': {
'handlers': ['charge'],
'level': 'INFO'
}
}
}
from evrouting.osm.imports import read_osm
from evaluation.T import *
from evaluation.export import write_head
from evaluation.queries import *
def query_benchmark(graphs,
conf,
result_dir):
QUERIES = [
Query(query_function=gasstation_query,
filename='gasstation.csv',
row_dataclass=GasstationQueryRow),
Query(charge_query, 'charge.csv', ChargeQueryRow),
Query(classic_query, 'classic.csv', ClassicQueryRow),
Query(astar_query, 'astar.csv', AStarQueryRow)
]
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)
def get_map(osm_path: Path, cs_path: Path):
graph = read_osm(str(osm_path))
with cs_path.open() as f:
cs = json.load(f)
graph.insert_charging_stations(cs)
return graph
if __name__ == '__main__':
base = Path(__file__).parent
static = base.joinpath('static')
results_dir = base.joinpath('results')
static_dir = base.joinpath('static')
maps_dir = static_dir.joinpath('maps')
# Setup File Streams
logging.config.dictConfig(
get_logging_config('gasstation.log', 'charge.log')
)
# Charging Stations
cs_path = static_dir.joinpath('charging_stations.json')
parser = argparse.ArgumentParser(description='Run Benchmark Scripts.')
parser.add_argument(
'--configs',
help='List of filenames to benchmark YAML configs in ./configs.',
type=Path,
nargs='+'
)
args = parser.parse_args()
path: str
path: Path
for path in args.configs:
if not path.endswith('.yaml'):
path += '.yaml'
benchmark_dir = results_dir.joinpath(path.with_suffix(''))
benchmark_dir.mkdir(exist_ok=True)
with open(base.joinpath('configs/' + path)) as f:
path = path.with_suffix('.yaml')
with base.joinpath('configs/', path).open() as f:
conf = yaml.load(f, Loader=yaml.Loader)
print(conf)
graphs = [get_map(maps_dir.joinpath(m), cs_path) for m in conf['maps']]
if conf['type'] == 'query':
query_dir = benchmark_dir.joinpath('queries')
query_dir.mkdir(exist_ok=True)
query_benchmark(graphs=graphs,
conf=conf,
result_dir=query_dir)
from collections import namedtuple
from typing import Union
import networkx as nx
from evrouting.T import (
......
......@@ -21,7 +21,7 @@ import rtree
from evrouting.graph_tools import CHARGING_COEFFICIENT_KEY, DISTANCE_KEY, HAVERSINE_KEY
from evrouting.osm.const import ms_to_kmh
from evrouting.osm.profiles import speed
from evrouting.osm.profiles import speed, car
from evrouting.osm.routing import point, haversine_distance
logger = logging.getLogger(__name__)
......@@ -101,7 +101,7 @@ class OSMGraph(nx.DiGraph):
return n
def read_osm(osm_xml_data, profile) -> OSMGraph:
def read_osm(osm_xml_data, profile=car) -> OSMGraph:
"""
Read graph in OSM format from file specified by name or by stream object.
Create Graph containing all highways as edges.
......
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