-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
blockchain_integration/pi_network/PiPulse/network/topology/graph.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import networkx as nx | ||
|
||
class Graph: | ||
def __init__(self): | ||
self.graph = nx.Graph() | ||
|
||
def add_node(self, node_id, node_type, **kwargs): | ||
self.graph.add_node(node_id, node_type=node_type, **kwargs) | ||
|
||
def add_edge(self, node1_id, node2_id, **kwargs): | ||
self.graph.add_edge(node1_id, node2_id, **kwargs) | ||
|
||
def remove_node(self, node_id): | ||
self.graph.remove_node(node_id) | ||
|
||
def remove_edge(self, node1_id, node2_id): | ||
self.graph.remove_edge(node1_id, node2_id) | ||
|
||
def get_node(self, node_id): | ||
return self.graph.nodes.get(node_id) | ||
|
||
def get_edge(self, node1_id, node2_id): | ||
return self.graph.get_edge_data(node1_id, node2_id) | ||
|
||
def nodes(self): | ||
return list(self.graph.nodes) | ||
|
||
def edges(self): | ||
return list(self.graph.edges) |