Skip to content

Commit 8ba4647

Browse files
committed
first commit
0 parents  commit 8ba4647

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/__init__.py

Whitespace-only changes.

src/lrsa.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import networkx as nx
2+
3+
4+
class LSRA:
5+
def __init__(self):
6+
self.graph = nx.Graph()
7+
8+
def add_edge(self, node1, node2, weight):
9+
self.graph.add_edge(node1, node2, weight=weight)
10+
11+
def shortest_path(self, source, target):
12+
return nx.shortest_path(self.graph, source=source, target=target, weight='weight')
13+
14+
if __name__ == "__main__":
15+
lsra = LSRA()
16+
lsra.add_edge('A', 'B', 1)
17+
lsra.add_edge('A', 'C', 2)
18+
lsra.add_edge('B', 'C', 1)
19+
lsra.add_edge('B', 'D', 3)
20+
lsra.add_edge('C', 'D', 1)
21+
print("Shortest path from A to D:", lsra.shortest_path('A', 'D'))

0 commit comments

Comments
 (0)