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 by pyTooling.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 references

  • BaseEdge: An edge can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All edges are

  • Edge: An edge can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All edges are

  • Link: A link can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All links are

  • BaseGraph: .. 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 of Graph holding references to


Exceptions

exception pyTooling.Graph.GraphException[source]

Base exception of all exceptions raised by pyTooling.Graph.

Inheritance

Inheritance diagram of GraphException

__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 GitHub

Inheritance

Inheritance diagram of InternalError

__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

Inheritance diagram of NotInSameGraph

__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

Inheritance diagram of NotInDifferentSubgraphs

__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

Inheritance diagram of DuplicateVertexError

__init__(message, /, *, vertexID=None)[source]

Initializes the exception with the identifier that is already taken.

Parameters:
  • message (str) – The exception’s message.

  • vertexID (Optional[TypeVar(VertexIDType, bound= Hashable)]) – Optional, the vertex identifier that already exists.

Return type:

None

classmethod __new__(*args, **kwargs)
exception pyTooling.Graph.DuplicateEdgeError[source]

The exception is raised when the edge already exists in the graph.

Inheritance

Inheritance diagram of DuplicateEdgeError

__init__(message, /, *, edgeID=None)[source]

Initializes the exception with the identifier that is already taken.

Parameters:
  • message (str) – The exception’s message.

  • edgeID (Optional[TypeVar(EdgeIDType, bound= Hashable)]) – Optional, the edge identifier that already exists.

Return type:

None

classmethod __new__(*args, **kwargs)
exception pyTooling.Graph.DestinationNotReachable[source]

The exception is raised when a destination vertex is not reachable.

Inheritance

Inheritance diagram of DestinationNotReachable

__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

Inheritance diagram of NotATreeError

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
exception pyTooling.Graph.CycleError[source]

The exception is raised when a not permitted cycle is found.

Inheritance

Inheritance diagram of CycleError

__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

Inheritance diagram of Base

__init__(keyValuePairs=None)[source]

Todo

GRAPH::Base::init Needs documentation.

Parameters:

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

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

__del__()[source]

Todo

GRAPH::Base::del Needs documentation.

Return type:

None

Delete()[source]

Remove this element’s attached attributes from internal dictionary.

Return type:

None

__getitem__(key)[source]

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__delitem__(key)[source]

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__contains__(key)[source]

Checks if the key is an attached attribute (key-value-pairs) on this vertex.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__len__()[source]

Returns the number of attached attributes (key-value-pairs) on this vertex.

Return type:

int

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 None to 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:

dict[str, Any]

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:

None

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

Inheritance diagram of BaseWithIDValueAndWeight

__init__(identifier=None, value=None, weight=None, keyValuePairs=None)[source]

Initialize a graph element with an optional ID, value and weight.

Parameters:
Raises:

TypeError – If parameter ‘name’ is not of type string.

Return type:

None

_id: IDType | None

Field storing the object’s Identifier.

_value: ValueType | None

Field storing the object’s value of any type.

_weight: WeightType | None

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 Value: ValueType

Property to get and set the value (_value).

Returns:

The value.

property Weight: EdgeWeightType | None

Property to get and set the weight (_weight) of an edge.

Returns:

The weight of an edge.

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__del__()

Todo

GRAPH::Base::del Needs documentation.

Return type:

None

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

class pyTooling.Graph.BaseWithName[source]

Base-class for named graph elements like a graph, a subgraph, a view or a component.

Inheritance

Inheritance diagram of BaseWithName

__init__(name=None, keyValuePairs=None)[source]

Initialize a named graph element with an optional name and optional key-value-pairs.

Parameters:
Raises:
Return type:

None

_name: str | None

Field storing the object’s name.

property Name: str | None

Property to access the name (_name).

Returns:

The object’s name, or None if it has none.

Raises:

TypeError – If an assigned value is not of type string.

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__del__()

Todo

GRAPH::Base::del Needs documentation.

Return type:

None

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

class pyTooling.Graph.BaseWithVertices[source]

Base-class for named graph elements owning a set of vertices - a subgraph, a view or a component.

Inheritance

Inheritance diagram of BaseWithVertices

__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:
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.

__del__()[source]

Todo

GRAPH::BaseWithVertices::del Needs documentation.

Return type:

None

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.

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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 None if 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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_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

Inheritance diagram of Vertex

__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:
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.

_component: Component

Field storing a reference to the component this vertex belongs to.

_views: dict[Hashable, View]

Field storing the views this vertex is part of, by view name.

_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.

Field storing a list of inbound links.

Field storing a list of outbound links.

__del__()[source]

Todo

GRAPH::BaseEdge::del Needs documentation.

Return type:

None

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:

None

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.

Read-only property to get a tuple of inbound links (_inboundLinks).

Returns:

Tuple of inbound links.

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:

Edge

Returns:

The edge object linking this vertex and the referenced vertex.

Raises:

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:

Edge

Returns:

The edge object linking the referenced vertex and this vertex.

Raises:

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:

Edge

Returns:

The edge object linking this vertex and the created vertex.

Raises:

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:

Edge

Returns:

The edge object linking this vertex and the created vertex.

Raises:

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:

Link

Returns:

The link object linking this vertex and the referenced vertex.

Raises:

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:

Edge

Returns:

The link object linking the referenced vertex and this vertex.

Raises:

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:

bool

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:

bool

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:

bool

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:

bool

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:

None

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:

None

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:

None

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:

None

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, if True, copy all attached attributes into the new vertex.

  • linkingKeyToOriginalVertex (Optional[str]) – Optional, if not None, add a key-value-pair using this parameter as key from new vertex to the original vertex.

  • linkingKeyFromOriginalVertex (Optional[str]) – Optional, if not None, add a key-value-pair using this parameter as key from original vertex to the new vertex.

Return type:

Vertex

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.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

Generator[Edge, None, None]

Returns:

A generator to iterate all outbound edges.

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.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

Generator[Edge, None, None]

Returns:

A generator to iterate all inbound edges.

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.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

Generator[Link, None, None]

Returns:

A generator to iterate all outbound links.

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.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

Generator[Link, None, None]

Returns:

A generator to iterate all inbound links.

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.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

Generator[Vertex, None, None]

Returns:

A generator to iterate all successor vertices.

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.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

Generator[Vertex, None, None]

Returns:

A generator to iterate all predecessor vertices.

IterateVerticesBFS()[source]

A generator to iterate all reachable vertices starting from this node in breadth-first search (BFS) order.

Return type:

Generator[Vertex, None, None]

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:

Generator[Vertex, None, None]

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.

Return type:

Generator[tuple[Vertex, ...], None, None]

Returns:

A generator yielding one tuple of vertices per path.

Raises:

CycleError – If a cycle is detected while walking a path.

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:

Generator[Vertex, None, None]

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:

Generator[Vertex, None, None]

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 Node instances.

The tree is traversed using depths-first-search.

Return type:

Node

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:

str

Returns:

The detailed string representation of the vertex.

__str__()[source]

Return a string representation of the vertex.

Order of resolution:

  1. If _value is not None, return the string representation of _value.

  2. If _id is not None, return the string representation of _id.

  3. Else, return __repr__().

Return type:

str

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 None to 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 Value: ValueType

Property to get and set the value (_value).

Returns:

The value.

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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_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

Inheritance diagram of BaseEdge

__init__(source, destination, edgeID=None, value=None, weight=None, keyValuePairs=None)[source]

Initialize an edge between a source and a destination vertex.

Parameters:
Return type:

None

_source: Vertex

Vertex the edge starts at.

_destination: Vertex

Vertex the edge ends at.

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.

Reverse()[source]

Reverse the direction of this edge.

Return type:

None

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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 Value: ValueType

Property to get and set the value (_value).

Returns:

The value.

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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__del__()

Todo

GRAPH::Base::del Needs documentation.

Return type:

None

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

_id: IDType | None

Field storing the object’s Identifier.

_value: ValueType | None

Field storing the object’s value of any type.

_weight: WeightType | None

Field storing the object’s weight.

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

Inheritance diagram of Edge

__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:
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:

None

_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 by Vertex.Delete(), which unlinks the vertices itself.

Return type:

None

_Delete()[source]

Delete the edge’s attached attributes, after it was disconnected.

Return type:

None

