Skip to content

Commit

Permalink
Create graph.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 10, 2024
1 parent 8aad7f8 commit 10a9b28
Showing 1 changed file with 29 additions and 0 deletions.
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)

0 comments on commit 10a9b28

Please sign in to comment.