Skip to main content

Protecting graphs under multiple simultaneous attacks: a heuristic approach

Project description

General

This repo contains the implementation, instances and results of the paper 'Protecting graphs under multiple simultaneous attacks: a heuristic approach' by Marko Djukanovic, Stefan Kapunac, Aleksandar Kartelj and Dragan Matic.

Original implementation is in C++ and can be compiled using the Makefile. We also created Python bindings using the Pybind11 library. For a quickstart see this Colab notebook.

Installation

pip install ksrdp

Minimal working example

import ksrdp

def test_greedy(in_file_path: str, num_attacks: int) -> None:
    neighbors = ksrdp.read_instance(in_file_path)
    solution, value = ksrdp.greedy_uncovered(neighbors, num_attacks)
    print(f'greedy solution: {solution}, value: {value}')

def test_vns(in_file_path: str, num_attacks: int, vns_params: dict) -> None:
    neighbors = ksrdp.read_instance(in_file_path)
    solution, fitness, iter, end_time, best_found_time = ksrdp.vns(
        neighbors,
        vns_params['comb_take_all_bound'],
        vns_params['comb_intense_max'],
        vns_params['comb_lightweight_max'],
        num_attacks,
        vns_params['time_limit'],
        vns_params['iter_limit'],
        vns_params['k_min'],
        vns_params['k_max'],
        vns_params['move_prob'],
        vns_params['tries'],
        vns_params['num_alternatives_cutoff'],
        # verbose=True,
    )
    print(f'vns solution: {solution}, fitness: {fitness}, iter: {iter}, end_time: {end_time}, best_found_time: {best_found_time}')

def main():
    # help(ksrdp)
    in_file_path = '../instances/random/10_1.txt'
    num_attacks = 2
    test_greedy(in_file_path, num_attacks)
    vns_params = {
        'comb_take_all_bound': 100_000,
        'comb_intense_max': 10_000_000,
        'comb_lightweight_max': 10_000,
        'time_limit': 60,
        'iter_limit': 5000,
        'k_min': 1,
        'k_max': 10,
        'move_prob': 0.5,
        'tries': 10,
        'num_alternatives_cutoff': 100,
    }
    test_vns(in_file_path, num_attacks, vns_params)

if __name__ == '__main__':
    main()

License

License: MIT

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

ksrdp-0.0.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

ksrdp-0.0.2-cp38-cp38-manylinux_2_34_x86_64.whl (119.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

File details

Details for the file ksrdp-0.0.2.tar.gz.

File metadata

  • Download URL: ksrdp-0.0.2.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.18

File hashes

Hashes for ksrdp-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b86bf31e696114f7f0baf5160984cd4805170901792f612f548d3bb07a17c360
MD5 6f6013d985c51c8caea9545905bfbdd3
BLAKE2b-256 f4a4efe7ad81ca2f4d5d62bbbc21b2def5737daf11718140c4e30e71bc62ef9c

See more details on using hashes here.

File details

Details for the file ksrdp-0.0.2-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ksrdp-0.0.2-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1ea01da0a6e6487edebfe36b1898057e66c6f420ed68a284fd33e8493ace7102
MD5 efee2f15f5038716e394873b0a08ae8c
BLAKE2b-256 b695345d84183665c07eaebd294f66c4e13c5ff87c615d4465e518b078fcfc8e

See more details on using hashes here.

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