ragraph.analysis.heuristics
¶
Heuristics¶
Heuristics are combinations of algorithms available in the other sub-packages or have an output that does not strictly fit one of the other categories. Not all heuristics have a common argument structure because of their more diverse nature.
Available heuristics¶
dijkstrashortest reach algorithm.johnsoncircuit finding algorithm.markov_gammahierarchical clustering with bus detection heuristic.
dijkstra
¶
dijkstra(
graph: Graph,
start_node: Node,
nodes: list[Node] | None = None,
weight: str | None = None,
inherit: bool = False,
aggregate: bool = False,
**kwargs
) -> tuple[defaultdict[str, float], dict[str, str]]
Dijkstra's algorithm for finding the all shortest (weighted) path originating from a given node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
Graph to find circuits in. |
required |
start_node
|
Node
|
Node to start the search from. |
required |
nodes
|
list[Node] | None
|
Nodes to consider during circuit search. |
None
|
weight
|
str | None
|
Weight label to use when traversing edges. |
None
|
inherit
|
bool
|
Whether to consider edges between children of the given nodes. |
False
|
aggregate
|
bool
|
Whether to take the aggregate of all edge weights between two nodes as the distance instead of evaluating individual edges. |
False
|
Returns:
| Type | Description |
|---|---|
defaultdict[str, float]
|
|
dict[str, str]
|
|
Source code in src/ragraph/analysis/heuristics/_dijkstra.py
johnson
¶
johnson(
graph: Graph,
nodes: list[Node] | None = None,
names: bool = False,
inherit: bool = True,
**kwargs
) -> Generator[list[str] | list[Node], None, None]
Donald B. Johnson's nested circuit finding algorithm. A circuit is a cycle in a graph, circuits can overlap or contain duplicate parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
Graph to find circuits in. |
required |
nodes
|
list[Node] | None
|
Nodes to consider during circuit search. |
None
|
inherit
|
bool
|
Whether to take into account (inherit) edges between children during SCC calculations. |
True
|
Yields:
| Type | Description |
|---|---|
list[str] | list[Node]
|
Node circuit lists. |
Note
Cannot cluster a graph directly since circuits may overlap in all sorts of ways. Therefore, it gives you cluster-related information, but no clear hierarchy.
Reference
Johnson, D. B. (1975). Finding all the elementary circuits of a directed graph. In SIAM J. COMPUT (Vol. 4). https://doi.org/10.1137/0204007
Source code in src/ragraph/analysis/heuristics/_johnson.py
markov_gamma
¶
markov_gamma(
graph: Graph,
root: Optional[Union[str, Node]] = None,
leafs: Optional[Union[List[Node], List[str]]] = None,
inherit: bool = True,
loops: bool = False,
edge_weights: Optional[List[str]] = None,
alpha: int = default,
beta: float = default,
mu: float = default,
gamma: float = default,
local_buses: bool = default,
max_iter: int = default,
symmetrize: bool = default,
inplace: bool = True,
names: bool = False,
safe: bool = True,
**kwargs
) -> Union[List[Node], Tuple[Graph, List[Node]]]
Cluster a given graph hierarchically with buses on a local level or globally.
Source code in src/ragraph/analysis/heuristics/_markov_gamma.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
_dijkstra
¶
Dijkstra's algorithm¶
Finding the all shortest (weighted) paths originating from a given node.
_evaluate_edge_aggregate
¶
_evaluate_edge_aggregate(
graph: Graph,
queue: SortedDict,
previous: dict[str, str],
distance: defaultdict[str, float],
source: str,
target: str,
offset: float,
inherit: bool,
weight: str | None,
) -> None
Take the aggregated of the weight of all edges between two nodes as the distance.
Source code in src/ragraph/analysis/heuristics/_dijkstra.py
_evaluate_individual_edges
¶
_evaluate_individual_edges(
graph: Graph,
queue: SortedDict,
previous: dict[str, str],
distance: defaultdict[str, float],
source: str,
target: str,
offset: float,
inherit: bool,
weight: str | None,
) -> None
Evaluate each edge between two nodes as a separate bridge that can be crossed.
Source code in src/ragraph/analysis/heuristics/_dijkstra.py
_initialize_queue
¶
Initialize the queue with the start node having a distance of 0.0 and all other nodes having a distance of infinity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
list[Node]
|
List of nodes to consider during circuit search. |
required |
start_node
|
Node
|
Node to start the search from. |
required |
Returns:
| Type | Description |
|---|---|
SortedDict
|
SortedDict with the start node having a distance of 0.0 and all other nodes having a |
SortedDict
|
distance of infinity. |
Source code in src/ragraph/analysis/heuristics/_dijkstra.py
dijkstra
¶
dijkstra(
graph: Graph,
start_node: Node,
nodes: list[Node] | None = None,
weight: str | None = None,
inherit: bool = False,
aggregate: bool = False,
**kwargs
) -> tuple[defaultdict[str, float], dict[str, str]]
Dijkstra's algorithm for finding the all shortest (weighted) path originating from a given node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
Graph to find circuits in. |
required |
start_node
|
Node
|
Node to start the search from. |
required |
nodes
|
list[Node] | None
|
Nodes to consider during circuit search. |
None
|
weight
|
str | None
|
Weight label to use when traversing edges. |
None
|
inherit
|
bool
|
Whether to consider edges between children of the given nodes. |
False
|
aggregate
|
bool
|
Whether to take the aggregate of all edge weights between two nodes as the distance instead of evaluating individual edges. |
False
|
Returns:
| Type | Description |
|---|---|
defaultdict[str, float]
|
|
dict[str, str]
|
|
Source code in src/ragraph/analysis/heuristics/_dijkstra.py
_johnson
¶
Donald B. Johnson's nested circuit finding algorithm¶
johnson
¶
johnson(
graph: Graph,
nodes: list[Node] | None = None,
names: bool = False,
inherit: bool = True,
**kwargs
) -> Generator[list[str] | list[Node], None, None]
Donald B. Johnson's nested circuit finding algorithm. A circuit is a cycle in a graph, circuits can overlap or contain duplicate parts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
Graph to find circuits in. |
required |
nodes
|
list[Node] | None
|
Nodes to consider during circuit search. |
None
|
inherit
|
bool
|
Whether to take into account (inherit) edges between children during SCC calculations. |
True
|
Yields:
| Type | Description |
|---|---|
list[str] | list[Node]
|
Node circuit lists. |
Note
Cannot cluster a graph directly since circuits may overlap in all sorts of ways. Therefore, it gives you cluster-related information, but no clear hierarchy.
Reference
Johnson, D. B. (1975). Finding all the elementary circuits of a directed graph. In SIAM J. COMPUT (Vol. 4). https://doi.org/10.1137/0204007
Source code in src/ragraph/analysis/heuristics/_johnson.py
_markov_gamma
¶
Hierarchical Markov Clustering (HMC) with Gamma bus detection.¶
markov_gamma
¶
markov_gamma(
graph: Graph,
root: Optional[Union[str, Node]] = None,
leafs: Optional[Union[List[Node], List[str]]] = None,
inherit: bool = True,
loops: bool = False,
edge_weights: Optional[List[str]] = None,
alpha: int = default,
beta: float = default,
mu: float = default,
gamma: float = default,
local_buses: bool = default,
max_iter: int = default,
symmetrize: bool = default,
inplace: bool = True,
names: bool = False,
safe: bool = True,
**kwargs
) -> Union[List[Node], Tuple[Graph, List[Node]]]
Cluster a given graph hierarchically with buses on a local level or globally.
Source code in src/ragraph/analysis/heuristics/_markov_gamma.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |