MutableGraph¶
The MutableGraph is an abstract base class, that allows modifications and additions to the graph. It is used to build graphs. SizeBoundedGraph is a subclass.
- class deglib.graph.MutableGraph(graph_cpp: SearchGraph)¶
Bases:
SearchGraph,ABC- abstract add_vertex(external_label: int, feature_vector: ndarray) int¶
Add a new vertex. The neighbor indices will be prefilled with a self-loop, the weights will be 0.
- Parameters:
external_label – The label for the new vertex
feature_vector – The feature vector to add. This numpy array should be c-contiguous, otherwise it has to be reallocated.
- Returns:
the internal index of the new vertex
- abstract remove_vertex(external_label: int)¶
Remove an existing vertex.
- Parameters:
external_label – The external label of the vertex that should be removed.
- abstract change_edge(internal_index: int, from_neighbor_index: int, to_neighbor_index: int, to_neighbor_weight: float) bool¶
Swap a neighbor with another neighbor and its weight.
- Parameters:
internal_index – vertex index which neighbors should be changed
from_neighbor_index – neighbor index to remove
to_neighbor_index – neighbor index to add
to_neighbor_weight – weight of the neighbor to add
- Returns:
True if the from_neighbor_index was found and changed
- abstract change_edges(internal_index: int, neighbor_indices: ndarray, neighbor_weights: ndarray)¶
Change all edges of a vertex. The neighbor indices/weights and feature vectors will be copied. The neighbor array need to have enough neighbors to match the edge-per-vertex count of the graph. The indices in the neighbor_indices array must be sorted.
- Parameters:
internal_index – The index of the vertex for which edges should change
neighbor_indices – These neighbors will be set as the new neighbors of the specified vertex
neighbor_weights – These weights will be set as the new weights for the neighbors.
- abstract get_neighbor_weights(internal_index: int, copy: bool = False) ndarray¶
Get weights for each neighbor of the vertex defined by the given index.
- Parameters:
internal_index – The index that specifies the vertex
copy – If True the returned neighbor weights are copied, otherwise they reference internal graph data.
- Returns:
The weights of the neighbors
- abstract get_edge_weight(from_neighbor_index: int, to_neighbor_index: int) float¶
Get the weight from vertex to another vertex. If start vertex is not a neighbor of end vertex, -1.0 is returned.
- Parameters:
from_neighbor_index – Internal index of the start vertex
to_neighbor_index – Internal index of the target vertex
- Returns:
If present the weight between start and target vertex, -1.0 otherwise
- abstract save_graph(path: str | Path) bool¶
Save graph to specified file. Creates necessary directories.
- Parameters:
path – The path where to save the file.
- remove_non_mrng_edges()¶
Remove all edges which are not MRNG conform.