Thanks for your help. But I was still confused by the graph filter. My aim
is to to remove the nodes that don't belong to largest component of
subnetwork consisted of type A nodes while the corresponding type B nodes
are remained in the graph. I wrote the script like this,
p = 0.02
G = gt.load_graph(File)
pos = G.vertex_properties['pos']
v_type = G.vertex_properties['v_type']
e_type = G.edge_properties['e_type']
exist = G.new_vertex_property('bool')
G.vertex_properties['exsit'] = exist
exist.a = True
for v in G.vertices():
if v_type[v]:
if np.random() < p:
exist[v] =False
for n in v.all_neighbours():
if not v_type[n]:
exist[n] = False
G.set_vertex_filter(prop=exist)
G.purge_vertices()
pos = G.vertex_properties['pos']
v_type = G.vertex_properties['v_type']
exist = G.vertex_properties['tag']
gt.graph_draw(G, pos=pos)
# step 1 largest component in network A
UA = gt.GraphView(G, vfilt=v_type)
LCA = gt.label_largest_component(UA)
exist.a = False
for v in G.vertices():
if LCA[v]:
exist[v] = True
for n in v.all_neighbours():
if not v_type[n]:
exist[v] = True
G.set_vertex_filter(exist)
line 56: G.purge_vertices()
Console warns that ,
Traceback (most recent call last):
File "/home/lockheed/PycharmProjects/cascade_failures/MAIN.py", line 56,
in <module>
G.purge_vertices()
File "/usr/lib/python2.7/dist-packages/graph_tool/__init__.py", line
1867, in purge_vertices
new_g = Graph(self, prune=(True, False, False))
File "/usr/lib/python2.7/dist-packages/graph_tool/__init__.py", line
1133, in __init__
_prop("v", gv, vorder))
ValueError: Cannot find property map type.
Very appreciate for your help.
best,
Liu
在 2014年4月29日星期二UTC+8下午5时02分02秒,Giuseppe Profiti写道:
>
> Hello Liu,
> there is an example code of what you are looking for in the
> "label_largest_component" documentation:
>
> http://graph-tool.skewed.de/static/doc/topology.html#graph_tool.topology.label_largest_component
>
> Best,
> Giuseppe
>
> 2014-04-29 9:15 GMT+02:00 Liu <[email protected] <javascript:>>:
>
>> Hi,
>>
>> I have tried to simulate the phenomenen of cascading failures in
>> interdependent networks. But I can't remove the nodes that don't belong to
>> the largest component. Is there any simple solution for this task?
>>
>> Best,
>> Liu
>>
>> _______________________________________________
>> graph-tool mailing list
>> [email protected] <javascript:>
>> http://lists.skewed.de/mailman/listinfo/graph-tool
>>
>>
>_______________________________________________
graph-tool mailing list
[email protected]
http://lists.skewed.de/mailman/listinfo/graph-tool