The impact of random attacks on an exponential complex network

I have been attempting to replicate a random attack on an Erdos-Renyi network. The expected outcome is for the network to collapse after removing approximately 20 to 30% of the nodes. However, my results differ as the size of the giant connected component appears to decrease linearly.

import networkx as nx
import random as rd

def simulate_random_attack():
    network = nx.fast_gnp_random_graph(1000, 0.01)
    nodes = []
    gcc = []
    total_nodes = network.number_of_nodes()
    removed_nodes = 0

    gcc_size = len(list(max(nx.connected_components(network), key=len))) / total_nodes
    gcc.append(gcc_size)
    nodes.append(0.0)

    while network.number_of_nodes() > 1:

        node = rd.choice(list(network.nodes()))
        network.remove_node(node)
        removed_nodes += 1

        gcc_size = len(list(max(nx.connected_components(network), key=len))) / total_nodes
        gcc.append(gcc_size)
        nodes.append(1 - ((total_nodes - removed_nodes) / total_nodes))

    fig, ax = plt.subplots()
    ax.plot(nodes, gcc)


Expected outcome:

https://i.stack.imgur.com/7A3fi.png

My results:

https://i.stack.imgur.com/hPn9N.png

Answer №1

Looking at the Expected outcome image, it appears that both the failure scenario and attack scenario yield identical results, which is somewhat peculiar. Typically, in actual scenarios, the impact of random attacks on a network is relatively gradual. Personally, I don't believe your findings are incorrect.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered CSRF validation error while working with a Python Django backend in conjunction with React frontend using Axios for making POST requests

I recently completed a tutorial at and now I'm attempting to add a POST functionality to it. Despite obtaining the csrf from cookies and including it in the "csrfmiddlewaretoken" variable alongside a test message in json format for the axios function ...

Button click event is not being triggered by Ajax rendering

I am facing an issue with my Django template that showcases scheduled classes for our training department. Each item in the list has a roster button which, when clicked, should display the class roster in a div. This functionality works perfectly. However, ...

Error message stating that there is no property 'collection' in Firestore when using Firebase v9 modular syntax in Firebase Firestore

Working on a React application that makes use of Firebase Firestore for handling database operations, I recently upgraded to Firebase version 9 and adopted the modular syntax for importing Firebase services. Nevertheless, when attempting to utilize the co ...

Exploring the capabilities of arrays within Ajax

Below is the original code I wrote in JavaScript: var wt_val = []; for (i = 0; i<human_wt.length; i++){ var mult; mult = data_list[basket_list[button_port_name][i]].map(x => x*(wt[i]/100)); wt_val.push(mult); ...

Invoke a Python function from JavaScript

As I ask this question, I acknowledge that it may have been asked many times before. If I missed the answers due to my ignorance, I apologize. I have a hosting plan that restricts me from installing Django, which provided a convenient way to set up a REST ...

What's the best way to determine which of the two forms has been submitted in Django?

On my homepage, I have both a log_in and sign_up form. Initially, the log_in form is displayed by default, but when a user clicks on the Sign Up button, the sign_up form appears. These toggles switch depending on which button the user clicks. from django ...

Executing a JavaScript code in a Python webdriver: A step-by-step guide

Using Selenium 2 Python webdriver: I encountered an issue where I needed to click on a hidden element due to a hover effect. In search of solutions to unhide and select the element, I came across the following examples: Example in Java: JavascriptExecut ...

Learn how to retrieve values from a .json file in real-time and then perform comparisons with user input using Python

I have a JSON file structured like this: [ { "name": { "common": "Aruba", "official": "Aruba", "native": { "nld": { "official ...

Flask does not provide a direct boolean value for checkboxes

After struggling for a week, I am still lost on where to make changes in my code. I need the checkbox to return a boolean value in my Flask application. Below are snippets of the relevant code: mycode.py import os, sqlite3 from flask import Flask, flash ...