python - Diameter computation in igraph -
i'm new python , igraph , wish simulate targeted attack network. specifically, given directed graph g, want progressively delete vertices g according in-degree.
function takes input list (vertices_to_delete) of vertices delete g plus graph g. creates copy of g, deletes g vertices in vertices_to_delete , computes, on new instance of g, size of wcc , diameter of new graph. such process repeated different instances of vertices_to_delete (thus @ each iteration re-compute size of wcc , diameter).
i report code below. results wcc in line expectations while values of d quite weird (i expect d increases no clear pattern emerges). i've tried code on dataset extracted wikipedia (wiki-vote - https://snap.stanford.edu/data/wiki-vote.html). think i'm not using correct function computing diameter , depend on fact g directed.
thanks lot kind , developers/contributors of igraph wonderful package!
def attack(graph, vertices_to_delete): gc = graph.copy() gc.delete_vertices(vertices_to_delete) largest_connected_component = gc.clusters(mode = weak).giant() wcc_size=largest_connected_component.vcount() diameter = gc.diameter() return wcc_size, diameter
Comments
Post a Comment