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

using other alg

parent 3ce94a16
No related branches found
No related tags found
No related merge requests found
from typing import Set, Union, Callable, List
import networkx as nx
from evrouting.T import Node, SoC
......@@ -21,10 +20,12 @@ def shortest_path(G: nx.Graph, s, t, b_0: float, b_t: float, U: float):
pass
def dijkstra(G: nx.Graph, u: Node, v: Node, weight: str = 'weight') -> Union[int, float]:
path: List[Node] = nx.algorithms.shortest_path(G, u, v, weight=weight)
return sum([G.edges[path[i], path[i + 1]][weight] for i in range(len(path) - 1)])
def dijkstra(G: nx.Graph, u: Node, v: Node,
weight: str = 'weight') -> Union[int, float]:
length, _ = nx.algorithms.shortest_paths.single_source_dijkstra(
G, u, v, weight=weight
)
return length
def contract_graph(G: nx.Graph, S: Set[Node], U: SoC,
......
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