Attacks

class graph_tiger.attacks.Attack(graph, runs=10, steps=50, attack='id_node', defense=None, k_d=0, **kwargs)

Bases: Simulation

This class simulates a variety of attack strategies on an undirected NetworkX graph

Parameters
  • graph – an undirected NetworkX graph

  • runs – an integer number of times to run the simulation

  • steps – an integer number of steps to run a single simulation

  • attack – a string representing the attack strategy to run

  • defense – a string representing the defense strategy to run

  • k_d – an integer number of nodes to defend

  • **kwargs

    see parent class Simulation for additional options

reset_simulation()

Resets the simulation between each run

run_single_sim()

Run the attack simulation

track_simulation(step)

Keeps track of important simulation information at each step of the simulation

Parameters

step – current simulation iteration

graph_tiger.attacks.get_attack_category(method)

Gets the attack category e.g., ‘node’, ‘edge’ attack

Parameters

method – a string representing the attack method

Returns

a string representing the attack type (‘node’ or ‘edge’)

graph_tiger.attacks.get_attack_methods()

Gets a list of available attach methods as a list of functions

Returns

a list of all attack functions

graph_tiger.attacks.get_edge_ib(graph, k=3, approx=inf)

Get k edges to attack based on Initial Betweenness (IB) Removal [14].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

  • approx – number of edges to approximate the betweenness centrality

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_id(graph, k=3)

Get k edges to attack based on Initial Degree (ID) Removal [14].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_line_deg(graph, k=3)

Get k edges to attack using degree centrality by transforming the graph into a line graph [18].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_line_eig(graph, k=3)

Get k edges to attack using eigenvector centrality by transforming the graph into a line graph [18].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_line_ns(graph, k=3)

Get k edges to attack using Netshield by transforming the graph into a line graph [18, 19]

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_line_pr(graph, k=3)

Get k edges to attack using PageRank by transforming the graph into a line graph [18].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_rb(graph, k=3, approx=inf)

Get k edges to attack based on Recalculated Betweenness (RB) Removal [14].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

  • approx – number of edges to approximate the betweenness centrality

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_rd(graph, k=3)

Get k edges to attack based on Recalculated Degree (RD) Removal [14].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_edge_rnd(graph, k=3)

Randomly select k edges to attack

Parameters
  • graph – an undirected NetworkX graph

  • k – number of edges to attack

Returns

a list of edge tuples to attack

graph_tiger.attacks.get_node_eig(graph, k=3)

Get k nodes to attack based on top eigenvector centrality entries

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

Returns

a list of nodes to attack

graph_tiger.attacks.get_node_ib(graph, k=3, approx=inf)

Get k nodes to attack based on Initial Betweenness (IB) Removal [2].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

  • approx – number of nodes to approximate the betweenness centrality, k=0.1n is a good approximation, where n

is the number of nodes in the graph

Returns

a list of nodes to attack

graph_tiger.attacks.get_node_id(graph, k=3)

Get k nodes to attack based on Initial Degree (ID) Removal [2].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

Returns

a list of nodes to attack

graph_tiger.attacks.get_node_ns(graph, k=3)

Get k nodes to attack based on the Netshield algorithm :cite`tong2010vulnerability`.

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

Returns

a list of nodes to attack

graph_tiger.attacks.get_node_pr(graph, k=3)

Get k nodes to attack based on top PageRank entries :cite`page1999pagerank`.

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

Returns

a list of nodes to attack

graph_tiger.attacks.get_node_rb(graph, k=3, approx=inf)

Get k nodes to attack based on Recalculated Betweenness (RB) Removal [2].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

  • approx – number of nodes to approximate the betweenness centrality, k=0.1n is a good approximation, where n

is the number of nodes in the graph

Returns

a list of nodes to attack

graph_tiger.attacks.get_node_rd(graph, k=3)

Get k nodes to attack based on Recalculated Degree (RD) Removal [2].

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

Returns

a list of nodes to attack

graph_tiger.attacks.get_node_rnd(graph, k=3)

Randomly select k distinct nodes to attack

Parameters
  • graph – an undirected NetworkX graph

  • k – number of nodes to attack

Returns

a list of nodes to attack

graph_tiger.attacks.main()
graph_tiger.attacks.run_attack_method(graph, method, k=3, approx=None, seed=None)

Runs a specified attack on an undirected graph, returning a list of nodes to attack

Parameters
  • graph – an undirected NetworkX graph

  • method – a string representing one of the attack methods

  • k – number of nodes or edges to attack

  • approx – attack approximation parameter (not available for every measure)

  • seed – sets the seed in order to obtain reproducible attacks

Returns

a list of nodes selected for attack