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
-
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.
-
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.
-
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. -
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.6matplotlib >= 3.4
Metadata
Release files for kmax-domset 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kmax_domset-0.1.2.tar.gz | 5.7 kB | Without provenance | Details for kmax_domset-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kmax_domset-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for kmax_domset-0.1.2-py3-none-any.whl |
Total release size: 11.9 kB
Release files / kmax_domset-0.1.2.tar.gz
| Download URL | kmax_domset-0.1.2.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c216a67b6d278588fe44f66bd002299cfc48408359830166f99616414e923923
|
|
BLAKE2b-256 checksum How to use checksums |
ed8b5572dd58d646a35ee22fca4d91452a7180ccd78dedaa3cc07638ddfa6b61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / kmax_domset-0.1.2-py3-none-any.whl
| Download URL | kmax_domset-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bcd2cdd8b8914000a6bbfafd0a1e7d423ab536554a26d6dedb29c72d19beccf7
|
|
BLAKE2b-256 checksum How to use checksums |
4919eab133faff21baad6c9c6fdb6287ece6da368d187ed79f09f87dd5b8f235
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for kmax-domset 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.