graph
Bases: base_topology
Represents a generic graph structure, inheriting from the base_topology
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the graph, by default 'graph'. |
'graph'
|
*args
|
tuple
|
Additional positional arguments to be passed to the |
()
|
**kwargs
|
dict
|
Additional keyword arguments to be passed to the |
{}
|
Inherits From
base_topology The base class for topological structures.
Source code in tinybig/koala/topology/graph.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 |
|
__init__(name='graph', *args, **kwargs)
Initializes a graph with the specified name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the graph, by default 'graph'. |
'graph'
|
*args
|
tuple
|
Additional positional arguments to be passed to the |
()
|
**kwargs
|
dict
|
Additional keyword arguments to be passed to the |
{}
|
Source code in tinybig/koala/topology/graph.py
bfs(start=None, goal=None)
Performs a Breadth-First Search (BFS) traversal of the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
node
|
The starting node for the BFS traversal. If None, traversal starts from an arbitrary node. |
None
|
goal
|
node
|
The target node to search for. If None, the BFS traversal continues until all nodes are visited. |
None
|
Returns:
Type | Description |
---|---|
list
|
A list of nodes representing the BFS traversal path or the path to the goal if specified. |
Source code in tinybig/koala/topology/graph.py
dfs(start=None, goal=None)
Performs a Depth-First Search (DFS) traversal of the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
node
|
The starting node for the DFS traversal. If None, traversal starts from an arbitrary node. |
None
|
goal
|
node
|
The target node to search for. If None, the DFS traversal continues until all nodes are visited. |
None
|
Returns:
Type | Description |
---|---|
list
|
A list of nodes representing the DFS traversal path or the path to the goal if specified. |
Source code in tinybig/koala/topology/graph.py
radius()
Calculates the radius of the graph.
Returns:
Type | Description |
---|---|
int
|
The radius of the graph, defined as the minimum eccentricity of all nodes. |
Notes
Eccentricity is the maximum distance from a node to any other node in the graph.
Source code in tinybig/koala/topology/graph.py
shortest_path(start=None, goal=None)
Finds the shortest path between two nodes in the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
node
|
The starting node for the path. If None, raises a ValueError. |
None
|
goal
|
node
|
The target node for the path. If None, raises a ValueError. |
None
|
Returns:
Type | Description |
---|---|
list
|
A list of nodes representing the shortest path from the start node to the goal node. |
Raises:
Type | Description |
---|---|
ValueError
|
If either the |