0

Cross posting this from CS Theory since it is more of a software question.

I need a code for calculating exact MIN-DOM-SET. Currently the best option suggested has been to formulate it as an SMT problem and throw it at an SMT solver.

Curious if there were any good MIN-DOM-SET specific codes out there or a good SMT-LIB formulation.

Community
  • 1
  • 1
Chad Brewbaker
  • 2,523
  • 2
  • 19
  • 26
  • 1
    Hakan Kjellerstrand developed a [MiniZinc algorithm](https://github.com/hakank/hakank/blob/master/minizinc/dominating_set.mzn) for the dominating set problem. – Axel Kemper Feb 21 '16 at 22:44
  • It has an obvious ILP model too so you can throw it in Gurobi or the like – harold Feb 21 '16 at 22:49

1 Answers1

1

I coded one up in Z3's Python bindings using the new Optimize functionality.

def min_dom_set(graph):
    """Try to dominate the graph with the least number of verticies possible"""
    s = Optimize()
    nodes_colors = dict((node_name, Int('k%r' % node_name)) for node_name in graph.nodes())
    for node in graph.nodes():
           s.add(And(nodes_colors[node] >= 0, nodes_colors[node] <= 1)) # dominator or not
           dom_neighbor = Sum ([ (nodes_colors[j]) for j in graph.neighbors(node) ])
           s.add(Sum(nodes_colors[node], dom_neighbor ) >= 1 )
    s.minimize( Sum([ nodes_colors[y] for y in graph.nodes() ]) )

    if s.check() == sat:
        m = s.model()
        return dict((name, m[color].as_long()) for name, color in nodes_colors.iteritems())

    raise Exception('Could not find a solution.')
Chad Brewbaker
  • 2,523
  • 2
  • 19
  • 26