Skip to main content

A high-performance Python solver for Critical Node Problems

Project description

PyCNP: An Open-Source Python Package for Critical Node Detection Problems

PyPI version CI Documentation

PyCNP is an open-source, high-performance Python solver for the Critical Node Problem (CNP) and Distance-based Critical Node Problem (DCNP).

The Critical Node Problem asks: which nodes should be removed from a network to minimize its connectivity while respecting a budget constraint? This problem has applications in:

  • Network security - Identifying critical infrastructure nodes whose removal would most disrupt a network
  • Epidemiology - Modeling disease spread by removing highly connected individuals (vaccination strategies)
  • Social network analysis - Understanding information flow by identifying influential nodes
  • Biological networks - Identifying critical proteins or genes in protein-protein interaction networks

PyCNP currently supports:

  • Critical Node Problem (CNP) - Minimize pairwise connectivity in undirected graphs
  • Distance-based Critical Node Problem (DCNP) - CNP variant with hop distance constraints
  • Multiple search strategies - CBNS, CHNS, DLAS, and BCLS
  • Multiple crossover operators - DBX, IRR, and RSC

The package provides a flexible Python interface backed by efficient C++ implementations.

Installation

PyCNP can be installed via pip:

pip install pycnp

To install the latest version from source:

pip install 'pycnp @ git+https://github.com/xuebo100/PyCNP'

For development installation:

git clone https://github.com/xuebo100/PyCNP.git
cd PyCNP
pip install -e .

See the installation guide for detailed requirements and instructions.

Quick Start

import pycnp

# Create a model and add nodes/edges
model = pycnp.Model()
for i in range(10):
    model.add_node(i)
model.add_edge(0, 1)
model.add_edge(1, 2)
model.add_edge(2, 3)

# Solve the problem
result = model.solve(
    problem_type="CNP",
    budget=3,
    stopping_criterion=pycnp.MaxRuntime(60),
    seed=42
)

print(f"Best solution: {result.best_solution}")
print(f"Objective value: {result.best_obj_value}")

See the examples for a more comprehensive introduction.

Key Features

Problem Types

  • CNP (Critical Node Problem): The standard CNP on undirected graphs. The objective is to minimize pairwise connectivity by removing at most budget nodes.
  • DCNP (Distance-based Critical Node Problem): An extension that introduces a hop distance constraint. Two nodes are only considered connected if they are within the specified hop_distance of each other.

Search Strategies

Strategy Description Best For
CBNS Component-Based Neighborhood Search General CNP instances
CHNS Component-Based Hybrid Neighborhood Search Balance of quality and speed
DLAS Diversified Late Acceptance Search When diversification is important
BCLS Betweenness Centrality-based Late Acceptance Search DCNP problems

Crossover Operators or Problem Reduction

Operator Parents Description
DBX 2 Double Backbone Based Crossover - preserves common nodes between parents
IRR 3 Inherit-Repair-Recombination - designed for DCNP
RSC 2 Reduce-Solve-Combine - can be used for both CNP and DCNP

Stopping Criteria

  • MaxIterations - Stop after a fixed number of iterations
  • MaxRuntime - Stop after a specified amount of time (seconds)
  • NoImprovement - Stop if no improving solution is found

Documentation

The full documentation is available at https://xuebo100.github.io/PyCNP/.

Key resources:

Getting Help

If you have questions or need help:

  1. Browse discussions
  2. Open a new discussion thread for questions
  3. Open a bug report for issues

When reporting bugs, please include:

  • A minimal, reproducible example
  • PyCNP version (run python -c 'import pycnp; print(pycnp.__version__)')
  • Python version and operating system
  • Any error messages or tracebacks

Contributing

Contributions are welcome! Please see our contributing guide for details.

Before starting, please discuss changes in a GitHub issue first.

How to Cite PyCNP

If you use PyCNP in your research, please cite the relevant papers:

@article{pycnp2026,
  title={PyCNP: An Open-Source Python Package for Critical Node Detection Problems},
  author={Yangming Zhou and Bo Xue and MengChu Zhou and Tieju Ma},
  year={2026},
}

License

