Hi,

Here's an example:

Imaging your subgraph (let's call it sub. save it in a file called sub.gml)
looks like this in .gml format:

graph [
   directed 1
   node [
      id 0
      name "a"
      status "down"
   ]
   node [
      id 1
      name "b"
      status "up"
   ]
]

And your larger graph (let's call it g. save it in a file called g.gml)
looks like this:

graph [
   directed 1
   node [
      id 0
      name "a"
      status "up"
   ]
   node [
      id 1
      name "b"
      status "up"
   ]
      node [
      id 0
      name "a"
      status "down"
   ]
   node [
      id 1
      name "b"
      status "up"
   ]
   node [
      id 4
      name "c"
      status "down"
   ]
]

When you load your graphs, the properties load in the graphs' property maps
(you can retrieve them with g.vertex_properties['status'] for example).
Here's 2 ways you can find subgraphs that are isomorphic:

vertex_mapping_name, edge_mapping_name=gt.subgraph_isomorphism(sub, g,
vertex_label=(sub.vertex_properties["name"],g.vertex_properties["name"]),random=True)
vertex_mapping_status, edge_mapping_status=gt.subgraph_isomorphism(sub, g,
vertex_label=(sub.vertex_properties["status"],g.vertex_properties["status"]),random=True)
      
If I have multiple criteria, I perform an intersection of sorts after the
fact. I'm not sure if there's a better way to use different labels at the
same time.

I've pasted the python code below.

Hope that helps!

Reem

import graph_tool.all as gt

g = gt.load_graph("./g.gml")
sub = gt.load_graph("./sub.gml")

vertex_mapping_name, edge_mapping_name=gt.subgraph_isomorphism(sub, g,
vertex_label=(sub.vertex_properties["name"],g.vertex_properties["name"]),random=True)
vertex_mapping_status, edge_mapping_status=gt.subgraph_isomorphism(sub, g,
vertex_label=(sub.vertex_properties["status"],g.vertex_properties["status"]),random=True)

print(len(vertex_mapping_name))
print(len(vertex_mapping_status))



--
View this message in context: 
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/vertex-label-and-edge-label-in-subgraph-isomorphism-tp4025587p4025670.html
Sent from the Main discussion list for the graph-tool project mailing list 
archive at Nabble.com.
_______________________________________________
graph-tool mailing list
[email protected]
http://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to