mqt.problemsolver.qubo_tools.pathfinder.graph

Provides a simple implementation for graphs to be used with qubo_tools.

Module Contents

Edge
class Graph(n_vertices: int, edges: list[Edge])[source]

Represents a graph to be used with qubo_tools.

n_vertices

The number of vertices in the graph.

Type:

int

adjacency_matrix

The adjacency matrix of the graph.

Type:

npt.NDArray[np.int_ | np.float64]

all_vertices

A list of all vertices in the graph.

Type:

list[int]

all_edges

A list of all edges in the graph.

Type:

list[tuple[int, int]]

non_edges

A list of all non-edges in the graph.

Type:

list[tuple[int, int]]

n_vertices: int
adjacency_matrix: numpy.typing.NDArray[int_ | numpy.float64]
property all_vertices: list[int]

A list of all vertices in the graph.

property all_edges: list[tuple[int, int]]

A list of all edges in the graph.

property non_edges: list[tuple[int, int]]

A list of all pairs (i, j) that are not edges in the graph.

static read(file: TextIOWrapper) → Graph[source]

Reads a graph from a file.

Parameters:

file (TextIOWrapper) – The file to read the graph from.

Returns:

The graph read from the file.

Return type:

Graph

store(file: TextIOWrapper) → None[source]

Stores the graph in a file.

Parameters:

file (TextIOWrapper) – The file to store the graph in.

static from_adjacency_matrix(adjacency_matrix: numpy.typing.NDArray[int_ | numpy.float64] | list[list[int]] | list[list[float]]) → Graph[source]

Creates a graph from an adjacency matrix.

Parameters:

adjacency_matrix (npt.NDArray[np.int_ | np.float64]) – The adjacency matrix to create the graph from.

Returns:

The graph created from the adjacency matrix.

Return type:

Graph

static deserialize(encoding: str) → Graph[source]

Deserializes a graph from a string.

Parameters:

encoding (str) – The string to deserialize the graph from.

Returns:

The deserialized graph.

Return type:

Graph

serialize() → str[source]

Serializes the graph into a string.

Returns:

The serialized graph as a string.

Return type:

str

__eq__(value: object) → bool[source]

Checks if two graphs are equal.

Parameters:

value (object) – The other graph to compare to.

Returns:

True if the graphs are equal, False otherwise.

Return type:

bool

__hash__() → int[source]

Returns the hash of the graph.

Returns:

The hash of the graph.

Return type:

int