Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Network Dismantling Framework

Python Version License: MIT

A comprehensive Python framework for network dismantling tasks, providing multiple network dismantling strategies, evaluation methods, and extensible architecture design.

NOTICE: All implementations are based on the paper's description and publicly available code, and there may be minor differences. If you have any corrections, optimizations, or improvements, please feel free to submit a PR.

Features

  • Modular Design: Flexible combination of selectors, operators, and evaluators
  • Multiple Algorithms: Support for various dismantling strategies from basic centrality to state-of-the-art deep learning
  • Spatial Network Support: Specialized algorithms for geographic/spatial networks with coordinate-based dismantling
  • Comprehensive Evaluation: Built-in metrics and strategies for performance assessment
  • Extensible Architecture: Easy to add custom algorithms and evaluation methods
  • Performance Optimized: Suitable for networks of different scales
  • PyTorch Integration: Support for neural network-based dismantling strategies (GAT, GNN, DQN)

Installation

From PyPI (Recommended)

pip install network-dismantling

From Source

git clone https://github.com/your-username/network-dismantling.git
cd network-dismantling
pip install -e .

Development Installation

git clone https://github.com/your-username/network-dismantling.git
cd network-dismantling
pip install -e .[dev]

Quick Start

Basic Usage

import networkx as nx
from network_dismantling import NetworkDismantler
from network_dismantling.node_selectors import GND
from network_dismantling.operators import NodeRemovalOperator
from network_dismantling.evaluators import DismantlingEvaluator, LCCSizeMetric, RelativeChangeStrategy

# Create a test network
G = nx.karate_club_graph()

# Create dismantler with GND selector and node removal operator
dismantler = NetworkDismantler(
    selector=GND(),
    operator=NodeRemovalOperator()
)

# Execute dismantling (remove 5 nodes)
dismantled_graph, removed_nodes = dismantler.dismantle(G, num_elements=5)

# Evaluate the result
evaluator = DismantlingEvaluator([LCCSizeMetric()], strategy=RelativeChangeStrategy())
results = evaluator.evaluate(G, dismantled_graph)
print(f"LCC size reduction: {results['LCC Size']*100:.2f}%")

Strategy Comparison

from network_dismantling.node_selectors import GND, CoreHD, Degree
from network_dismantling.evaluators import (
    DismantlingEvaluator, LCCSizeMetric, GlobalEfficiencyMetric,
    RelativeChangeStrategy
)

# Create multiple dismantling strategies
dismantlers = [
    NetworkDismantler(GND(), NodeRemovalOperator()),
    NetworkDismantler(CoreHD(), NodeRemovalOperator()),
    NetworkDismantler(Degree(), NodeRemovalOperator()),
]

# Set up evaluation
metrics = [LCCSizeMetric(), GlobalEfficiencyMetric()]
evaluator = DismantlingEvaluator(metrics, RelativeChangeStrategy())

# Compare strategies
results = DismantlingEvaluator.compare_strategies(
    G, dismantlers, num_nodes_to_remove=5, evaluator=evaluator
)

# Print results
for strategy, metrics in results.items():
    print(f"\n{strategy}:")
    for metric, value in metrics.items():
        print(f"  {metric}: {value:.2f}%")

Spatial Networks

For spatial networks with geographic coordinates:

import networkx as nx
from network_dismantling.spatial import GA_SNDHC, RegionCentralityRSD, SpatialUtils

# Create a spatial network with coordinates
G = nx.random_geometric_graph(200, 0.125)
# Nodes automatically have 'pos' attribute with (x, y) coordinates in [0, 1]

# Option 1: Genetic Algorithm with heterogeneous costs
selector = GA_SNDHC(
    num_circles=10,
    radius=0.02,
    cost_parameter_p=1.0,        # Cost: c_i = degree^p
    cost_constraint_alpha=0.5,    # Budget: 50% of total cost
    population_size=10,
    num_generations=1000
)
nodes_to_remove = selector.select(G, num_nodes=50)

# Option 2: Region Centrality (Sum of Degrees)
selector = RegionCentralityRSD(num_circles=10, radius=0.02, grid_size=100)
nodes_to_remove = selector.select(G, num_nodes=50)

Available Algorithms

Node Selectors

  • Basic Selectors: BruteForce (optimal for small networks), Random
  • Centrality-based: Degree, Betweenness, Closeness
  • Advanced Algorithms:
    • CoreHD - Core highest degree (2-core based, Zdeborová 2016)
    • GND/GNDR - Generalized network dismantling with spectral bisection (Ren 2019)
    • GDM/CoreGDM - Machine learning dismantling with GAT (Grassia 2021)
    • GASC_BA/GASC_CM - State-of-the-art GAT with shortcut connections (Hong 2025)
    • EntanglementCentrality/MultiscaleEntanglementCentrality - Physics-based functional dismantling (Ghavasieh 2023)
  • Influence-based: CollectiveInfluence, ExplosiveImmunization
  • Deep Learning:
    • FINDER - Deep Q-Network based reinforcement learning
    • GASC_BA - GAT with shortcut connections, trained on BA networks (fastest)
    • GASC_CM - GAT with shortcut connections, tailored to target network (most accurate)
  • Min-Sum Algorithm: MinSum - Three-stage message passing algorithm (Braunstein 2016)

Edge Selectors

  • Path Attack: PathAttackLP, PathAttackGreedy, NaiveEdgeCut, EigenScoreCut
  • Higher-Order Structure: BPDH, BPDH_Accurate - Targets k-cores and higher-order structures (Peng 2024)
  • Deep Learning: SHEAR - Deep Q-Network for edge removal

Spatial Network Selectors

For spatial networks with geographic coordinates (nodes have pos attribute):

  • Disintegration Circle Model - Tabu Search optimization for circle placement (Deng 2019)
  • Region Centrality:
    • RegionCentralityRSD - Recalculated Sum of Degrees (Wang 2021)
    • RegionCentralityRSE - Recalculated Sum of Edges (Wang 2021)
  • GA-SNDHC - Genetic Algorithm with heterogeneous cost constraints (Shen 2026)

Operators

  • Node Removal: Remove selected nodes and their connections
  • Edge Removal: Remove selected edges while preserving nodes

Evaluation Metrics

  • Connectivity: LCCSizeMetric, NumComponentsMetric
  • Efficiency: GlobalEfficiencyMetric, AvgPathLengthMetric
  • Structure: AvgClusteringMetric

Architecture

The framework follows a modular design with four main layers:

  1. Core Framework: Base classes and interfaces
  2. Selectors: Algorithms for choosing elements to remove
  3. Operators: Methods for executing removal operations
  4. Evaluators: Tools for measuring dismantling effectiveness
  5. Utils: Auxiliary tools and optimizations

For detailed architecture information, see ARCHITECTURE.md.

Performance Guidelines

Network Size Recommended Selectors Notes
< 100 nodes BruteForce Optimal solutions
100-10k nodes GND, CoreHD, MinSum Good balance of quality/speed
> 10k nodes Degree, CollectiveInfluence Fast execution
High quality needed GASC_BA, GASC_CM, GDM, MinSum State-of-the-art results
Deep learning applications GASC_BA, GASC_CM, FINDER Requires PyTorch
Physics-based / Functional EntanglementCentrality Based on information flow
Higher-order structures BPDH, BPDH_Accurate (edges) Eliminates k-cores, cliques
Spatial networks GA_SNDHC, RegionCentralityRSD/RSE Requires node coordinates

Examples

See the examples/ directory for comprehensive usage examples:

  • examples/nn.py: Basic usage and strategy comparison
  • examples/heuristic.py: Advanced algorithm demonstrations
  • examples/finder_demo.py: FINDER algorithm comprehensive demonstration
  • examples/min_sum_demo.py: MinSum algorithm usage and examples
  • examples/finder_vs_minsum_comparison.py: Head-to-head comparison of FINDER and MinSum
  • examples/langchain_llm.ipynb: Integration with machine learning

For detailed algorithm documentation, see:

  • docs/FINDER_MINSUM_GUIDE.md: Comprehensive guide to FINDER and MinSum algorithms

API Reference

Core Classes

# Main dismantling interface
NetworkDismantler(selector, operator)

# Strategy comparison
DismantlingEvaluator.compare_strategies(graph, dismantlers, num_elements, evaluator)

Extension Points

# Custom selector
class MySelector(ElementSelector):
    def select(self, G, num_elements):
        # Your algorithm here
        return selected_elements

# Custom metric  
class MyMetric(EvaluationMetric):
    def compute(self, G):
        # Your metric calculation
        return metric_value

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

git clone https://github.com/your-username/network-dismantling.git
cd network-dismantling
pip install -e .[dev]

Running Tests

pytest tests/

Code Style

We use Black for code formatting:

black network_dismantling/

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this framework in your research, please cite:

@software{network_dismantling_framework,
  title={Network Dismantling Framework},
  author={Command Mao},
  year={2025},
  url={https://github.com/c0mm4nd/network-dismantling}
}

Maintainers

c0mm4nd ChatGPT Claude Copilot ...

Changelog

See CHANGELOG.md for version history and updates.

Support

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages