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.
- 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)
pip install network-dismantlinggit clone https://github.com/your-username/network-dismantling.git
cd network-dismantling
pip install -e .git clone https://github.com/your-username/network-dismantling.git
cd network-dismantling
pip install -e .[dev]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}%")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}%")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)- 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 learningGASC_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)
- 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
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)
- Node Removal: Remove selected nodes and their connections
- Edge Removal: Remove selected edges while preserving nodes
- Connectivity:
LCCSizeMetric,NumComponentsMetric - Efficiency:
GlobalEfficiencyMetric,AvgPathLengthMetric - Structure:
AvgClusteringMetric
The framework follows a modular design with four main layers:
- Core Framework: Base classes and interfaces
- Selectors: Algorithms for choosing elements to remove
- Operators: Methods for executing removal operations
- Evaluators: Tools for measuring dismantling effectiveness
- Utils: Auxiliary tools and optimizations
For detailed architecture information, see ARCHITECTURE.md.
| 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 |
See the examples/ directory for comprehensive usage examples:
examples/nn.py: Basic usage and strategy comparisonexamples/heuristic.py: Advanced algorithm demonstrationsexamples/finder_demo.py: FINDER algorithm comprehensive demonstrationexamples/min_sum_demo.py: MinSum algorithm usage and examplesexamples/finder_vs_minsum_comparison.py: Head-to-head comparison of FINDER and MinSumexamples/langchain_llm.ipynb: Integration with machine learning
For detailed algorithm documentation, see:
docs/FINDER_MINSUM_GUIDE.md: Comprehensive guide to FINDER and MinSum algorithms
# Main dismantling interface
NetworkDismantler(selector, operator)
# Strategy comparison
DismantlingEvaluator.compare_strategies(graph, dismantlers, num_elements, evaluator)# 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_valueWe welcome contributions! Please see our Contributing Guidelines for details.
git clone https://github.com/your-username/network-dismantling.git
cd network-dismantling
pip install -e .[dev]pytest tests/We use Black for code formatting:
black network_dismantling/This project is licensed under the MIT License - see the LICENSE file for details.
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}
}See CHANGELOG.md for version history and updates.
- Documentation: Full documentation
- Issues: GitHub Issues
- Discussions: GitHub Discussions