You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently using the subgraph_isomorphism function to find isomorphic subgraphs in a host graph. However, the current isos array returned only includes the vertex IDs from the host graph without providing a mapping to the IDs of the subgraph. This makes it challenging to reconstruct the subgraph using the host graph IDs.
Here is the code illustrating the current behavior:
With help from Oliver, I created a function that maps the subgraph IDs to the host graph IDs based on the isos output, allowing me to recreate the subgraph. Here's a concise explanation of the provided code:
The function first checks if the length of the isos array is a multiple of the number of subgraph nodes. It then iterates through each isomorphic subgraph found, creating a mapping from the subgraph node IDs to the corresponding host graph node IDs. Finally, it reconstructs the subgraph edges using the host graph node IDs.
Here's the complete code:
import arkouda as ak
import arachne as ar
ak.connect()
# Define the host graph
G = ar.PropGraph()
src_host = [1, 2, 3, 2]
dst_host = [2, 3, 4, 7]
G.add_edges_from(ak.array(src_host), ak.array(dst_host))
# Define the subgraph
subgraph = ar.PropGraph()
src_sub = [10, 20, 30, 20]
dst_sub = [20, 30, 40, 70]
subgraph.add_edges_from(ak.array(src_sub), ak.array(dst_sub))
# Find isomorphic subgraphs
isos = ar.subgraph_isomorphism(G, subgraph)
print(f"Isomorphisms found: {isos}")
isos_ndarray = isos.to_ndarray() # Convert pdarray to ndarray
# Check if the length of isomorphisms is a multiple of the number of subgraph nodes
if len(isos) % len(subgraph) != 0:
raise ValueError("The length of isomorphisms is not a multiple of the number of subgraph nodes.")
subgraph_nodes=[]
host_graph_nodes=[]
node_mapping={}
number_isos_found= len(isos)/len(subgraph)
for i in range(0,int(number_isos_found)):
# Create a mapping from subgraph nodes to host graph nodes
subgraph_nodes = sorted(list(set(src_sub + dst_sub)))
host_graph_nodes = isos_ndarray[i*len(subgraph_nodes):i*len(subgraph_nodes) + len(subgraph_nodes)]
node_mapping = dict(zip(subgraph_nodes, host_graph_nodes))
print("Mapping:", node_mapping)
# Recreate the subgraph with host graph node IDs
mapped_src_sub = [node_mapping[node] for node in src_sub]
mapped_dst_sub = [node_mapping[node] for node in dst_sub]
# Output the mapped subgraph edges
print("Mapped subgraph edges (using host graph node IDs):")
for s, d in zip(mapped_src_sub, mapped_dst_sub):
print(f"{s} -> {d}")
I hope this helps to implement a mapping feature directly into the library!
The text was updated successfully, but these errors were encountered:
michaelfekadu
changed the title
Mapping of subgraph nodes to host graph nodes
Feature Request: Add Subgraph Node ID Mapping in subgraph_isomorphism Output
Jul 2, 2024
Hi!
I'm currently using the
subgraph_isomorphism
function to find isomorphic subgraphs in a host graph. However, the currentisos
array returned only includes the vertex IDs from the host graph without providing a mapping to the IDs of the subgraph. This makes it challenging to reconstruct the subgraph using the host graph IDs.Here is the code illustrating the current behavior:
The output I get is:
With help from Oliver, I created a function that maps the subgraph IDs to the host graph IDs based on the isos output, allowing me to recreate the subgraph. Here's a concise explanation of the provided code:
The function first checks if the length of the isos array is a multiple of the number of subgraph nodes. It then iterates through each isomorphic subgraph found, creating a mapping from the subgraph node IDs to the corresponding host graph node IDs. Finally, it reconstructs the subgraph edges using the host graph node IDs.
Here's the complete code:
The output I get is:
I hope this helps to implement a mapping feature directly into the library!
The text was updated successfully, but these errors were encountered: