dimod.generators.independent_set#

independent_set(edges: Iterable[Tuple[Hashable, Hashable]], nodes: Iterable[Hashable] | None = None) BinaryQuadraticModel[source]#

Generate a binary quadratic model encoding an independent set problem.

Given a graph G, an independent set is a set of nodes such that the subgraph of G induced by these nodes contains no edges.

Parameters:
  • edges – Edges of the graph.

  • nodes – Nodes of the graph.

Returns:

A binary quadratic model (BQM) with variables and interactions corresponding to nodes and edges. Each interaction has a quadratic bias of 1 and each node has a linear bias of 0.

Examples

Generate an independent set BQM from a list of edges.

>>> dimod.generators.independent_set([(0, 1), (1, 2)])
BinaryQuadraticModel({0: 0.0, 1: 0.0, 2: 0.0}, {(1, 0): 1.0, (2, 1): 1.0}, 0.0, 'BINARY')

Generate an independent set BQM from a list of edges and nodes.

>>> dimod.generators.independent_set([(0, 1)], [0, 1, 2])
BinaryQuadraticModel({0: 0.0, 1: 0.0, 2: 0.0}, {(1, 0): 1.0}, 0.0, 'BINARY')

Generate an independent set BQM from a networkx.Graph.

>>> import networkx as nx
>>> G = nx.complete_graph(2)
>>> dimod.generators.independent_set(G.edges, G.nodes)
BinaryQuadraticModel({0: 0.0, 1: 0.0}, {(1, 0): 1.0}, 0.0, 'BINARY')