pyTooling.Graph
A powerful graph data structure for Python.
Graph algorithms using all vertices are provided as methods on the graph instance. Whereas graph algorithms based on a starting vertex are provided as methods on a vertex.
Example Graph
%%{init: { "flowchart": { "nodeSpacing": 15, "rankSpacing": 30, "curve": "linear", "useMaxWidth": false } } }%%
graph LR
A(A); B(B); C(C); D(D); E(E); F(F) ; G(G); H(H); I(I)
A --> B --> E
G --> F
A --> C --> G --> H --> D
D -.-> A
D & F -.-> B
I ---> E --> F --> D
classDef node fill:#eee,stroke:#777,font-size:smaller;
A directed graph with backward-edges denoted by dotted vertex relations.
See also
pyTooling.Graph.GraphML→ Writing a graph as a GraphML document.
pyTooling.Tree→ A tree, which is a graph without cycles and with a single root.
pyTooling.StateMachine→ A statemachine, which is a directed graph of states and transitions.
Submodules
Exceptions
GraphException: Base exception of all exceptions raised bypyTooling.Graph.InternalError: The exception is raised when a data structure corruption is detected.NotInSameGraph: The exception is raised when creating an edge between two vertices, but these are not in the same graph.NotInDifferentSubgraphs: The exception is raised when creating a link between two vertices, but these are in the same subgraph.DuplicateVertexError: The exception is raised when the vertex already exists in the graph.DuplicateEdgeError: The exception is raised when the edge already exists in the graph.DestinationNotReachable: The exception is raised when a destination vertex is not reachable.NotATreeError: The exception is raised when a subgraph is not a tree.CycleError: The exception is raised when a not permitted cycle is found.
Classes
Base: Base-class for all graph elements, adding a dictionary of arbitrary key-value-pairs to them.BaseWithIDValueAndWeight: Base-class for graph elements identified by an ID and carrying a value and a weight - vertices, edges and links.BaseWithName: Base-class for named graph elements like a graph, a subgraph, a view or a component.BaseWithVertices: Base-class for named graph elements owning a set of vertices - a subgraph, a view or a component.Vertex: A vertex can have a unique ID, a value and attached meta information as key-value-pairs. A vertex has referencesBaseEdge: An edge can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All edges areEdge: An edge can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All edges areLink: A link can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All links areBaseGraph: .. todo:: GRAPH::BaseGraph Needs documentation.Subgraph: .. todo:: GRAPH::Subgraph Needs documentation.View: .. todo:: GRAPH::View Needs documentation.Component: .. todo:: GRAPH::Component Needs documentation.Graph: A graph data structure is represented by an instance ofGraphholding references to
Exceptions
- exception pyTooling.Graph.GraphException[source]
Base exception of all exceptions raised by
pyTooling.Graph.Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.InternalError[source]
The exception is raised when a data structure corruption is detected.
Danger
This exception should never be raised.
If so, please create an issue at GitHub so the data structure corruption can be investigated and fixed.
⇒ Bug Tracker at GitHubInheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.NotInSameGraph[source]
The exception is raised when creating an edge between two vertices, but these are not in the same graph.
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.NotInDifferentSubgraphs[source]
The exception is raised when creating a link between two vertices, but these are in the same subgraph.
A link crosses subgraph boundaries. Two vertices within one subgraph are connected by an edge.
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.DuplicateVertexError[source]
The exception is raised when the vertex already exists in the graph.
Inheritance
- __init__(message, /, *, vertexID=None)[source]
Initializes the exception with the identifier that is already taken.
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.DuplicateEdgeError[source]
The exception is raised when the edge already exists in the graph.
Inheritance
- __init__(message, /, *, edgeID=None)[source]
Initializes the exception with the identifier that is already taken.
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.DestinationNotReachable[source]
The exception is raised when a destination vertex is not reachable.
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.NotATreeError[source]
The exception is raised when a subgraph is not a tree.
Either the subgraph has a cycle (backward edge) or links between branches (cross-edge).
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
- exception pyTooling.Graph.CycleError[source]
The exception is raised when a not permitted cycle is found.
Inheritance
- __init__(*args, **kwargs)
- classmethod __new__(*args, **kwargs)
Classes
- class pyTooling.Graph.Base[source]
Base-class for all graph elements, adding a dictionary of arbitrary key-value-pairs to them.
Every vertex, edge, link, component, view, subgraph and graph can carry meta information this way.
Inheritance
- __setitem__(key, value)[source]
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __delitem__(key)[source]
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __contains__(key)[source]
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __len__()[source]
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- class pyTooling.Graph.BaseWithIDValueAndWeight[source]
Base-class for graph elements identified by an ID and carrying a value and a weight - vertices, edges and links.
All three are optional: an element without an ID is still part of the graph, it just can’t be looked up by ID.
Inheritance
- __init__(identifier=None, value=None, weight=None, keyValuePairs=None)[source]
Initialize a graph element with an optional ID, value and weight.
- Parameters:
identifier (
Optional[TypeVar(IDType, bound=Hashable)]) – Optional, unique ID.weight (
Optional[TypeVar(WeightType, bound=Union[int,float])]) – Optional, weight.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs.
- Raises:
TypeError – If parameter ‘name’ is not of type string.
- Return type:
None
- property ID: IDType | None
Read-only property to access the unique ID (
_id).If no ID was given at creation time, ID returns
None.- Returns:
Unique ID, if ID was given at creation time, else
None.
- property Weight: EdgeWeightType | None
Property to get and set the weight (
_weight) of an edge.- Returns:
The weight of an edge.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- class pyTooling.Graph.BaseWithName[source]
Base-class for named graph elements like a graph, a subgraph, a view or a component.
Inheritance
- __init__(name=None, keyValuePairs=None)[source]
Initialize a named graph element with an optional name and optional key-value-pairs.
- Parameters:
- Raises:
ValueError – If parameter ‘graph’ is None.
- Return type:
None
- property Name: str | None
Property to access the name (
_name).- Returns:
The object’s name, or
Noneif it has none.- Raises:
TypeError – If an assigned value is not of type string.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- class pyTooling.Graph.BaseWithVertices[source]
Base-class for named graph elements owning a set of vertices - a subgraph, a view or a component.
Inheritance
- __init__(graph, name=None, vertices=None, keyValuePairs=None)[source]
Initialize a named graph element owning a set of vertices, and register it at its graph.
- Parameters:
- Raises:
ValueError – If parameter ‘graph’ is None.
- Return type:
None
- _graph: Graph[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]
Field storing a reference to the graph.
- _vertices: set[Vertex[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Field storing a set of vertices.
- property Graph: Graph
Read-only property to access the graph, this object is associated to (
_graph).- Returns:
The graph this object is associated to.
- property Vertices: set[Vertex]
Read-only property to access the vertices in this component (
_vertices).- Returns:
The set of vertices in this component.
- property VertexCount: int
Read-only property to return the number of vertices referenced by this object.
- Returns:
The number of vertices this object references.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property Name: str | None
Property to access the name (
_name).- Returns:
The object’s name, or
Noneif it has none.- Raises:
TypeError – If an assigned value is not of type string.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- _dict
A dictionary to store arbitrary key-value-pairs.
- _name
Field storing the object’s name.
- class pyTooling.Graph.Vertex[source]
A vertex can have a unique ID, a value and attached meta information as key-value-pairs. A vertex has references to inbound and outbound edges, thus a graph can be traversed in reverse.
Inheritance
- __init__(vertexID=None, value=None, weight=None, keyValuePairs=None, graph=None, subgraph=None)[source]
Initialize a vertex and register it at its graph or subgraph.
- Parameters:
vertexID (
Optional[TypeVar(VertexIDType, bound=Hashable)]) – Optional, ID for the new vertex.value (
Optional[TypeVar(VertexValueType)]) – Optional, value for the new vertex.weight (
Optional[TypeVar(VertexWeightType, bound=Union[int,float])]) – Optional, weight for the new vertex.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs.
- Raises:
TypeError – If parameter ‘vertexID’ is not of the graph’s vertex ID type.
DuplicateVertexError – If the given vertex ID already exists in this graph or subgraph.
- Return type:
None
- _graph: BaseGraph[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]
Field storing a reference to the graph.
- _subgraph: Subgraph[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]
Field storing a reference to the subgraph.
- _inboundEdges: list[Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Field storing a list of inbound edges.
- _outboundEdges: list[Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Field storing a list of outbound edges.
- _inboundLinks: list[Link[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Field storing a list of inbound links.
- _outboundLinks: list[Link[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Field storing a list of outbound links.
- Delete()[source]
Delete this vertex and every edge and link connected to it.
The vertex is removed from its graph or subgraph, and from its views; every connected edge and link is removed from its other vertex and unregistered from the graph or subgraph it was registered on.
- Return type:
- property Graph: Graph
Read-only property to access the graph, this vertex is associated to (
_graph).- Returns:
The graph this vertex is associated to.
- property Component: Component
Read-only property to access the component, this vertex is associated to (
_component).- Returns:
The component this vertex is associated to.
- property InboundEdges: tuple[Edge, ...]
Read-only property to get a tuple of inbound edges (
_inboundEdges).- Returns:
Tuple of inbound edges.
- property OutboundEdges: tuple[Edge, ...]
Read-only property to get a tuple of outbound edges (
_outboundEdges).- Returns:
Tuple of outbound edges.
- property InboundLinks: tuple[Link, ...]
Read-only property to get a tuple of inbound links (
_inboundLinks).- Returns:
Tuple of inbound links.
- property OutboundLinks: tuple[Link, ...]
Read-only property to get a tuple of outbound links (
_outboundLinks).- Returns:
Tuple of outbound links.
- property EdgeCount: int
Read-only property to get the number of all edges (inbound and outbound).
- Returns:
Number of inbound and outbound edges.
- property InboundEdgeCount: int
Read-only property to get the number of inbound edges.
- Returns:
Number of inbound edges.
- property OutboundEdgeCount: int
Read-only property to get the number of outbound edges.
- Returns:
Number of outbound edges.
- property LinkCount: int
Read-only property to get the number of all links (inbound and outbound).
- Returns:
Number of inbound and outbound links.
- property InboundLinkCount: int
Read-only property to get the number of inbound links.
- Returns:
Number of inbound links.
- property OutboundLinkCount: int
Read-only property to get the number of outbound links.
- Returns:
Number of outbound links.
- property IsRoot: bool
Read-only property to check if this vertex is a root vertex in the graph.
A root has no inbound edges (no predecessor vertices).
- Returns:
True, if this vertex is a root.
See also
Vertex.IsLeaf→ Check if a vertex is a leaf vertex in the graph.
BaseGraph.IterateRoots→ Iterate all roots of a graph.
BaseGraph.IterateLeafs→ Iterate all leafs of a graph.
- property IsLeaf: bool
Read-only property to check if this vertex is a leaf vertex in the graph.
A leaf has no outbound edges (no successor vertices).
- Returns:
True, if this vertex is a leaf.
See also
Vertex.IsRoot→ Check if a vertex is a root vertex in the graph.
BaseGraph.IterateRoots→ Iterate all roots of a graph.
BaseGraph.IterateLeafs→ Iterate all leafs of a graph.
- property Predecessors: tuple[Vertex, ...]
Read-only property to get a tuple of predecessor vertices.
- Returns:
Tuple of predecessor vertices.
- property Successors: tuple[Vertex, ...]
Read-only property to get a tuple of successor vertices.
- Returns:
Tuple of successor vertices.
- EdgeToVertex(vertex, edgeID=None, edgeWeight=None, edgeValue=None, keyValuePairs=None)[source]
Create an outbound edge from this vertex to the referenced vertex.
- Parameters:
vertex (
Vertex) – The vertex to be linked to.edgeID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, the edge’s optional ID for the new edge object.edgeWeight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, the edge’s optional weight for the new edge object.edgeValue (
Optional[TypeVar(VertexValueType)]) – Optional, the edge’s optional value for the new edge object.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new edge object.
- Return type:
- Returns:
The edge object linking this vertex and the referenced vertex.
- Raises:
DuplicateEdgeError – If the given edge ID already exists in this graph or subgraph.
NotInSameGraph – If both vertices are not in the same graph or subgraph.
UseLinkToVertex()orLinkFromVertex()to connect vertices across subgraph boundaries.
See also
EdgeFromVertex()→ Create an inbound edge from the referenced vertex to this vertex.
EdgeToNewVertex()→ Create a new vertex and link that vertex by an outbound edge from this vertex.
EdgeFromNewVertex()→ Create a new vertex and link that vertex by an inbound edge to this vertex.
LinkToVertex()→ Create an outbound link from this vertex to the referenced vertex.
LinkFromVertex()→ Create an inbound link from the referenced vertex to this vertex.
- EdgeFromVertex(vertex, edgeID=None, edgeWeight=None, edgeValue=None, keyValuePairs=None)[source]
Create an inbound edge from the referenced vertex to this vertex.
- Parameters:
vertex (
Vertex) – The vertex to be linked from.edgeID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, the edge’s optional ID for the new edge object.edgeWeight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, the edge’s optional weight for the new edge object.edgeValue (
Optional[TypeVar(VertexValueType)]) – Optional, the edge’s optional value for the new edge object.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new edge object.
- Return type:
- Returns:
The edge object linking the referenced vertex and this vertex.
- Raises:
DuplicateEdgeError – If the given edge ID already exists in this graph or subgraph.
NotInSameGraph – If both vertices are not in the same graph or subgraph.
UseLinkToVertex()orLinkFromVertex()to connect vertices across subgraph boundaries.
See also
EdgeToVertex()→ Create an outbound edge from this vertex to the referenced vertex.
EdgeToNewVertex()→ Create a new vertex and link that vertex by an outbound edge from this vertex.
EdgeFromNewVertex()→ Create a new vertex and link that vertex by an inbound edge to this vertex.
LinkToVertex()→ Create an outbound link from this vertex to the referenced vertex.
LinkFromVertex()→ Create an inbound link from the referenced vertex to this vertex.
- EdgeToNewVertex(vertexID=None, vertexValue=None, vertexWeight=None, vertexKeyValuePairs=None, edgeID=None, edgeWeight=None, edgeValue=None, edgeKeyValuePairs=None)[source]
Create a new vertex and link that vertex by an outbound edge from this vertex.
- Parameters:
vertexID (
Optional[TypeVar(VertexIDType, bound=Hashable)]) – Optional, the new vertex’ optional ID.vertexValue (
Optional[TypeVar(VertexValueType)]) – Optional, the new vertex’ optional value.vertexWeight (
Optional[TypeVar(VertexWeightType, bound=Union[int,float])]) – Optional, the new vertex’ optional weight.vertexKeyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new vertex.edgeID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, the edge’s optional ID for the new edge object.edgeWeight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, the edge’s optional weight for the new edge object.edgeValue (
Optional[TypeVar(VertexValueType)]) – Optional, the edge’s optional value for the new edge object.edgeKeyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new edge object.
- Return type:
- Returns:
The edge object linking this vertex and the created vertex.
- Raises:
DuplicateEdgeError – If the given edge ID already exists in this graph or subgraph.
NotInSameGraph – If both vertices are not in the same graph or subgraph.
UseLinkToVertex()orLinkFromVertex()to connect vertices across subgraph boundaries.
See also
EdgeToVertex()→ Create an outbound edge from this vertex to the referenced vertex.
EdgeFromVertex()→ Create an inbound edge from the referenced vertex to this vertex.
EdgeFromNewVertex()→ Create a new vertex and link that vertex by an inbound edge to this vertex.
LinkToVertex()→ Create an outbound link from this vertex to the referenced vertex.
LinkFromVertex()→ Create an inbound link from the referenced vertex to this vertex.
- EdgeFromNewVertex(vertexID=None, vertexValue=None, vertexWeight=None, vertexKeyValuePairs=None, edgeID=None, edgeWeight=None, edgeValue=None, edgeKeyValuePairs=None)[source]
Create a new vertex and link that vertex by an inbound edge to this vertex.
- Parameters:
vertexID (
Optional[TypeVar(VertexIDType, bound=Hashable)]) – Optional, the new vertex’ optional ID.vertexValue (
Optional[TypeVar(VertexValueType)]) – Optional, the new vertex’ optional value.vertexWeight (
Optional[TypeVar(VertexWeightType, bound=Union[int,float])]) – Optional, the new vertex’ optional weight.vertexKeyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new vertex.edgeID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, the edge’s optional ID for the new edge object.edgeWeight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, the edge’s optional weight for the new edge object.edgeValue (
Optional[TypeVar(VertexValueType)]) – Optional, the edge’s optional value for the new edge object.edgeKeyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new edge object.
- Return type:
- Returns:
The edge object linking this vertex and the created vertex.
- Raises:
DuplicateEdgeError – If the given edge ID already exists in this graph or subgraph.
NotInSameGraph – If both vertices are not in the same graph or subgraph.
UseLinkToVertex()orLinkFromVertex()to connect vertices across subgraph boundaries.
See also
EdgeToVertex()→ Create an outbound edge from this vertex to the referenced vertex.
EdgeFromVertex()→ Create an inbound edge from the referenced vertex to this vertex.
EdgeToNewVertex()→ Create a new vertex and link that vertex by an outbound edge from this vertex.
LinkToVertex()→ Create an outbound link from this vertex to the referenced vertex.
LinkFromVertex()→ Create an inbound link from the referenced vertex to this vertex.
- LinkToVertex(vertex, linkID=None, linkWeight=None, linkValue=None, keyValuePairs=None)[source]
Create an outbound link from this vertex to the referenced vertex.
- Parameters:
vertex (
Vertex) – The vertex to be linked to.linkID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, the link’s optional ID for the new link object.linkWeight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, the link’s optional weight for the new link object.linkValue (
Optional[TypeVar(VertexValueType)]) – Optional, the link’s optional value for the new link object.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new link object.
- Return type:
- Returns:
The link object linking this vertex and the referenced vertex.
- Raises:
DuplicateEdgeError – If the given link ID already exists in this graph.
NotInDifferentSubgraphs – If both vertices are in the same subgraph - a link connects vertices across subgraph boundaries.
UseEdgeToVertex()orEdgeFromVertex()to connect vertices within the same subgraph.
See also
EdgeToVertex()→ Create an outbound edge from this vertex to the referenced vertex.
EdgeFromVertex()→ Create an inbound edge from the referenced vertex to this vertex.
EdgeToNewVertex()→ Create a new vertex and link that vertex by an outbound edge from this vertex.
EdgeFromNewVertex()→ Create a new vertex and link that vertex by an inbound edge to this vertex.
LinkFromVertex()→ Create an inbound link from the referenced vertex to this vertex.
- LinkFromVertex(vertex, linkID=None, linkWeight=None, linkValue=None, keyValuePairs=None)[source]
Create an inbound link from the referenced vertex to this vertex.
- Parameters:
vertex (
Vertex) – The vertex to be linked from.linkID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, the link’s optional ID for the new link object.linkWeight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, the link’s optional weight for the new link object.linkValue (
Optional[TypeVar(VertexValueType)]) – Optional, the link’s optional value for the new link object.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs for the new link object.
- Return type:
- Returns:
The link object linking the referenced vertex and this vertex.
- Raises:
DuplicateEdgeError – If the given link ID already exists in this graph.
NotInDifferentSubgraphs – If both vertices are in the same subgraph - a link connects vertices across subgraph boundaries.
UseEdgeToVertex()orEdgeFromVertex()to connect vertices within the same subgraph.
See also
EdgeToVertex()→ Create an outbound edge from this vertex to the referenced vertex.
EdgeFromVertex()→ Create an inbound edge from the referenced vertex to this vertex.
EdgeToNewVertex()→ Create a new vertex and link that vertex by an outbound edge from this vertex.
EdgeFromNewVertex()→ Create a new vertex and link that vertex by an inbound edge to this vertex.
LinkToVertex()→ Create an outbound link from this vertex to the referenced vertex.
- HasEdgeToDestination(destination)[source]
Check if this vertex is linked to another vertex by any outbound edge.
- Parameters:
destination (
Vertex) – Destination vertex to check.- Return type:
- Returns:
True, if the destination vertex is a destination on any outbound edge.
See also
HasEdgeFromSource()→ Check if this vertex is linked to another vertex by any inbound edge.
HasLinkToDestination()→ Check if this vertex is linked to another vertex by any outbound link.
HasLinkFromSource()→ Check if this vertex is linked to another vertex by any inbound link.
- HasEdgeFromSource(source)[source]
Check if this vertex is linked to another vertex by any inbound edge.
- Parameters:
source (
Vertex) – Source vertex to check.- Return type:
- Returns:
True, if the source vertex is a source on any inbound edge.
See also
HasEdgeToDestination()→ Check if this vertex is linked to another vertex by any outbound edge.
HasLinkToDestination()→ Check if this vertex is linked to another vertex by any outbound link.
HasLinkFromSource()→ Check if this vertex is linked to another vertex by any inbound link.
- HasLinkToDestination(destination)[source]
Check if this vertex is linked to another vertex by any outbound link.
- Parameters:
destination (
Vertex) – Destination vertex to check.- Return type:
- Returns:
True, if the destination vertex is a destination on any outbound link.
See also
HasEdgeToDestination()→ Check if this vertex is linked to another vertex by any outbound edge.
HasEdgeFromSource()→ Check if this vertex is linked to another vertex by any inbound edge.
HasLinkFromSource()→ Check if this vertex is linked to another vertex by any inbound link.
- HasLinkFromSource(source)[source]
Check if this vertex is linked to another vertex by any inbound link.
- Parameters:
source (
Vertex) – Source vertex to check.- Return type:
- Returns:
True, if the source vertex is a source on any inbound link.
See also
HasEdgeToDestination()→ Check if this vertex is linked to another vertex by any outbound edge.
HasEdgeFromSource()→ Check if this vertex is linked to another vertex by any inbound edge.
HasLinkToDestination()→ Check if this vertex is linked to another vertex by any outbound link.
- DeleteEdgeTo(destination)[source]
Delete the outbound edge to the given vertex.
- Parameters:
destination (
Vertex) – The vertex the edge points to.- Raises:
GraphException – If no outbound edge to that vertex exists.
- Return type:
- DeleteEdgeFrom(source)[source]
Delete the inbound edge from the given vertex.
- Parameters:
source (
Vertex) – The vertex the edge comes from.- Raises:
GraphException – If no inbound edge from that vertex exists.
- Return type:
- DeleteLinkTo(destination)[source]
Delete the outbound link to the given vertex.
- Parameters:
destination (
Vertex) – The vertex the link points to.- Raises:
GraphException – If no outbound link to that vertex exists.
- Return type:
- DeleteLinkFrom(source)[source]
Delete the inbound link from the given vertex.
- Parameters:
source (
Vertex) – The vertex the link comes from.- Raises:
GraphException – If no inbound link from that vertex exists.
- Return type:
- Copy(graph, copyDict=False, linkingKeyToOriginalVertex=None, linkingKeyFromOriginalVertex=None)[source]
Creates a copy of this vertex in another graph.
Optionally, the vertex’s attached attributes (key-value-pairs) can be copied and a linkage between both vertices can be established.
- Parameters:
graph (
Graph) – Optional, the graph, the vertex is created in.copyDict (
bool) – Optional, ifTrue, copy all attached attributes into the new vertex.linkingKeyToOriginalVertex (
Optional[str]) – Optional, if notNone, add a key-value-pair using this parameter as key from new vertex to the original vertex.linkingKeyFromOriginalVertex (
Optional[str]) – Optional, if notNone, add a key-value-pair using this parameter as key from original vertex to the new vertex.
- Return type:
- Returns:
The newly created vertex.
- Raises:
GraphException – If source graph and destination graph are the same.
- IterateOutboundEdges(predicate=None)[source]
Iterate all or selected outbound edges of this vertex.
If parameter
predicateis not None, the given filter function is used to skip edges in the generator.
- IterateInboundEdges(predicate=None)[source]
Iterate all or selected inbound edges of this vertex.
If parameter
predicateis not None, the given filter function is used to skip edges in the generator.
- IterateOutboundLinks(predicate=None)[source]
Iterate all or selected outbound links of this vertex.
If parameter
predicateis not None, the given filter function is used to skip links in the generator.
- IterateInboundLinks(predicate=None)[source]
Iterate all or selected inbound links of this vertex.
If parameter
predicateis not None, the given filter function is used to skip links in the generator.
- IterateSuccessorVertices(predicate=None)[source]
Iterate all or selected successor vertices of this vertex.
If parameter
predicateis not None, the given filter function is used to skip successors in the generator.
- IteratePredecessorVertices(predicate=None)[source]
Iterate all or selected predecessor vertices of this vertex.
If parameter
predicateis not None, the given filter function is used to skip predecessors in the generator.
- IterateVerticesBFS()[source]
A generator to iterate all reachable vertices starting from this node in breadth-first search (BFS) order.
- Return type:
- Returns:
A generator to iterate vertices traversed in BFS order.
See also
IterateVerticesDFS()→ Iterate all reachable vertices depth-first search order.
- IterateVerticesDFS()[source]
A generator to iterate all reachable vertices starting from this node in depth-first search (DFS) order.
- Return type:
- Returns:
A generator to iterate vertices traversed in DFS order.
See also
IterateVerticesBFS()→ Iterate all reachable vertices breadth-first search order.
Wikipedia - https://en.wikipedia.org/wiki/Depth-first_search
- IterateAllOutboundPathsAsVertexList()[source]
Iterate all paths starting at this vertex, each as a tuple of vertices.
The traversal is depth-first and keeps the vertices of the current path in a set, so a cycle is detected instead of iterated endlessly. A vertex without outbound edges yields the path containing only itself.
- ShortestPathToByHops(destination)[source]
Compute the shortest path (by hops) between this vertex and the destination vertex.
A generator is return to iterate all vertices along the path including source and destination vertex.
The search algorithm is breadth-first search (BFS) based. The found solution, if any, is not unique but deterministic as long as the graph was not modified (e.g. ordering of edges on vertices).
- Parameters:
destination (
Vertex) – The destination vertex to reach.- Return type:
- Returns:
A generator to iterate all vertices on the path found between this vertex and the destination vertex.
- Raises:
DestinationNotReachable – If the destination vertex cannot be reached from this vertex.
- ShortestPathToByWeight(destination)[source]
Compute the shortest path (by edge weight) between this vertex and the destination vertex.
A generator is return to iterate all vertices along the path including source and destination vertex.
The search algorithm is based on Dijkstra algorithm and using
heapq. The found solution, if any, is not unique but deterministic as long as the graph was not modified (e.g. ordering of edges on vertices).- Parameters:
destination (
Vertex) – The destination vertex to reach.- Return type:
- Returns:
A generator to iterate all vertices on the path found between this vertex and the destination vertex.
- Raises:
DestinationNotReachable – If the destination vertex cannot be reached from this vertex.
- ConvertToTree()[source]
Converts all reachable vertices from this starting vertex to a tree of
Nodeinstances.The tree is traversed using depths-first-search.
- Return type:
- Returns:
Root node of the resulting tree, representing this vertex.
- Raises:
NotATreeError – If the graph reachable from this vertex is not a tree, because a vertex has more than one parent.
- __repr__()[source]
Returns a detailed string representation of the vertex.
- Return type:
- Returns:
The detailed string representation of the vertex.
- __str__()[source]
Return a string representation of the vertex.
Order of resolution:
If
_valueis not None, return the string representation of_value.If
_idis not None, return the string representation of_id.Else, return
__repr__().
- Return type:
- Returns:
The resolved string representation of the vertex.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property ID: IDType | None
Read-only property to access the unique ID (
_id).If no ID was given at creation time, ID returns
None.- Returns:
Unique ID, if ID was given at creation time, else
None.
- property Weight: EdgeWeightType | None
Property to get and set the weight (
_weight) of an edge.- Returns:
The weight of an edge.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- _dict
A dictionary to store arbitrary key-value-pairs.
- _id
Field storing the object’s Identifier.
- _value
Field storing the object’s value of any type.
- _weight
Field storing the object’s weight.
- class pyTooling.Graph.BaseEdge[source]
An edge can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All edges are directed.
Inheritance
- __init__(source, destination, edgeID=None, value=None, weight=None, keyValuePairs=None)[source]
Initialize an edge between a source and a destination vertex.
- Parameters:
source (
Vertex) – The source of the new edge.destination (
Vertex) – The destination of the new edge.edgeID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, unique ID for the new edge.value (
Optional[TypeVar(EdgeValueType)]) – Optional, value for the new edge.weight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, weight for the new edge.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs.
- Return type:
None
- property Source: Vertex
Read-only property to get the source (
_source) of an edge.- Returns:
The source of an edge.
- property Destination: Vertex
Read-only property to get the destination (
_destination) of an edge.- Returns:
The destination of an edge.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property ID: IDType | None
Read-only property to access the unique ID (
_id).If no ID was given at creation time, ID returns
None.- Returns:
Unique ID, if ID was given at creation time, else
None.
- property Weight: EdgeWeightType | None
Property to get and set the weight (
_weight) of an edge.- Returns:
The weight of an edge.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- class pyTooling.Graph.Edge[source]
An edge can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All edges are directed.
Inheritance
- __init__(source, destination, edgeID=None, value=None, weight=None, keyValuePairs=None)[source]
Initialize an edge between two vertices of the same graph or subgraph.
- Parameters:
source (
Vertex) – The source of the new edge.destination (
Vertex) – The destination of the new edge.edgeID (
Optional[TypeVar(EdgeIDType, bound=Hashable)]) – Optional, unique ID for the new edge.value (
Optional[TypeVar(EdgeValueType)]) – Optional, value for the new edge.weight (
Optional[TypeVar(EdgeWeightType, bound=Union[int,float])]) – Optional, weight for the new edge.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs.
- Raises:
TypeError – If parameter ‘weight’ is not of the graph’s edge weight type.
NotInSameGraph – If source and destination vertex are not in the same graph or subgraph.
- Return type:
None
- Delete()[source]
Delete this edge from both of its vertices and from the graph or subgraph it belongs to.
- Return type:
- _Unregister()[source]
Remove this edge from the graph or subgraph it was registered on.
An edge is registered on the subgraph it lives in, otherwise on the graph. Called by
Delete()and byVertex.Delete(), which unlinks the vertices itself.- Return type:
- property Destination: Vertex
Read-only property to get the destination (
_destination) of an edge.- Returns:
The destination of an edge.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property ID: IDType | None
Read-only property to access the unique ID (
_id).If no ID was given at creation time, ID returns
None.- Returns:
Unique ID, if ID was given at creation time, else
None.
- property Source: Vertex
Read-only property to get the source (
_source) of an edge.- Returns:
The source of an edge.
- property Weight: EdgeWeightType | None
Property to get and set the weight (
_weight) of an edge.- Returns:
The weight of an edge.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- class pyTooling.Graph.Link[source]
A link can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All links are directed.
Inheritance
- __init__(source, destination, linkID=None, value=None, weight=None, keyValuePairs=None)[source]
Initialize a link between two vertices of different subgraphs.
- Parameters:
source (
Vertex) – The source of the new link.destination (
Vertex) – The destination of the new link.linkID (
TypeVar(LinkIDType, bound=Hashable)) – Optional, unique ID for the new link.value (
TypeVar(LinkValueType)) – Optional, value for the new v.weight (
Optional[TypeVar(LinkWeightType, bound=Union[int,float])]) – Optional, weight for the new link.keyValuePairs (
Optional[Mapping[TypeVar(DictKeyType, bound=Hashable),TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs.
- Raises:
TypeError – If parameter ‘weight’ is not of the graph’s link weight type.
NotInSameGraph – If source and destination vertex are in the same subgraph, where an edge is to be used.
- Return type:
None
- Delete()[source]
Delete this link from both of its vertices and from the graph and subgraphs it belongs to.
- Return type:
- _Unregister()[source]
Remove this link from the graph or the subgraphs it was registered on.
A link crossing a subgraph boundary is registered on both subgraphs, a link between two top-level vertices on the graph. Called by
Delete()and byVertex.Delete(), which unlinks the vertices itself.- Return type:
- property Destination: Vertex
Read-only property to get the destination (
_destination) of an edge.- Returns:
The destination of an edge.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property ID: IDType | None
Read-only property to access the unique ID (
_id).If no ID was given at creation time, ID returns
None.- Returns:
Unique ID, if ID was given at creation time, else
None.
- property Source: Vertex
Read-only property to get the source (
_source) of an edge.- Returns:
The source of an edge.
- property Weight: EdgeWeightType | None
Property to get and set the weight (
_weight) of an edge.- Returns:
The weight of an edge.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- class pyTooling.Graph.BaseGraph[source]
Todo
GRAPH::BaseGraph Needs documentation.
Inheritance
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property Name: str | None
Property to access the name (
_name).- Returns:
The object’s name, or
Noneif it has none.- Raises:
TypeError – If an assigned value is not of type string.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- _verticesWithoutID: list[Vertex[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Vertices without an ID, in insertion order.
- _verticesWithID: dict[VertexIDType, Vertex[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Vertices with an ID, by ID.
- _edgesWithoutID: list[Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Edges without an ID, in insertion order.
- _edgesWithID: dict[EdgeIDType, Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Edges with an ID, by ID.
- _linksWithoutID: list[Link[LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Links between subgraphs without an ID, in insertion order.
- _linksWithID: dict[EdgeIDType, Link[LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Links between subgraphs with an ID, by ID.
- property VertexCount: int
Read-only property to return the number of vertices in this graph.
- Returns:
The number of vertices in this graph.
- property EdgeCount: int
Read-only property to return the number of edges in this graph.
- Returns:
The number of edges in this graph.
- property LinkCount: int
Read-only property to return the number of links in this graph.
- Returns:
The number of links in this graph.
- IterateVertices(predicate=None)[source]
Iterate all or selected vertices of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices.
- IterateRoots(predicate=None)[source]
Iterate all or selected roots (vertices without inbound edges / without predecessors) of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices without inbound edges.
See also
BaseGraph.IterateLeafs→ Iterate leafs of a graph.
Vertex.IsRoot→ Check if a vertex is a root vertex in the graph.
Vertex.IsLeaf→ Check if a vertex is a leaf vertex in the graph.
- IterateLeafs(predicate=None)[source]
Iterate all or selected leafs (vertices without outbound edges / without successors) of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices without outbound edges.
See also
BaseGraph.IterateRoots→ Iterate roots of a graph.
Vertex.IsRoot→ Check if a vertex is a root vertex in the graph.
Vertex.IsLeaf→ Check if a vertex is a leaf vertex in the graph.
- IterateTopologically(predicate=None)[source]
Iterate all or selected vertices in topological order.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices in topological order.
- Raises:
CycleError – If the graph contains a cycle, so no topological order exists.
InternalError – If the algorithm’s internal state became inconsistent.
CycleError – Raised if graph is cyclic, thus topological sorting isn’t possible.
- IterateEdges(predicate=None)[source]
Iterate all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges in the generator.- Parameters:
predicate (
Optional[Callable[[Edge],bool]]) – Optional, filter function accepting any edge and returning a boolean.- Return type:
Generator[Edge[TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType)],None,None]- Returns:
A generator to iterate all edges.
- IterateLinks(predicate=None)[source]
Iterate all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links in the generator.- Parameters:
predicate (
Optional[Callable[[Link],bool]]) – Optional, filter function accepting any link and returning a boolean.- Return type:
Generator[Link[TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all links.
- ReverseEdges(predicate=None)[source]
Reverse all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges.
- ReverseLinks(predicate=None)[source]
Reverse all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links.
- RemoveEdges(predicate=None)[source]
Remove all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges.
- RemoveLinks(predicate=None)[source]
Remove all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links.
- HasCycle()[source]
Check if the graph contains at least one cycle.
The graph is traversed depth-first from every unvisited vertex; a vertex reached again while it is still on the current path closes a cycle.
- Return type:
- Returns:
True, if the graph contains a cycle.- Raises:
InternalError – If the graph’s data structure is corrupted.
- class pyTooling.Graph.Subgraph[source]
Todo
GRAPH::Subgraph Needs documentation.
Inheritance
- property EdgeCount: int
Read-only property to return the number of edges in this graph.
- Returns:
The number of edges in this graph.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- HasCycle()
Check if the graph contains at least one cycle.
The graph is traversed depth-first from every unvisited vertex; a vertex reached again while it is still on the current path closes a cycle.
- Return type:
- Returns:
True, if the graph contains a cycle.- Raises:
InternalError – If the graph’s data structure is corrupted.
- IterateEdges(predicate=None)
Iterate all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges in the generator.- Parameters:
predicate (
Optional[Callable[[Edge],bool]]) – Optional, filter function accepting any edge and returning a boolean.- Return type:
Generator[Edge[TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType)],None,None]- Returns:
A generator to iterate all edges.
- IterateLeafs(predicate=None)
Iterate all or selected leafs (vertices without outbound edges / without successors) of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices without outbound edges.
See also
BaseGraph.IterateRoots→ Iterate roots of a graph.
Vertex.IsRoot→ Check if a vertex is a root vertex in the graph.
Vertex.IsLeaf→ Check if a vertex is a leaf vertex in the graph.
- IterateLinks(predicate=None)
Iterate all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links in the generator.- Parameters:
predicate (
Optional[Callable[[Link],bool]]) – Optional, filter function accepting any link and returning a boolean.- Return type:
Generator[Link[TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all links.
- IterateRoots(predicate=None)
Iterate all or selected roots (vertices without inbound edges / without predecessors) of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices without inbound edges.
See also
BaseGraph.IterateLeafs→ Iterate leafs of a graph.
Vertex.IsRoot→ Check if a vertex is a root vertex in the graph.
Vertex.IsLeaf→ Check if a vertex is a leaf vertex in the graph.
- IterateTopologically(predicate=None)
Iterate all or selected vertices in topological order.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices in topological order.
- Raises:
CycleError – If the graph contains a cycle, so no topological order exists.
InternalError – If the algorithm’s internal state became inconsistent.
CycleError – Raised if graph is cyclic, thus topological sorting isn’t possible.
- IterateVertices(predicate=None)
Iterate all or selected vertices of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices.
- property LinkCount: int
Read-only property to return the number of links in this graph.
- Returns:
The number of links in this graph.
- property Name: str | None
Property to access the name (
_name).- Returns:
The object’s name, or
Noneif it has none.- Raises:
TypeError – If an assigned value is not of type string.
- RemoveEdges(predicate=None)
Remove all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges.
- RemoveLinks(predicate=None)
Remove all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links.
- ReverseEdges(predicate=None)
Reverse all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges.
- ReverseLinks(predicate=None)
Reverse all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links.
- property VertexCount: int
Read-only property to return the number of vertices in this graph.
- Returns:
The number of vertices in this graph.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- _edgesWithID: dict[EdgeIDType, Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Edges with an ID, by ID.
- _edgesWithoutID: list[Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Edges without an ID, in insertion order.
- _linksWithID: dict[EdgeIDType, Link[LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Links between subgraphs with an ID, by ID.
- _linksWithoutID: list[Link[LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Links between subgraphs without an ID, in insertion order.
- _verticesWithID: dict[VertexIDType, Vertex[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Vertices with an ID, by ID.
- _verticesWithoutID: list[Vertex[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Vertices without an ID, in insertion order.
- __init__(graph, name=None, keyValuePairs=None)[source]
Initialize a subgraph and register it at its graph.
- Parameters:
- Raises:
ValueError – If parameter ‘graph’ is None.
- Return type:
None
- class pyTooling.Graph.View[source]
Todo
GRAPH::View Needs documentation.
Inheritance
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property Graph: Graph
Read-only property to access the graph, this object is associated to (
_graph).- Returns:
The graph this object is associated to.
- property Name: str | None
Property to access the name (
_name).- Returns:
The object’s name, or
Noneif it has none.- Raises:
TypeError – If an assigned value is not of type string.
- property VertexCount: int
Read-only property to return the number of vertices referenced by this object.
- Returns:
The number of vertices this object references.
- property Vertices: set[Vertex]
Read-only property to access the vertices in this component (
_vertices).- Returns:
The set of vertices in this component.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- _dict
A dictionary to store arbitrary key-value-pairs.
- _graph
Field storing a reference to the graph.
- _name
Field storing the object’s name.
- _vertices
Field storing a set of vertices.
- __init__(graph, name=None, vertices=None, keyValuePairs=None)[source]
Todo
GRAPH::View::init Needs documentation.
- Parameters:
- Return type:
None
- class pyTooling.Graph.Component[source]
Todo
GRAPH::Component Needs documentation.
Inheritance
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- property Graph: Graph
Read-only property to access the graph, this object is associated to (
_graph).- Returns:
The graph this object is associated to.
- property Name: str | None
Property to access the name (
_name).- Returns:
The object’s name, or
Noneif it has none.- Raises:
TypeError – If an assigned value is not of type string.
- property VertexCount: int
Read-only property to return the number of vertices referenced by this object.
- Returns:
The number of vertices this object references.
- property Vertices: set[Vertex]
Read-only property to access the vertices in this component (
_vertices).- Returns:
The set of vertices in this component.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- _dict
A dictionary to store arbitrary key-value-pairs.
- _graph
Field storing a reference to the graph.
- _name
Field storing the object’s name.
- _vertices
Field storing a set of vertices.
- __init__(graph, name=None, vertices=None, keyValuePairs=None)[source]
Initialize a component of a graph and register it at that graph.
- Parameters:
- Return type:
None
- class pyTooling.Graph.Graph[source]
A graph data structure is represented by an instance of
Graphholding references to all nodes. Nodes are instances ofVertexclasses and directed links between nodes are made ofEdgeinstances. A graph can have attached meta information as key-value-pairs.Inheritance
- property EdgeCount: int
Read-only property to return the number of edges in this graph.
- Returns:
The number of edges in this graph.
- classmethod GetMethodsWithAttributes(predicate: Nullable[TAttributeFilter[TAttr]] = None) dict[Callable[..., Any], tuple[Attribute, ...]]
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (Nullable[TAttributeFilter[TAttr]]) – Optional, an attribute class, an iterable of attribute classes, or
Noneto accept every attribute.- Return type:
dict[Callable[…, Any], tuple[Attribute, …]]
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- HasCycle()
Check if the graph contains at least one cycle.
The graph is traversed depth-first from every unvisited vertex; a vertex reached again while it is still on the current path closes a cycle.
- Return type:
- Returns:
True, if the graph contains a cycle.- Raises:
InternalError – If the graph’s data structure is corrupted.
- IterateEdges(predicate=None)
Iterate all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges in the generator.- Parameters:
predicate (
Optional[Callable[[Edge],bool]]) – Optional, filter function accepting any edge and returning a boolean.- Return type:
Generator[Edge[TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType)],None,None]- Returns:
A generator to iterate all edges.
- IterateLeafs(predicate=None)
Iterate all or selected leafs (vertices without outbound edges / without successors) of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices without outbound edges.
See also
BaseGraph.IterateRoots→ Iterate roots of a graph.
Vertex.IsRoot→ Check if a vertex is a root vertex in the graph.
Vertex.IsLeaf→ Check if a vertex is a leaf vertex in the graph.
- IterateLinks(predicate=None)
Iterate all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links in the generator.- Parameters:
predicate (
Optional[Callable[[Link],bool]]) – Optional, filter function accepting any link and returning a boolean.- Return type:
Generator[Link[TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all links.
- IterateRoots(predicate=None)
Iterate all or selected roots (vertices without inbound edges / without predecessors) of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices without inbound edges.
See also
BaseGraph.IterateLeafs→ Iterate leafs of a graph.
Vertex.IsRoot→ Check if a vertex is a root vertex in the graph.
Vertex.IsLeaf→ Check if a vertex is a leaf vertex in the graph.
- IterateTopologically(predicate=None)
Iterate all or selected vertices in topological order.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices in topological order.
- Raises:
CycleError – If the graph contains a cycle, so no topological order exists.
InternalError – If the algorithm’s internal state became inconsistent.
CycleError – Raised if graph is cyclic, thus topological sorting isn’t possible.
- IterateVertices(predicate=None)
Iterate all or selected vertices of a graph.
If parameter
predicateis not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.- Return type:
Generator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)],None,None]- Returns:
A generator to iterate all vertices.
- property LinkCount: int
Read-only property to return the number of links in this graph.
- Returns:
The number of links in this graph.
- property Name: str | None
Property to access the name (
_name).- Returns:
The object’s name, or
Noneif it has none.- Raises:
TypeError – If an assigned value is not of type string.
- RemoveEdges(predicate=None)
Remove all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges.
- RemoveLinks(predicate=None)
Remove all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links.
- ReverseEdges(predicate=None)
Reverse all or selected edges of a graph.
If parameter
predicateis not None, the given filter function is used to skip edges.
- ReverseLinks(predicate=None)
Reverse all or selected links of a graph.
If parameter
predicateis not None, the given filter function is used to skip links.
- property VertexCount: int
Read-only property to return the number of vertices in this graph.
- Returns:
The number of vertices in this graph.
- __contains__(key)
Checks if the key is an attached attribute (key-value-pairs) on this vertex.
- __delitem__(key)
Remove an entry from vertex’s attached attributes (key-value-pairs) by key.
- __getitem__(key)
Read a vertex’s attached attributes (key-value-pairs) by key.
- __getstate__() dict[str, Any]
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- Return type:
- Returns:
Dictionary of slot names and their values.
- Raises:
ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.
- __len__()
Returns the number of attached attributes (key-value-pairs) on this vertex.
- Return type:
- Returns:
Number of attached attributes.
- __setitem__(key, value)
Create or update a vertex’s attached attributes (key-value-pairs) by key.
If a key doesn’t exist yet, a new key-value-pair is created.
- __setstate__(state: dict[str, Any]) None
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- Parameters:
state (
dict[str,Any]) – Dictionary of slot names and their values.- Raises:
ExtendedTypeError – If the given state misses a slot or carries an unexpected one.
- Return type:
- _edgesWithID: dict[EdgeIDType, Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Edges with an ID, by ID.
- _edgesWithoutID: list[Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]
Edges without an ID, in insertion order.
- _linksWithID: dict[EdgeIDType, Link[LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Links between subgraphs with an ID, by ID.
- _linksWithoutID: list[Link[LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Links between subgraphs without an ID, in insertion order.
- _verticesWithID: dict[VertexIDType, Vertex[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Vertices with an ID, by ID.
- _verticesWithoutID: list[Vertex[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Vertices without an ID, in insertion order.
- _subgraphs: set[Subgraph[SubgraphDictKeyType, SubgraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Subgraphs of this graph.
- _views: set[View[ViewDictKeyType, ViewDictValueType, GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Views defined on this graph.
- _components: set[Component[ComponentDictKeyType, ComponentDictValueType, GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType, LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]]
Connected components of this graph.
- property Subgraphs: set[Subgraph]
Read-only property to access the subgraphs in this graph (
_subgraphs).- Returns:
The set of subgraphs in this graph.
- property Views: set[View]
Read-only property to access the views in this graph (
_views).- Returns:
The set of views in this graph.
- property Components: set[Component]
Read-only property to access the components in this graph (
_components).- Returns:
The set of components in this graph.
- property SubgraphCount: int
Read-only property to return the number of subgraphs in this graph.
- Returns:
The number of subgraphs in this graph.
- property ViewCount: int
Read-only property to return the number of views in this graph.
- Returns:
The number of views in this graph.
- property ComponentCount: int
Read-only property to return the number of components in this graph.
- Returns:
The number of components in this graph.
- __iter__()[source]
Iterate all vertices of this graph.
- Return type:
Iterator[Vertex[TypeVar(GraphDictKeyType, bound=Hashable),TypeVar(GraphDictValueType),TypeVar(VertexIDType, bound=Hashable),TypeVar(VertexWeightType, bound=Union[int,float]),TypeVar(VertexValueType),TypeVar(VertexDictKeyType, bound=Hashable),TypeVar(VertexDictValueType),TypeVar(EdgeIDType, bound=Hashable),TypeVar(EdgeWeightType, bound=Union[int,float]),TypeVar(EdgeValueType),TypeVar(EdgeDictKeyType, bound=Hashable),TypeVar(EdgeDictValueType),TypeVar(LinkIDType, bound=Hashable),TypeVar(LinkWeightType, bound=Union[int,float]),TypeVar(LinkValueType),TypeVar(LinkDictKeyType, bound=Hashable),TypeVar(LinkDictValueType)]]- Returns:
An iterator over the vertices without an ID, followed by those with one.
- GetVertexByID(vertexID)[source]
Return the vertex with the given ID.
A vertex created without an ID can be looked up with
None, provided it is the only such vertex.
- CopyGraph()[source]
Create a copy of this graph.
- Return type:
- Returns:
A new graph with copies of this graph’s vertices and edges.
- Raises:
NotImplementedError – Copying a whole graph is not implemented yet.
- CopyVertices(predicate=None, copyGraphDict=True, copyVertexDict=True)[source]
Create a new graph and copy all or selected vertices of the original graph.
If parameter
predicateis not None, the given filter function is used to skip vertices.- Parameters:
predicate (
Optional[Callable[[Vertex],bool]]) – Optional, filter function accepting any vertex and returning a boolean.copyGraphDict (
bool) – Optional, ifTrue, copy all graph attached attributes into the new graph.copyVertexDict (
bool) – Optional, ifTrue, copy all vertex attached attributes into the new vertices.
- Return type:
- Returns:
A new graph with copies of the selected vertices.