Reverse()[source]

Reverse the direction of this edge.

Return type:

None

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 None to 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 Value: ValueType

Property to get and set the value (_value).

Returns:

The value.

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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__del__()

Todo

GRAPH::Base::del Needs documentation.

Return type:

None

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_destination: Vertex

Vertex the edge ends at.

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

_id: IDType | None

Field storing the object’s Identifier.

_source: Vertex

Vertex the edge starts at.

_value: ValueType | None

Field storing the object’s value of any type.

_weight: WeightType | None

Field storing the object’s weight.

A link can have a unique ID, a value, a weight and attached meta information as key-value-pairs. All links are directed.

Inheritance

Inheritance diagram of Link

__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:

None

_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 by Vertex.Delete(), which unlinks the vertices itself.

Return type:

None

_Delete()[source]

Delete the link’s attached attributes, after it was disconnected.

Return type:

None

Reverse()[source]

Reverse the direction of this link.

Return type:

None

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 None to 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 Value: ValueType

Property to get and set the value (_value).

Returns:

The value.

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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__del__()

Todo

GRAPH::Base::del Needs documentation.

Return type:

None

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_destination: Vertex

Vertex the edge ends at.

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

_id: IDType | None

Field storing the object’s Identifier.

_source: Vertex

Vertex the edge starts at.

_value: ValueType | None

Field storing the object’s value of any type.

_weight: WeightType | None

Field storing the object’s weight.

class pyTooling.Graph.BaseGraph[source]

Todo

GRAPH::BaseGraph Needs documentation.

Inheritance

Inheritance diagram of BaseGraph

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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 None if 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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

_name: str | None

Field storing the object’s name.

__init__(name=None, keyValuePairs=None)[source]

Todo

GRAPH::BaseGraph::init Needs documentation.

Parameters:
Return type:

None

_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.

__del__()[source]

Todo

GRAPH::BaseGraph::del Needs documentation.

Return type:

None

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 predicate is 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 predicate is 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 predicate is 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 predicate is 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 predicate is 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.

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]]) – 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 predicate is not None, the given filter function is used to skip edges.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

None

Reverse all or selected links of a graph.

If parameter predicate is not None, the given filter function is used to skip links.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

None

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.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

None

Remove all or selected links of a graph.

If parameter predicate is not None, the given filter function is used to skip links.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

None

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:

bool

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

Inheritance diagram of Subgraph

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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:

bool

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 predicate is 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 predicate is 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.

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]]) – 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 predicate is 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 predicate is 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 predicate is 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 None if 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 predicate is not None, the given filter function is used to skip edges.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

None

Remove all or selected links of a graph.

If parameter predicate is not None, the given filter function is used to skip links.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

None

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.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

None

Reverse all or selected links of a graph.

If parameter predicate is not None, the given filter function is used to skip links.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

None

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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

_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.

_name: str | None

Field storing the object’s name.

_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:
  • graph (Graph) – Optional, the reference to the graph.

  • name (Optional[str]) – Optional, name of the new sub-graph.

  • keyValuePairs (Optional[Mapping[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]]) – Optional, mapping (dictionary) of key-value-pairs.

Raises:
Return type:

None

_graph: Graph

Reference to the graph this subgraph is part of.

__del__()[source]

Todo

GRAPH::Subgraph::del Needs documentation.

Return type:

None

property Graph: Graph

Read-only property to access the graph, this subgraph is associated to (_graph).

Returns:

The graph this subgraph is associated to.

__str__()[source]

Return a string representation of this subgraph.

Return type:

str

Returns:

The subgraph’s name, or "Unnamed subgraph" if it has none.

class pyTooling.Graph.View[source]

Todo

GRAPH::View Needs documentation.

Inheritance

Inheritance diagram of View

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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 None if 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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_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

__del__()[source]

Todo

GRAPH::View::del Needs documentation.

Return type:

None

__str__()[source]

Return a string representation of this view.

Return type:

str

Returns:

The view’s name, or "Unnamed view" if it has none.

class pyTooling.Graph.Component[source]

Todo

GRAPH::Component Needs documentation.

Inheritance

Inheritance diagram of Component

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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 None if 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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_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

__del__()[source]

Todo

