Minimum Dominating Set
import networkx as nx
import pyomo.core as pyo
def mds(graph: nx.Graph) -> pyo.ConcreteModel:
model = pyo.ConcreteModel()
model.x = pyo.Var(graph.nodes, domain=pyo.Binary)
@model.Constraint(graph.nodes)
def dominating_rule(model, idx):
sum_of_neighbors = sum(model.x[neighbor] for neighbor in graph.neighbors(idx))
return model.x[idx] + sum_of_neighbors >= 1
model.cost = pyo.Objective(expr=sum(model.x.values()), sense=pyo.minimize)
return model
This function generates a PYOMO model that formulates the Minimum Dominating Set problem. The problem finds the smallest set of vertices in a graph such that every vertex in the graph is adjacent to at least one member of the set. The model contains:
- Index set declarations (model.Nodes, model.Arcs).
- Binary variable declaration for each node (model.x) indicating whether that node is chosen for the set.
- Constraint rule – for each node, it must be a part of the chosen set or be neighbored by one.
- Objective rule – the sum of the variables equals the set size.