admin管理员组

文章数量:1122832

I am implementing a graph grammar using networkx that grows as it finds certain subgraphs, however, the above functions do not always work as expected. I found out that it depends not on the graphs and/or subgraphs themselves, but on the order in which the edges are arranged in the object. How can I solve this?

For example: a graph "initial" has:

    0:u
    1:u
    2:u
    3:u
    4:u
    5:u
    134:u
    135:u
    0:u 2:u
    2:u 4:u
    3:u 134:u
    3:u 135:u
    4:u 3:u
    5:u 135:u
    134:u 5:u
    135:u 1:u

When I apply two subgraphs: subg1 =


    1:*
    2:u
    0:*
    1:* 2:u
    2:u 0:*
    ```
[![enter image description here][2]][2]
    and 
    subg2 =
    ```
    1:*
    2:u
    0:*
    2:u 1:*
    0:* 2:u

The code is:


    GM = iso.DiGraphMatcher(initial, subg1, node_match=iso.generic_node_match('label', '@', initialpare_nodes) )
    res = list(GM.subgraph_monomorphisms_iter())
    print(res)

I can obtain:

[{2:u: 1:*, 4:u: 2:u, 3:u: 0:*},
 {134:u: 1:*, 5:u: 2:u, 135:u: 0:*},
 {3:u: 1:*, 134:u: 2:u, 5:u: 0:*},
 {3:u: 1:*, 135:u: 2:u, 1:u: 0:*},
 {5:u: 1:*, 135:u: 2:u, 1:u: 0:*},
 {4:u: 1:*, 3:u: 2:u, 134:u: 0:*},
 {4:u: 1:*, 3:u: 2:u, 135:u: 0:*}]

But, when I apply

GM = iso.DiGraphMatcher(initial, subg2, node_match=iso.generic_node_match('label', '@', initialpare_nodes) )
res = list(GM.subgraph_monomorphisms_iter())
print(res)

I obtain an empty list. Besides, I could not get {"0:u", "2:u", "4:u"} sequence.

本文标签: