Skip to content

complete_search

CompleteSearch

Bases: NKAlgorithm

Searching all possible cycles with number of nodes greater than 2.

algorithm = DijkstraShortestPath instance-attribute

min_length = 0 instance-attribute

search_algorithms = {'dijkstra': DijkstraShortestPath, 'bfs': BreadthFirstSearch} instance-attribute

search_type = 'shortest' instance-attribute

__init__(graph)

compute_weight_matrix()

Calculate weight matrix. The weight matrix has, for each set of two nodes a value of 0 if the nodes are not connected. If the nodes are connected, the value in the matrix is the weight of the edge connectint them.

Returns:

Type Description
ndarray

np.ndarray[N, N]: weight matrix

cycle_pairs()

For each node, find all edges connecting to it (in-neighbors). Using the distance matrix, verify if a cycle exists between with a distance larger than min_distance. If self.search_type is 'shortest', only return the closest in-neighbor, else return all in-neighbors.

Returns:

Type Description
tuple[ndarray, ndarray]

tuple[np.ndarrays]: sources and targets

run()

Find all possible cycles in the graph.

Returns:

Name Type Description
Dataframe DataFrame

Dataframe of cycles.

set_algorithm(algorithm)

Default: 'dijkstra'

set_min_length(min_length)

minimum length of a valid cycle found by the cycle search Default: 0

set_search_type(search_type)

Default: 'shortest'

to_nk_graph(graph)