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
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.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
: Abstract base class for generic types.BaseWithIDValueAndWeight
: Abstract base class for generic types.BaseWithName
: Abstract base class for generic types.BaseWithVertices
: Abstract base class for generic types.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 ofGraph
holding references to
Exceptions
- exception pyTooling.Graph.GraphException[source]
Base exception of all exceptions raised by
pyTooling.Graph
.Inheritance
- 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
- 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
- exception pyTooling.Graph.DuplicateVertexError[source]
The exception is raised when the vertex already exists in the graph.
Inheritance
- exception pyTooling.Graph.DuplicateEdgeError[source]
The exception is raised when the edge already exists in the graph.
Inheritance
- exception pyTooling.Graph.DestinationNotReachable[source]
The exception is raised when a destination vertex is not reachable.
Inheritance
- 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
- exception pyTooling.Graph.CycleError[source]
The exception is raised when a not permitted cycle is found.
Inheritance
Classes
- class pyTooling.Graph.Base[source]
Inheritance
-
_dict:
Dict
[TypeVar
(DictKeyType
, bound=Hashable
),TypeVar
(DictValueType
)] Dictionary to store key-value-pairs.
- __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]
Returns 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.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __init_subclass__()
Function to initialize subclasses.
-
_dict:
- class pyTooling.Graph.BaseWithIDValueAndWeight(identifier=None, value=None, weight=None)[source]
Inheritance
- Parameters:
identifier (IDType | None)
value (ValueType | None)
weight (WeightType | None)
- __init__(identifier=None, value=None, weight=None)[source]
Todo
GRAPH::Vertex::init Needs documentation.
- Parameters:
identifier (IDType | None)
value (ValueType | None)
weight (WeightType | None)
- Return type:
None
-
_weight:
Optional
[TypeVar
(WeightType
, bound=Union
[int
,float
])] Field storing the object’s weight.
- 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.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns if the key is an attached attribute (key-value-pairs) on this vertex.
- __del__()
Todo
GRAPH::Base::del Needs documentation.
- __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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- class pyTooling.Graph.BaseWithName(name=None)[source]
Inheritance
- Parameters:
name (str | None)
- __init__(name=None)[source]
Todo
GRAPH::BaseWithName::init Needs documentation.
- Parameters:
name (str | None)
- Return type:
None
- property Name: str | None
Property to get and set the name (
_name
).- Returns:
The value of a component.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns if the key is an attached attribute (key-value-pairs) on this vertex.
- __del__()
Todo
GRAPH::Base::del Needs documentation.
- __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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- class pyTooling.Graph.BaseWithVertices(graph, name=None, vertices=None)[source]
Inheritance
- _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 access the number of vertices referenced by this object.
- Returns:
The number of vertices this object references.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- property Name: str | None
Property to get and set the name (
_name
).- Returns:
The value of a component.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns 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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- _dict: Dict[DictKeyType, DictValueType]
Dictionary to store key-value-pairs.
- _name: Nullable[str]
Field storing the object’s name.
- class pyTooling.Graph.Vertex(vertexID=None, value=None, weight=None, graph=None, subgraph=None)[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
- Parameters:
- __init__(vertexID=None, value=None, weight=None, graph=None, subgraph=None)[source]
Todo
GRAPH::Vertex::init Needs documentation.
- _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.
- 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
IsLeaf()
→ Check if a vertex is a leaf vertex in the graph.
Graph.IterateRoots
→ Iterate all roots of a graph.
Graph.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
IsRoot()
→ Check if a vertex is a root vertex in the graph.
Graph.IterateRoots
→ Iterate all roots of a graph.
Graph.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)[source]
Todo
GRAPH::Vertex::EdgeToVertex Needs documentation.
- EdgeFromVertex(vertex, edgeID=None, edgeWeight=None, edgeValue=None)[source]
Todo
GRAPH::Vertex::EdgeFromVertex Needs documentation.
- EdgeToNewVertex(vertexID=None, vertexValue=None, vertexWeight=None, edgeID=None, edgeWeight=None, edgeValue=None)[source]
Todo
GRAPH::Vertex::EdgeToNewVertex Needs documentation.
- Return type:
- Parameters:
vertexID (VertexIDType | None)
vertexValue (VertexValueType | None)
vertexWeight (VertexWeightType | None)
edgeID (EdgeIDType | None)
edgeWeight (EdgeWeightType | None)
edgeValue (VertexValueType | None)
- EdgeFromNewVertex(vertexID=None, vertexValue=None, vertexWeight=None, edgeID=None, edgeWeight=None, edgeValue=None)[source]
Todo
GRAPH::Vertex::EdgeFromNewVertex Needs documentation.
- Return type:
- Parameters:
vertexID (VertexIDType | None)
vertexValue (VertexValueType | None)
vertexWeight (VertexWeightType | None)
edgeID (EdgeIDType | None)
edgeWeight (EdgeWeightType | None)
edgeValue (VertexValueType | None)
- LinkToVertex(vertex, linkID=None, linkWeight=None, linkValue=None)[source]
Todo
GRAPH::Vertex::LinkToVertex Needs documentation.
- LinkFromVertex(vertex, linkID=None, linkWeight=None, linkValue=None)[source]
Todo
GRAPH::Vertex::LinkToVertex Needs documentation.
- 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.
- 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 (<property object at 0x7f163ed31f80>) – The graph, the vertex is created in.
copyDict (
bool
) – IfTrue
, copy all attached attributes into the new vertex.linkingKeyToOriginalVertex (
Optional
[str
]) – If notNone
, add a key-value-pair using this parameter as key from new vertex to the original vertex.linkingKeyFromOriginalVertex (
Optional
[str
]) – 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
predicate
is 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
predicate
is 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
predicate
is 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
predicate
is 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
predicate
is 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
predicate
is 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
- 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).
- 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).
- ConvertToTree()[source]
Converts all reachable vertices from this starting vertex to a tree of
Node
instances.The tree is traversed using depths-first-search.
- Return type:
- Returns:
- __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
_value
is not None, return the string representation of_value
.If
_id
is not None, return the string representation of_id
.Else, return
__repr__()
.
- Return type:
- Returns:
The resolved string representation of the vertex.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- 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.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns 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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- _dict: Dict[DictKeyType, DictValueType]
Dictionary to store key-value-pairs.
- _id: Nullable[IDType]
Field storing the object’s Identifier.
- _value: Nullable[ValueType]
Field storing the object’s value of any type.
- _weight: Nullable[WeightType]
Field storing the object’s weight.
- class pyTooling.Graph.BaseEdge(source, destination, edgeID=None, value=None, weight=None)[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
- Parameters:
- __init__(source, destination, edgeID=None, value=None, weight=None)[source]
Todo
GRAPH::BaseEdge::init Needs documentation.
- 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.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- 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.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns if the key is an attached attribute (key-value-pairs) on this vertex.
- __del__()
Todo
GRAPH::Base::del Needs documentation.
- __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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- class pyTooling.Graph.Edge(source, destination, edgeID=None, value=None, weight=None)[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
- Parameters:
- __init__(source, destination, edgeID=None, value=None, weight=None)[source]
Todo
GRAPH::Edge::init Needs documentation.
- property Destination: Vertex
Read-only property to get the destination (
_destination
) of an edge.- Returns:
The destination of an edge.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- 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.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns if the key is an attached attribute (key-value-pairs) on this vertex.
- __del__()
Todo
GRAPH::Base::del Needs documentation.
- __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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- class pyTooling.Graph.Link(source, destination, linkID=None, value=None, weight=None)[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
- Parameters:
- __init__(source, destination, linkID=None, value=None, weight=None)[source]
Todo
GRAPH::Edge::init Needs documentation.
- property Destination: Vertex
Read-only property to get the destination (
_destination
) of an edge.- Returns:
The destination of an edge.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- 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.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns if the key is an attached attribute (key-value-pairs) on this vertex.
- __del__()
Todo
GRAPH::Base::del Needs documentation.
- __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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- class pyTooling.Graph.BaseGraph(name=None)[source]
Todo
GRAPH::BaseGraph Needs documentation.
Inheritance
- Parameters:
name (str | None)
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- property Name: str | None
Property to get and set the name (
_name
).- Returns:
The value of a component.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns 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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
-
_dict:
Dict
[TypeVar
(DictKeyType
, bound=Hashable
),TypeVar
(DictValueType
)] Dictionary to store key-value-pairs.
- __init__(name=None)[source]
Todo
GRAPH::BaseGraph::init Needs documentation.
- Parameters:
name (str | None)
- property VertexCount: int
Read-only property to access the number of vertices in this graph.
- Returns:
The number of vertices in this graph.
- property EdgeCount: int
Read-only property to access the number of edges in this graph.
- Returns:
The number of edges in this graph.
- property LinkCount: int
Read-only property to access 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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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
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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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
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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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 – 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
predicate
is not None, the given filter function is used to skip edges in the generator.- Parameters:
predicate (
Optional
[Callable
[[Edge
],bool
]]) – 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
predicate
is not None, the given filter function is used to skip links in the generator.- Parameters:
predicate (
Optional
[Callable
[[Link
],bool
]]) – 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
predicate
is 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
predicate
is 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
predicate
is not None, the given filter function is used to skip edges.
- class pyTooling.Graph.Subgraph(graph, name=None, vertices=None)[source]
Todo
GRAPH::Subgraph Needs documentation.
Inheritance
- property EdgeCount: int
Read-only property to access the number of edges in this graph.
- Returns:
The number of edges in this graph.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- IterateEdges(predicate=None)
Iterate all or selected edges of a graph.
If parameter
predicate
is not None, the given filter function is used to skip edges in the generator.- Parameters:
predicate (
Optional
[Callable
[[Edge
],bool
]]) – 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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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
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
predicate
is not None, the given filter function is used to skip links in the generator.- Parameters:
predicate (
Optional
[Callable
[[Link
],bool
]]) – 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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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
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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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 – Raised if graph is cyclic, thus topological sorting isn’t possible.
- IterateVertices(predicate=None)
Iterate all or selected vertices of a graph.
If parameter
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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 access the number of links in this graph.
- Returns:
The number of links in this graph.
- property Name: str | None
Property to get and set the name (
_name
).- Returns:
The value of a component.
- RemoveEdges(predicate=None)
Remove all or selected edges of a graph.
If parameter
predicate
is not None, the given filter function is used to skip edges.
- RemoveLinks(predicate=None)
Remove all or selected links of a graph.
If parameter
predicate
is not None, the given filter function is used to skip links.
- ReverseEdges(predicate=None)
Reverse all or selected edges of a graph.
If parameter
predicate
is not None, the given filter function is used to skip edges.
- ReverseLinks(predicate=None)
Reverse all or selected links of a graph.
If parameter
predicate
is not None, the given filter function is used to skip links.
- property VertexCount: int
Read-only property to access the number of vertices in this graph.
- Returns:
The number of vertices in this graph.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns 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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
-
_dict:
Dict
[TypeVar
(DictKeyType
, bound=Hashable
),TypeVar
(DictValueType
)] Dictionary to store key-value-pairs.
- class pyTooling.Graph.View(graph, name=None, vertices=None)[source]
Todo
GRAPH::View Needs documentation.
Inheritance
- property Graph: Graph
Read-only property to access the graph, this object is associated to (
_graph
).- Returns:
The graph this object is associated to.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- property Name: str | None
Property to get and set the name (
_name
).- Returns:
The value of a component.
- property VertexCount: int
Read-only property to access 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.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns 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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- _dict: Dict[DictKeyType, DictValueType]
Dictionary to store key-value-pairs.
- _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.
- _name: Nullable[str]
Field storing the object’s name.
- _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.
- class pyTooling.Graph.Component(graph, name=None, vertices=None)[source]
Todo
GRAPH::Component Needs documentation.
Inheritance
- property Graph: Graph
Read-only property to access the graph, this object is associated to (
_graph
).- Returns:
The graph this object is associated to.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- property Name: str | None
Property to get and set the name (
_name
).- Returns:
The value of a component.
- property VertexCount: int
Read-only property to access 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.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns 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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
- _dict: Dict[DictKeyType, DictValueType]
Dictionary to store key-value-pairs.
- _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.
- _name: Nullable[str]
Field storing the object’s name.
- _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.
- class pyTooling.Graph.Graph(name=None)[source]
A graph data structure is represented by an instance of
Graph
holding references to all nodes. Nodes are instances ofVertex
classes and directed links between nodes are made ofEdge
instances. A graph can have attached meta information as key-value-pairs.Inheritance
- Parameters:
name (str | None)
- property EdgeCount: int
Read-only property to access the number of edges in this graph.
- Returns:
The number of edges in this graph.
- class property HasClassAttributes: bool
Check if class has Attributes.
- Returns:
True
, if the class has Attributes.
- class property HasMethodAttributes: bool
Check if class has any method with Attributes.
- Returns:
True
, if the class has any method with Attributes.
- IterateEdges(predicate=None)
Iterate all or selected edges of a graph.
If parameter
predicate
is not None, the given filter function is used to skip edges in the generator.- Parameters:
predicate (
Optional
[Callable
[[Edge
],bool
]]) – 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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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
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
predicate
is not None, the given filter function is used to skip links in the generator.- Parameters:
predicate (
Optional
[Callable
[[Link
],bool
]]) – 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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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
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
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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 – Raised if graph is cyclic, thus topological sorting isn’t possible.
- IterateVertices(predicate=None)
Iterate all or selected vertices of a graph.
If parameter
predicate
is not None, the given filter function is used to skip vertices in the generator.- Parameters:
predicate (
Optional
[Callable
[[Vertex
],bool
]]) – 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 access the number of links in this graph.
- Returns:
The number of links in this graph.
- property Name: str | None
Property to get and set the name (
_name
).- Returns:
The value of a component.
- RemoveEdges(predicate=None)
Remove all or selected edges of a graph.
If parameter
predicate
is not None, the given filter function is used to skip edges.
- RemoveLinks(predicate=None)
Remove all or selected links of a graph.
If parameter
predicate
is not None, the given filter function is used to skip links.
- ReverseEdges(predicate=None)
Reverse all or selected edges of a graph.
If parameter
predicate
is not None, the given filter function is used to skip edges.
- ReverseLinks(predicate=None)
Reverse all or selected links of a graph.
If parameter
predicate
is not None, the given filter function is used to skip links.
- property VertexCount: int
Read-only property to access the number of vertices in this graph.
- Returns:
The number of vertices in this graph.
- __class_getitem__()
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.
However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….
- __contains__(key)
Returns 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.
- __init_subclass__()
Function to initialize subclasses.
- __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.
-
_dict:
Dict
[TypeVar
(DictKeyType
, bound=Hashable
),TypeVar
(DictValueType
)] Dictionary to store key-value-pairs.
- __init__(name=None)[source]
Todo
GRAPH::Graph::init Needs documentation.
- Parameters:
name (str | None)
- Return type:
None
- 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 access the number of subgraphs in this graph.
- Returns:
The number of subgraphs in this graph.
- property ViewCount: int
Read-only property to access the number of views in this graph.
- Returns:
The number of views in this graph.
- property ComponentCount: int
Read-only property to access the number of components in this graph.
- Returns:
The number of components in this graph.
- __iter__()[source]
Todo
GRAPH::Graph::iter Needs documentation.
- 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
)]]
- GetVertexByID(vertexID)[source]
Todo
GRAPH::Graph::GetVertexByID Needs documentation.
- Return type:
- Parameters:
vertexID (VertexIDType | None)
- GetVertexByValue(value)[source]
Todo
GRAPH::Graph::GetVertexByValue Needs documentation.
- Return type: