Skip to content

Commit

Permalink
Added option to Edge weight the graph when splitting
Browse files Browse the repository at this point in the history
Including this line of code will split the graph using edge weighting

G.graph['edge_weight_attr'] = 'weight'
  • Loading branch information
pjuangph committed Jun 20, 2024
1 parent fb821f3 commit 9fafb85
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 9,268 deletions.
4 changes: 2 additions & 2 deletions python/examples/metis-block-graph/block_to_graph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def view_pydot(pdot):

import metis
G = read_data()['Graph']
G.graph['node_weight_attr'] = ['weights']

G.graph['node_weight_attr'] = ['weight']
G.graph['edge_weight_attr'] = 'weight'
(edgecuts, parts) = metis.part_graph(G, 2,tpwgts=[0.5,0.5])

colors = ['red','blue','green','magenta']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ def view_pydot(pdot):
face_matches = glennht_to_con('kenji_diced_1.p3d_conn')
max_block_index = [(f['block1']['block_index'], f['block2']['block_index']) for f in face_matches]
max_block_index = np.max(np.array(max_block_index).flatten())
block_sizes = [(np.random.randint(33,101), np.random.randint(33,101), np.random.randint(33,101)) for _ in range(max_block_index)]
block_sizes = [(np.random.randint(33,101)*np.random.randint(33,101)*np.random.randint(33,101)) for _ in range(max_block_index)]
G = block_connectivity_to_graph(face_matches,block_sizes)

#%% Split the Graph
import metis
G.graph['node_weight_attr'] = ['weight']
G.graph['edge_weight_attr'] = 'weight'
nparts = 3
(edgecuts, parts) = metis.part_graph(G, nparts,tpwgts=[0.3,0.3,0.4])
nodes_per_part = list()
Expand All @@ -29,7 +30,7 @@ def view_pydot(pdot):
indexes = [p for p, e in enumerate(parts) if e == i]
nodes = 0
for idx in indexes:
nodes += block_sizes[idx-1][0]*block_sizes[idx-1][1]*block_sizes[idx-1][2]
nodes += block_sizes[idx-1]
nodes_per_part.append(nodes)

#%% Plotting
Expand Down
Loading

0 comments on commit 9fafb85

Please sign in to comment.