GRAPH::Component::del Needs documentation.

Return type:

None

__str__()[source]

Return a string representation of this component.

Return type:

str

Returns:

The component’s name, or "Unnamed component" if it has none.

class pyTooling.Graph.Graph[source]

A graph data structure is represented by an instance of Graph holding references to all nodes. Nodes are instances of Vertex classes and directed links between nodes are made of Edge instances. A graph can have attached meta information as key-value-pairs.

Inheritance

Inheritance diagram of Graph

Delete()

Remove this element’s attached attributes from internal dictionary.

Return type:

None

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 None to 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:

bool

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 predicate is 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 predicate is 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.

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]]) – 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 predicate is 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 predicate is 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 predicate is 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 None if 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 predicate is not None, the given filter function is used to skip edges.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

None

Remove all or selected links of a graph.

If parameter predicate is not None, the given filter function is used to skip links.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

None

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.

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – Optional, filter function accepting any edge and returning a boolean.

Return type:

None

Reverse all or selected links of a graph.

If parameter predicate is not None, the given filter function is used to skip links.

Parameters:

predicate (Optional[Callable[[Link], bool]]) – Optional, filter function accepting any link and returning a boolean.

Return type:

None

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.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to check.

Return type:

bool

Returns:

True, if the key is an attached attribute.

__delitem__(key)

Remove an entry from vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to remove.

Raises:

KeyError – If key doesn’t exist in the vertex’s attributes.

Return type:

None

__getitem__(key)

Read a vertex’s attached attributes (key-value-pairs) by key.

Parameters:

key (TypeVar(DictKeyType, bound= Hashable)) – The key to look for.

Return type:

TypeVar(DictValueType)

Returns:

The value associated to the given key.

__getstate__() dict[str, Any]

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

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:

int

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.

Parameters:
  • key (TypeVar(DictKeyType, bound= Hashable)) – The key to create or update.

  • value (TypeVar(DictValueType)) – Optional, the value to associate to the given key.

Return type:

None

__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:

None

_dict: dict[DictKeyType, DictValueType]

A dictionary to store arbitrary key-value-pairs.

_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.

_name: str | None

Field storing the object’s name.

_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__(name=None, keyValuePairs=None)[source]

Todo

GRAPH::Graph::init Needs documentation.

Parameters:
Return type:

None

_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.

__del__()[source]

Todo

GRAPH::Graph::del Needs documentation.

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 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.

HasVertexByID(vertexID)[source]

Check if a vertex with the given ID exists in this graph.

Parameters:

vertexID (Optional[TypeVar(VertexIDType, bound= Hashable)]) – Optional, ID to look for, or None for a vertex without an ID.

Return type:

bool

Returns:

True, if such a vertex exists.

HasVertexByValue(value)[source]

Check if a vertex carrying the given value exists in this graph.

Parameters:

value (Optional[TypeVar(VertexValueType)]) – Optional, value to look for.

Return type:

bool

Returns:

True, if such a vertex exists.

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.

Parameters:

vertexID (Optional[TypeVar(VertexIDType, bound= Hashable)]) – Optional, ID of the vertex to return, or None for the vertex without an ID.

Return type:

Vertex

Returns:

The vertex with that ID.

Raises:

KeyError – If no vertex has that ID, or if more than one vertex matches None.

GetVertexByValue(value)[source]

Return the vertex carrying the given value.

Parameters:

value (Optional[TypeVar(VertexValueType)]) – Optional, value of the vertex to return.

Return type:

Vertex

Returns:

The vertex with that value.

Raises:

KeyError – If no vertex carries that value, or if more than one vertex does.

CopyGraph()[source]

Create a copy of this graph.

Return type:

Graph

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 predicate is 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, if True, copy all graph attached attributes into the new graph.

  • copyVertexDict (bool) – Optional, if True, copy all vertex attached attributes into the new vertices.

Return type:

Graph

Returns:

A new graph with copies of the selected vertices.

__repr__()[source]

Return a detailed string representation of this graph.

Return type:

str

Returns:

The graph’s name and its vertex and edge counts.

__str__()[source]

Return a string representation of this graph.

Return type:

str

Returns:

The graph’s name, or "Unnamed graph" if it has none.