def main(): graph_path = sys.argv[1] source_path = sys.argv[2] graph = read_edgelist(graph_path, create_using=DiGraph(), nodetype=int) sources = read_source(source_path) #Part 1: diffusion phase #lt_model(graph) infected = ic_model.ic_model_ori(graph, sources, 0.8) ratio = (float)(len(infected))/graph.number_of_nodes() print ratio #Part 2: block phase block = block_graph.degree_block(graph, sources) #block = greedy_block.greedy_block(graph, sources) new_graph = graph for i in range(5): for b in block[(int)(i*0.2*len(block)):(int)((i+1)*0.2*len(block))]: new_graph.remove_node(b) infected = ic_model.ic_model_ori(new_graph, sources, 0.8) ratio = (float)(len(infected))/graph.number_of_nodes() print ratio
def greedy_block (graph, sources): block_nodes= [] new_graph = graph.copy() temp_node=0 while len(block_nodes) < (int)(graph.number_of_nodes()*0.05): curr = len(ic_model.ic_model_ori(new_graph, sources, 0.8)) for i in new_graph: if sources.count(i)==0: temp_graph = new_graph.copy() temp_graph.remove_node(i) temp = ic_model.ic_model_inc(temp_graph, sources, 0.8, curr) if temp < curr: curr = temp temp_node = i block_nodes.append(temp_node) print len(block_nodes) new_graph.remove_node(temp_node) temp_node=0 return block_nodes