PyCNP is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycnp-0.1.4.tar.gz (865.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycnp-0.1.4-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

pycnp-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (439.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pycnp-0.1.4-cp313-cp313-macosx_11_0_arm64.whl (381.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pycnp-0.1.4-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

pycnp-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (439.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pycnp-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (380.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pycnp-0.1.4-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11Windows x86-64

pycnp-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (436.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pycnp-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (379.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pycnp-0.1.4-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

pycnp-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (434.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pycnp-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (376.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pycnp-0.1.4-cp39-cp39-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9Windows x86-64

pycnp-0.1.4-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (434.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pycnp-0.1.4-cp39-cp39-macosx_11_0_arm64.whl (376.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file pycnp-0.1.4.tar.gz.

File metadata

  • Download URL: pycnp-0.1.4.tar.gz
  • Upload date:
  • Size: 865.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycnp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ac9a0b95c4f54a48273191b619c51635a77a677dafec4da7f084defc1a33eb63
MD5 b4c4579ab5167674db47224679038b04
BLAKE2b-256 1816776fafbe4695bf556197a6cb8d6d8b8a44296b7f01407720d570a65f9ef1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4.tar.gz:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pycnp-0.1.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycnp-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 351c6a925b9a331eecb3655838fcce7e57698348218e25e7202ccd8350a334cd
MD5 da3d3023bd13f9ce7f12b555099f0e4c
BLAKE2b-256 0c074392ab5686303cf4d1dbb875d9e2c75d62887802c1c1b7f5b0010c2678a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp313-cp313-win_amd64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9818795b3ad995b304ff7f3efce0aa0e667646b733668207b24a4630c3743de9
MD5 b8ecdcb5d3505bd04ce817ba1e996116
BLAKE2b-256 f37cd816bb5d5a1932b77357737c6dbdaa0b229049c83aac73d5a5bce9ba97d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f0a46ecdfb64aa36b55cb296497dc39def295d63939189b238d94656abd81dd5
MD5 8632dcceb853f29a89cc4736c862648d
BLAKE2b-256 d918922b61128f3d3911f2c7bfca80f7786116a5ba320d675f7bd7c235fed511

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pycnp-0.1.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycnp-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 75acd8824ee6a075227c35264da07c3917f1313490b5d64faa96881671bc0be0
MD5 7384bfcf692008fc2b4619170c585a83
BLAKE2b-256 87cee902318fd5af32158c577b1cc5567ee94024cb92c639be66378b0733de66

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 baa26c5db56986dd36e5b3b1cb1ee263bd2909be90d88e2e6caae774f6a74a72
MD5 dd8ce2d8ed530f42c21af83f01221a8f
BLAKE2b-256 10e53042920cceb06f215ee8ba827ff103b9d3c82b011c66869c1783e8334bc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c3a61329d8b4f4f22ed2c17085c4f31a64c5588eca80e07988dedbb4907524b
MD5 890847ecf93bbb34681cff2eec5b41e8
BLAKE2b-256 f7495d9f4b5be06c3e5d780fe262219bc13c31608a02357058015649eab18ac1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pycnp-0.1.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycnp-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cc2cc584c65e1fd3947a66876ff421d834356b307ebe88e36a5536ba0cdc74fe
MD5 a23b81e4a21c6d60d24acff8089173d3
BLAKE2b-256 6668f8307622839406284f6643fda03c45bed468ad3584f0e90b93756c12a881

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad0f95730757ad70d37d5aba1a1702cf4acf3409473ad7d87b778d46f8b0236b
MD5 5138504668024bf61330438d158ce963
BLAKE2b-256 28348d699f14df5d1c8fa44a06ca971ea848fe6c998f093f97066fee6d13426f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16d8ad76918e9d0fec6792b48309530b60b08b514b05a6e12db447be45cf66df
MD5 27a7905bb2e818927eead720096b606d
BLAKE2b-256 9ea75904c701332029fd8a5574f559513e84c7575d16469ac625cec6d410e86e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pycnp-0.1.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycnp-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 56c95f5f23c5f0c39b94cc36e12002332b624d8b929419ce6dbf3a38a4afb1de
MD5 37d199cc18be423a4de9f68d01cec529
BLAKE2b-256 14c0d7768bccce2b1fdf36f83571eebf90d46d0e55a872162f994652fd367b14

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0862707fbf65e9e0c31daf946a19111f8c0218a8b7a8df2ccc6720199194405b
MD5 e6130c570472aa571f176fe806e051bb
BLAKE2b-256 4b11b720e097feae652b921dc82885679c22c1c71071fc9e113a8b4646e5c3d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6737cf0dcef94ec8e1a59394b710759ba6015b693312b1b5a8b1123a717c5a5d
MD5 47f7ef66145a3d6f0b9a2d509198d565
BLAKE2b-256 f0cf9c9e652399663587685f00049b1ad8595f3f7290ae8d983f1509c004270d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pycnp-0.1.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycnp-0.1.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 75d425a49723eaaf44c40405917c7a12123b8261c164d57fc290812ab61a7cb0
MD5 6d65726efb611cb275d1d986d303dcb4
BLAKE2b-256 174e03954cab0f0d77eb8c54cb2cb04f7a1e243c2b5243a28177a594638fc27a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp39-cp39-win_amd64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pycnp-0.1.4-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 96947554cf4c4bc9342321a168ad47edad066be1ecf3f90d4864eb1ef1f62f6b
MD5 72ca3e5b9c1e745f8f1bb09c088c25eb
BLAKE2b-256 9ce9d50f9f5398ff756d84ef7e77663184396295060353690e1f09505b637093

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycnp-0.1.4-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pycnp-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 376.5 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pycnp-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5cd1839b68f6725d91dcf499699b58eb0ef5f7ffe161913f7dd6094183ccfe88
MD5 1ecf01ecaff9316a9384aaa4cd94c585
BLAKE2b-256 8c6fffaaf71f79d11e8abb66d1c1adf5bf99669efab3198a5e6f94a79c3e43fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycnp-0.1.4-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: wheels.yml on xuebo100/PyCNP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page