Skip to main content

K-Max algorithm for computing dominating sets in undirected graphs

Project description

kmax-domset

K-Max algorithm for computing dominating sets in undirected graphs.

A dominating set D of a graph G = (V, E) is a subset of vertices such that every vertex in V either belongs to D or is adjacent to at least one vertex in D.

This package implements the K-Max algorithm, which uses Karci centrality — a measure that combines the node degree in the original graph, its degree in a K-max spanning tree, and the sizes of fundamental cut-sets — to greedily select the most structurally important nodes into the dominating set.


Installation

pip install kmax-domset

Quick Start

from kmax_domset import KMaxAlgorithm

# Adjacency matrix: 1 = edge, 0 = no edge
adj = [
    [0, 1, 0, 0, 1],
    [1, 0, 1, 0, 0],
    [0, 1, 0, 1, 0],
    [0, 0, 1, 0, 1],
    [1, 0, 0, 1, 0],
]

algo = KMaxAlgorithm(adj)
D = algo.dominating_set()
print("Dominating set:", sorted(D))   # e.g. [0, 2]

Visualisation

algo.visualize(D)                        # spring layout (default)
algo.visualize(D, layout="circular")     # circular layout
algo.visualize(D, layout="kamada")       # Kamada-Kawai layout
algo.visualize(D, layout="spectral")     # spectral layout

Red nodes are in the dominating set; blue nodes are dominated neighbours.


Building the adjacency matrix

Manual (small graphs)

n = 6
adj = [[0] * n for _ in range(n)]

edges = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 0), (0, 3)]
for u, v in edges:
    adj[u][v] = 1
    adj[v][u] = 1

From NetworkX

import networkx as nx
from kmax_domset import KMaxAlgorithm

G = nx.petersen_graph()
n = G.number_of_nodes()
adj = [[0] * n for _ in range(n)]
for u, v in G.edges():
    adj[u][v] = 1
    adj[v][u] = 1

D = KMaxAlgorithm(adj).dominating_set()
print("Dominating set:", sorted(D))

API

KMaxAlgorithm(adj_matrix)

Parameter Type Description
adj_matrix list[list[int]] Square symmetric adjacency matrix (0/1).

dominating_set() → set[int]

Returns a set of node indices forming a dominating set.

visualize(D=None, layout="spring")

Parameter Type Description
D set[int] Dominating set to highlight. Auto-computed if None.
layout str "spring" · "circular" · "kamada" · "spectral"

Algorithm Overview

  1. Phase 1 — K-max spanning tree: Build a spanning tree (forest for disconnected graphs) by greedily selecting the highest-degree unvisited node at each step using a max-priority queue.

  2. Phase 2 — Fundamental cut-sets: For each tree branch (edge), compute the size of its fundamental cut-set — the number of graph edges (branches + chords) whose removal disconnects the two components formed by removing that branch.

  3. Karci centrality: For each node v:
    K(v) = deg_G(v) + deg_T(v) + Σ cut_size(e) for all tree branches e incident to v.

  4. Phase 3 — Greedy selection: Repeatedly pick the undominated node with the highest Karci centrality and add it to the dominating set until all nodes are covered.


Requirements

  • Python ≥ 3.8
  • networkx >= 2.6
  • matplotlib >= 3.4

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

kmax_domset-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

kmax_domset-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file kmax_domset-0.1.1.tar.gz.

File metadata

  • Download URL: kmax_domset-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for kmax_domset-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ff4140c41c9adaf2173fdeb20512542a17e089d4ea2ba3230d1efe24654b673d
MD5 b861c225e5ab6d9a92bcaf971f740b67
BLAKE2b-256 85678e0b6933a742d9f72eb44feb016f815be1c81540f6a7efaab789f1450197

See more details on using hashes here.

File details

Details for the file kmax_domset-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kmax_domset-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for kmax_domset-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a0da48c253b847a67977cf1cc215148585616ed86418120af84575aa57cdc870
MD5 34f7896afacb23be7bbb18c78415c6e3
BLAKE2b-256 a58043f4159aeb3a686c22022ee131f5736c2328b9d2255f86d527ad106b6338

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