From 31033f25c68a5b08f042c4a9f073144dbfe14541 Mon Sep 17 00:00:00 2001 From: "niehues.mark@gmail.com" <niehues.mark@gmail.com> Date: Fri, 13 Mar 2020 12:51:17 +0100 Subject: [PATCH] wip --- evrouting/charge/routing.py | 83 +++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/evrouting/charge/routing.py b/evrouting/charge/routing.py index e9a2def..6d825fe 100644 --- a/evrouting/charge/routing.py +++ b/evrouting/charge/routing.py @@ -1,16 +1,93 @@ +from typing import Callable +from math import inf + import networkx as nx +from evrouting.T import Node, SoC +from evrouting.utils import PriorityQueue + +from .T import SoCProfile -def shortest_path(G: nx.Graph, s, t, b_0: float, b_t: float, U: float): +def shortest_path(G: nx.Graph, S: set, s: Node, t: Node, beta_s: SoC, beta_t: SoC, U: SoC): """ Calculates shortest path using the CHarge algorithm. :param G: Input Graph :param s: Start Node identifier :param t: End Node identifier - :param b_0: Start SoC - :param b_t: End SoC + :param beta_s: Start SoC + :param beta_t: End SoC :param U: Capacity :return: """ + q = PriorityQueue() + l_set = {v: set() for v in G} + l_uns = {v: PriorityQueue() for v in G} + + v_0: Node = Node(len(G.nodes)) + G.add_node(v_0) + + S.add(v_0) + + cf_v_0 = [(0, beta_s)] + + l_uns[s] = PriorityQueue() + l_uns[s].insert((0, beta_s, v_0, WHAT), 0) + + q.insert(s, 0) + + # run main loop + while True: + try: + v = q.peak_min() + except KeyError: + # empty queue + break + + l = l_uns[v].delete_min() + l_set[v].add(l) + + if v == t: + return t_min(f(l)) + + # handle charging stations + t_trip, beta_u, u, b_u_v = l + if v in S and not v == u: + for t_charge in t_breaks(l): + l_uns[v].insert(new_label(l), priority=) # prio?? + + # update priority queue + if l_uns[v]: + l_new = l_uns[v].peak_min() + q.insert(v, key(l_new)) + else: + q.delete_min() + + # scan outgoing arcs + for x, y in G[v]: + b_x_y = link(beta_u_v, create_b(G, x, y)) + if not b_x_y(beta_max_u) == -inf: + l_new = (t_trip + G.edges[x, y]['weight'], beta_u, u, b_x_y) + l_uns[y].insert(l_new) + if l_new == l_uns[y].peak_min(): + q.insert(y, key(l_new)) + + +def link(beta: SoCProfile, b_func: SoCProfile) -> SoCProfile: + pass + + +def creade_b(G: nx.Graph, x: Node, y: Node) -> SoCProfile: + pass + + +def key(label): + pass + + +def f(label): + pass + + +def t_min(f): pass -- GitLab