Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can kahypar give the hyperedges those are cut after partition? #194

Closed
RoyIronGrey opened this issue Dec 5, 2023 · 4 comments
Closed

Can kahypar give the hyperedges those are cut after partition? #194

RoyIronGrey opened this issue Dec 5, 2023 · 4 comments

Comments

@RoyIronGrey
Copy link

e.x., when I execute the python/tests/test_kahypar.py, I can get the block of each node belonging. Can I get the hyperedges those are cut from any function. I coded a function to do that, but it is inefficient.

def get_cut_hyperedges(result, hyperedge_indices, hyperedge):
    cut_hyperedges = []
    for i in range(len(hyperedge_indices) - 1):
        start_idx = hyperedge_indices[i]
        end_idx = hyperedge_indices[i+1]
        hyperedge_nodes = hyperedge[start_idx:end_idx]
        part_set = set()
        for part_idx, part_nodes in enumerate(result):
            if any(node in part_nodes for node in hyperedge_nodes):
                part_set.add(part_idx)
        if len(part_set) > 1:
            cut_hyperedges.append(hyperedge[start_idx:end_idx])
    return cut_hyperedges

# test-case
hyperedge_indices = [0, 4, 6, 7, 10, 12, 13, 16, 18, 19, 22, 25, 29]
hyperedge = [2, 5, 9, 10, 4, 9, 3, 7, 9, 10, 6, 7, 2, 1, 3, 8, 2, 5, 7, 4, 9, 10, 1, 2, 3, 1, 2, 5, 8]
result = [[1, 2, 3, 5, 8, 12], [4, 6, 7, 9, 10, 11]]
cut_hyperedges = get_cut_hyperedges(result, hyperedge_indices, hyperedge)
print("Cut Hyperedges:", cut_hyperedges) 
@SebastianSchlag
Copy link
Member

Hi @RoyIronGrey,
thanks for reaching out.

Yes, this is possible via:

for e in hypergraph.edges():
	if hypergraph.connectivity(e) > 1:
		print (f"cut edge: {e}")

The entire interface available and (somewhat poorly) documented here: https://github.com/kahypar/kahypar/blob/master/python/module.cpp

@RoyIronGrey
Copy link
Author

Hi @RoyIronGrey, thanks for reaching out.

Yes, this is possible via:

for e in hypergraph.edges():
	if hypergraph.connectivity(e) > 1:
		print (f"cut edge: {e}")

The entire interface available and (somewhat poorly) documented here: https://github.com/kahypar/kahypar/blob/master/python/module.cpp

Thanks for your reply. The e in hypergraph.edges() I got is a integer, but the hyperedge should include mutil nodes, right? I am a bit confused.

@N-Maas
Copy link
Collaborator

N-Maas commented Dec 5, 2023

Thanks for your reply. The e in hypergraph.edges() I got is a integer, but the hyperedge should include mutil nodes, right? I am a bit confused.

hypergraph.edges() returns the IDs of the hyperedges. You can retrieve the included nodes of the hyperedge (which are called the pins of the hyperedge) via hypergraph.pins(e).

@RoyIronGrey
Copy link
Author

Thanks for your reply. The e in hypergraph.edges() I got is a integer, but the hyperedge should include mutil nodes, right? I am a bit confused.

hypergraph.edges() returns the IDs of the hyperedges. You can retrieve the included nodes of the hyperedge (which are called the pins of the hyperedge) via hypergraph.pins(e).

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@SebastianSchlag @RoyIronGrey @N-Maas and others