Maxcut

class Maxcut(graph)[source]

Bases: GraphOptimizationApplication

Optimization application for the “max-cut” [1] problem based on a NetworkX graph.

References

[1]: “Maximum cut”, https://en.wikipedia.org/wiki/Maximum_cut

Parameters:

graph (nx.Graph | np.ndarray | list) – A graph representing a problem. It can be specified directly as a NetworkX graph, or as an array or list format suitable to build out a NetworkX graph.

Attributes

graph

Getter of the graph

Returns:

A graph for a problem

Methods

draw(result=None, pos=None)

Draw a graph with the result. When the result is None, draw an original graph without colors.

Parameters:
  • result (OptimizationResult | np.ndarray | None) – The calculated result for the problem

  • pos (dict[int, np.ndarray] | None) – The positions of nodes

static get_gset_result(x)[source]

Get graph solution in Gset format from binary string.

Parameters:

x (ndarray) – binary string as numpy array.

Returns:

A graph solution in Gset format.

Return type:

dict[int, int]

interpret(result)[source]

Interpret a result as two lists of node indices

Parameters:

result (OptimizationResult | np.ndarray) – The calculated result of the problem

Returns:

Two lists of node indices correspond to two node sets for the Max-cut

Return type:

list[list[int]]

static parse_gset_format(filename)[source]

Read graph in Gset format from file.

Parameters:

filename (str) – the name of the file.

Returns:

An adjacency matrix as a 2D numpy array.

Return type:

ndarray

static sample_most_likely(state_vector)

Compute the most likely binary string from state vector.

Parameters:

state_vector (QuasiDistribution | Statevector | np.ndarray | dict) – state vector or counts or quasi-probabilities.

Returns:

binary string as numpy.ndarray of ints.

Raises:

ValueError – if state_vector is not QuasiDistribution, Statevector, np.ndarray, or dict.

Return type:

np.ndarray

to_quadratic_program()[source]

Convert a Max-cut problem instance into a QuadraticProgram

Returns:

The QuadraticProgram created from the Max-cut problem instance.

Return type:

QuadraticProgram