Skip to content

Commit

Permalink
update utils.py with dense nx graph examples
Browse files Browse the repository at this point in the history
  • Loading branch information
XinweiHe committed Dec 24, 2020
1 parent fc10d98 commit 33e30f2
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ def simple_networkx_small_graph(directed=True):

return G


def simple_networkx_dense_multigraph(num_edges_removed=0):
# TODO: restrict value of num_edges_removed
G = nx.MultiDiGraph()
for i in range(5):
G.add_node(i, node_label=0)

cnt = 0
for i in range(5):
for j in range(5):
if cnt >= num_edges_removed:
for k in range(3):
G.add_edge(i, j, edge_label=0)
cnt += 1

return G


def simple_networkx_dense_graph(num_edges_removed=0):
# TODO: restrict value of num_edges_removed
G = nx.DiGraph()
for i in range(5):
G.add_node(i, node_label=0)

cnt = 0
for i in range(5):
for j in range(5):
if cnt >= num_edges_removed:
G.add_edge(i, j, edge_label=0)
cnt += 1

return G

# TODO: update graph generator s.t. homogeneous & heterogeneous graph share the same format.
def simple_networkx_graph(directed=True):
num_nodes = 10
Expand Down Expand Up @@ -197,6 +230,66 @@ def gen_graph(size, graph):
return graph.subgraph(neigh)


def generate_simple_dense_hete_graph(num_edges_removed=0):
# TODO: restrict value of num_edges_removed
G = nx.DiGraph()

for i in range(3):
G.add_node(i, node_label=0, node_type=0)

for i in range(3, 5):
G.add_node(i, node_label=0, node_type=1)

# message_type (0, 0, 0)
cnt = 0
for i in range(3):
for j in range(3):
if cnt >= num_edges_removed:
G.add_edge(i, j, edge_label=1, edge_type=0)
cnt += 1

# message_type (1, 1, 1)
cnt = 0
for i in range(3, 5):
for j in range(3, 5):
if cnt >= num_edges_removed:
G.add_edge(i, j, edge_label=1, edge_type=1)
cnt += 1

return G


def generate_simple_dense_hete_multigraph(num_edges_removed=0):
# TODO: restrict value of num_edges_removed
G = nx.MultiDiGraph()

for i in range(3):
G.add_node(i, node_label=0, node_type=0)

for i in range(3, 5):
G.add_node(i, node_label=0, node_type=1)

# message_type (0, 0, 0)
cnt = 0
for i in range(3):
for j in range(3):
if cnt >= num_edges_removed:
for k in range(3):
G.add_edge(i, j, edge_label=1, edge_type=0)
cnt += 1

# message_type (1, 1, 1)
cnt = 0
for i in range(3, 5):
for j in range(3, 5):
if cnt >= num_edges_removed:
for k in range(3):
G.add_edge(i, j, edge_label=1, edge_type=1)
cnt += 1

return G


def generate_simple_small_hete_graph(directed=True):
if directed:
G = nx.DiGraph()
Expand Down

0 comments on commit 33e30f2

Please sign in to comment.