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.

Submodules

Exceptions

Classes

  • Base: Abstract base class for generic types.

  • BaseWithIDValueAndWeight: Abstract base class for generic types.

  • BaseWithName: Abstract base class for generic types.

  • BaseWithVertices: Abstract base class for generic types.

  • Vertex: A vertex can have a unique ID, a value and attached meta information as key-value-pairs. A vertex has 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

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

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

exception pyTooling.Graph.DuplicateVertexError[source]

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

Inheritance

Inheritance diagram of DuplicateVertexError

exception pyTooling.Graph.DuplicateEdgeError[source]

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

Inheritance

Inheritance diagram of DuplicateEdgeError

exception pyTooling.Graph.DestinationNotReachable[source]

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

Inheritance

Inheritance diagram of DestinationNotReachable

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

exception pyTooling.Graph.CycleError[source]

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

Inheritance

Inheritance diagram of CycleError


Classes

class pyTooling.Graph.Base[source]

Inheritance

Inheritance diagram of Base

__init__()[source]

Todo

GRAPH::Base::init Needs documentation.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

__del__()[source]

Todo

GRAPH::Base::del Needs documentation.

__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)) – 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]

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

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__init_subclass__()

Function to initialize subclasses.

class pyTooling.Graph.BaseWithIDValueAndWeight(identifier=None, value=None, weight=None)[source]

Inheritance

Inheritance diagram of BaseWithIDValueAndWeight

Parameters:
  • identifier (IDType | None)

  • value (ValueType | None)

  • weight (WeightType | None)

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

Todo

GRAPH::Vertex::init Needs documentation.

Parameters:
  • identifier (IDType | None)

  • value (ValueType | None)

  • weight (WeightType | None)

Return type:

None

_id: Optional[TypeVar(IDType, bound= Hashable)]

Field storing the object’s Identifier.

_value: Optional[TypeVar(ValueType)]

Field storing the object’s value of any type.

_weight: Optional[TypeVar(WeightType, bound= Union[int, float])]

Field storing the object’s weight.

property ID: IDType | None

Read-only property to access the unique ID (_id).

If no ID was given at creation time, ID returns None.

Returns:

Unique ID, if ID was given at creation time, else None.

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

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

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

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

class pyTooling.Graph.BaseWithName(name=None)[source]

Inheritance

Inheritance diagram of BaseWithName

Parameters:

name (str | None)

__init__(name=None)[source]

Todo

GRAPH::BaseWithName::init Needs documentation.

Parameters:

name (str | None)

Return type:

None

_name: Optional[str]

Field storing the object’s name.

property Name: str | None

Property to get and set the name (_name).

Returns:

The value of a component.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

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

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

class pyTooling.Graph.BaseWithVertices(graph, name=None, vertices=None)[source]

Inheritance

Inheritance diagram of BaseWithVertices

Parameters:
__init__(graph, name=None, vertices=None)[source]

Todo

GRAPH::Component::init Needs documentation.

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

property Graph: Graph

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

Returns:

The graph this object is associated to.

property Vertices: Set[Vertex]

Read-only property to access the vertices in this component (_vertices).

Returns:

The set of vertices in this component.

property VertexCount: int

Read-only property to access the number of vertices referenced by this object.

Returns:

The number of vertices this object references.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property Name: str | None

Property to get and set the name (_name).

Returns:

The value of a component.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[DictKeyType, DictValueType]

Dictionary to store key-value-pairs.

_name: Nullable[str]

Field storing the object’s name.

class pyTooling.Graph.Vertex(vertexID=None, value=None, weight=None, graph=None, subgraph=None)[source]

A vertex can have a unique ID, a value and attached meta information as key-value-pairs. A vertex has references to inbound and outbound edges, thus a graph can be traversed in reverse.

Inheritance

Inheritance diagram of Vertex

Parameters:
  • vertexID (VertexIDType | None)

  • value (VertexValueType | None)

  • weight (VertexWeightType | None)

  • graph (Graph | None)

  • subgraph (Subgraph | None)

__init__(vertexID=None, value=None, weight=None, graph=None, subgraph=None)[source]

Todo

GRAPH::Vertex::init Needs documentation.

Parameters:
  • vertexID (VertexIDType | None)

  • value (VertexValueType | None)

  • weight (VertexWeightType | None)

  • graph (Graph | None)

  • subgraph (Subgraph | None)

Return type:

None

_graph: BaseGraph[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]

Field storing a reference to the graph.

_subgraph: Subgraph[GraphDictKeyType, GraphDictValueType, VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType, EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]

Field storing a reference to the subgraph.

_inboundEdges: List[Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]

Field storing a list of inbound edges.

_outboundEdges: List[Edge[EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType]]

Field storing a list of outbound edges.

Field storing a list of inbound links.

Field storing a list of outbound links.

__del__()[source]

Todo

GRAPH::BaseEdge::del Needs documentation.

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

IsLeaf()

→ Check if a vertex is a leaf vertex in the graph.

Graph.IterateRoots

→ Iterate all roots of a graph.

Graph.IterateLeafs

→ Iterate all leafs of a graph.

property IsLeaf: bool

Read-only property to check if this vertex is a leaf vertex in the graph.

A leaf has no outbound edges (no successor vertices).

Returns:

True, if this vertex is a leaf.

See also

IsRoot()

→ Check if a vertex is a root vertex in the graph.

Graph.IterateRoots

→ Iterate all roots of a graph.

Graph.IterateLeafs

→ Iterate all leafs of a graph.

property Predecessors: Tuple[Vertex, ...]

Read-only property to get a tuple of predecessor vertices.

Returns:

Tuple of predecessor vertices.

property Successors: Tuple[Vertex, ...]

Read-only property to get a tuple of successor vertices.

Returns:

Tuple of successor vertices.

EdgeToVertex(vertex, edgeID=None, edgeWeight=None, edgeValue=None)[source]

Todo

GRAPH::Vertex::EdgeToVertex Needs documentation.

Return type:

Edge

Parameters:
  • vertex (Vertex)

  • edgeID (EdgeIDType | None)

  • edgeWeight (EdgeWeightType | None)

  • edgeValue (VertexValueType | None)

EdgeFromVertex(vertex, edgeID=None, edgeWeight=None, edgeValue=None)[source]

Todo

GRAPH::Vertex::EdgeFromVertex Needs documentation.

Return type:

Edge

Parameters:
  • vertex (Vertex)

  • edgeID (EdgeIDType | None)

  • edgeWeight (EdgeWeightType | None)

  • edgeValue (VertexValueType | None)

EdgeToNewVertex(vertexID=None, vertexValue=None, vertexWeight=None, edgeID=None, edgeWeight=None, edgeValue=None)[source]

Todo

GRAPH::Vertex::EdgeToNewVertex Needs documentation.

Return type:

Edge

Parameters:
  • vertexID (VertexIDType | None)

  • vertexValue (VertexValueType | None)

  • vertexWeight (VertexWeightType | None)

  • edgeID (EdgeIDType | None)

  • edgeWeight (EdgeWeightType | None)

  • edgeValue (VertexValueType | None)

EdgeFromNewVertex(vertexID=None, vertexValue=None, vertexWeight=None, edgeID=None, edgeWeight=None, edgeValue=None)[source]

Todo

GRAPH::Vertex::EdgeFromNewVertex Needs documentation.

Return type:

Edge

Parameters:
  • vertexID (VertexIDType | None)

  • vertexValue (VertexValueType | None)

  • vertexWeight (VertexWeightType | None)

  • edgeID (EdgeIDType | None)

  • edgeWeight (EdgeWeightType | None)

  • edgeValue (VertexValueType | None)

LinkToVertex(vertex, linkID=None, linkWeight=None, linkValue=None)[source]

Todo

GRAPH::Vertex::LinkToVertex Needs documentation.

Return type:

Link

Parameters:
  • vertex (Vertex)

  • linkID (EdgeIDType | None)

  • linkWeight (EdgeWeightType | None)

  • linkValue (VertexValueType | None)

LinkFromVertex(vertex, linkID=None, linkWeight=None, linkValue=None)[source]

Todo

GRAPH::Vertex::LinkToVertex Needs documentation.

Return type:

Edge

Parameters:
  • vertex (Vertex)

  • linkID (EdgeIDType | None)

  • linkWeight (EdgeWeightType | None)

  • linkValue (VertexValueType | None)

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.

Copy(graph, copyDict=False, linkingKeyToOriginalVertex=None, linkingKeyFromOriginalVertex=None)[source]

Creates a copy of this vertex in another graph.

Optionally, the vertex’s attached attributes (key-value-pairs) can be copied and a linkage between both vertices can be established.

Parameters:
  • graph (<property object at 0x7f163ed31f80>) – The graph, the vertex is created in.

  • copyDict (bool) – If True, copy all attached attributes into the new vertex.

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

  • linkingKeyFromOriginalVertex (Optional[str]) – 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]]) – 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]]) – 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]]) – 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]]) – 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]]) – 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]]) – 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

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.

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.

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:

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

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property ID: IDType | None

Read-only property to access the unique ID (_id).

If no ID was given at creation time, ID returns None.

Returns:

Unique ID, if ID was given at creation time, else None.

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

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[DictKeyType, DictValueType]

Dictionary to store key-value-pairs.

_id: Nullable[IDType]

Field storing the object’s Identifier.

_value: Nullable[ValueType]

Field storing the object’s value of any type.

_weight: Nullable[WeightType]

Field storing the object’s weight.

class pyTooling.Graph.BaseEdge(source, destination, edgeID=None, value=None, weight=None)[source]

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

Inheritance

Inheritance diagram of BaseEdge

Parameters:
  • source (Vertex)

  • destination (Vertex)

  • edgeID (EdgeIDType | None)

  • value (EdgeValueType | None)

  • weight (EdgeWeightType | None)

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

Todo

GRAPH::BaseEdge::init Needs documentation.

Parameters:
  • source (Vertex)

  • destination (Vertex)

  • edgeID (EdgeIDType | None)

  • value (EdgeValueType | None)

  • weight (EdgeWeightType | None)

Return type:

None

property Source: Vertex

Read-only property to get the source (_source) of an edge.

Returns:

The source of an edge.

property Destination: Vertex

Read-only property to get the destination (_destination) of an edge.

Returns:

The destination of an edge.

Reverse()[source]

Reverse the direction of this edge.

Return type:

None

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

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

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

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

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

_id: Optional[TypeVar(IDType, bound= Hashable)]

Field storing the object’s Identifier.

_value: Optional[TypeVar(ValueType)]

Field storing the object’s value of any type.

_weight: Optional[TypeVar(WeightType, bound= Union[int, float])]

Field storing the object’s weight.

class pyTooling.Graph.Edge(source, destination, edgeID=None, value=None, weight=None)[source]

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

Inheritance

Inheritance diagram of Edge

Parameters:
  • source (Vertex)

  • destination (Vertex)

  • edgeID (EdgeIDType | None)

  • value (EdgeValueType | None)

  • weight (EdgeWeightType | None)

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

Todo

GRAPH::Edge::init Needs documentation.

Parameters:
  • source (Vertex)

  • destination (Vertex)

  • edgeID (EdgeIDType | None)

  • value (EdgeValueType | None)

  • weight (EdgeWeightType | None)

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.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property ID: IDType | None

Read-only property to access the unique ID (_id).

If no ID was given at creation time, ID returns None.

Returns:

Unique ID, if ID was given at creation time, else None.

property Source: Vertex

Read-only property to get the source (_source) of an edge.

Returns:

The source of an edge.

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

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

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

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

_id: Optional[TypeVar(IDType, bound= Hashable)]

Field storing the object’s Identifier.

_value: Optional[TypeVar(ValueType)]

Field storing the object’s value of any type.

_weight: Optional[TypeVar(WeightType, bound= Union[int, float])]

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

Parameters:
  • source (Vertex)

  • destination (Vertex)

  • linkID (LinkIDType)

  • value (LinkValueType)

  • weight (LinkWeightType | None)

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

Todo

GRAPH::Edge::init Needs documentation.

Parameters:
  • source (Vertex)

  • destination (Vertex)

  • linkID (LinkIDType)

  • value (LinkValueType)

  • weight (LinkWeightType | None)

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.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property ID: IDType | None

Read-only property to access the unique ID (_id).

If no ID was given at creation time, ID returns None.

Returns:

Unique ID, if ID was given at creation time, else None.

property Source: Vertex

Read-only property to get the source (_source) of an edge.

Returns:

The source of an edge.

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

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

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

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

_id: Optional[TypeVar(IDType, bound= Hashable)]

Field storing the object’s Identifier.

_value: Optional[TypeVar(ValueType)]

Field storing the object’s value of any type.

_weight: Optional[TypeVar(WeightType, bound= Union[int, float])]

Field storing the object’s weight.

class pyTooling.Graph.BaseGraph(name=None)[source]

Todo

GRAPH::BaseGraph Needs documentation.

Inheritance

Inheritance diagram of BaseGraph

Parameters:

name (str | None)

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property Name: str | None

Property to get and set the name (_name).

Returns:

The value of a component.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

_name: Optional[str]

Field storing the object’s name.

__init__(name=None)[source]

Todo

GRAPH::BaseGraph::init Needs documentation.

Parameters:

name (str | None)

__del__()[source]

Todo

GRAPH::BaseGraph::del Needs documentation.

property VertexCount: int

Read-only property to access the number of vertices in this graph.

Returns:

The number of vertices in this graph.

property EdgeCount: int

Read-only property to access the number of edges in this graph.

Returns:

The number of edges in this graph.

property LinkCount: int

Read-only property to access the number of links in this graph.

Returns:

The number of links in this graph.

IterateVertices(predicate=None)[source]

Iterate all or selected vertices of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices.

IterateRoots(predicate=None)[source]

Iterate all or selected roots (vertices without inbound edges / without predecessors) of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices without inbound edges.

See also

IterateLeafs()

→ Iterate leafs of a graph.

Vertex.IsRoot

→ Check if a vertex is a root vertex in the graph.

Vertex.IsLeaf

→ Check if a vertex is a leaf vertex in the graph.

IterateLeafs(predicate=None)[source]

Iterate all or selected leafs (vertices without outbound edges / without successors) of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices without outbound edges.

See also

IterateRoots()

→ Iterate roots of a graph.

Vertex.IsRoot

→ Check if a vertex is a root vertex in the graph.

Vertex.IsLeaf

→ Check if a vertex is a leaf vertex in the graph.

IterateTopologically(predicate=None)[source]

Iterate all or selected vertices in topological order.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices in topological order.

Raises:

CycleError – Raised if graph is cyclic, thus topological sorting isn’t possible.

IterateEdges(predicate=None)[source]

Iterate all or selected edges of a graph.

If parameter predicate is not None, the given filter function is used to skip edges in the generator.

Parameters:

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

Return type:

Generator[Edge[TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType)], None, None]

Returns:

A generator to iterate all edges.

Iterate all or selected links of a graph.

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

Parameters:

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

Return type:

Generator[Link[TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all links.

ReverseEdges(predicate=None)[source]

Reverse all or selected edges of a graph.

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

Parameters:

predicate (Optional[Callable[[Edge], bool]]) – 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]]) – 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]]) – Filter function accepting any edge and returning a boolean.

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]]) – Filter function accepting any link and returning a boolean.

HasCycle()[source]

Todo

GRAPH::BaseGraph::HasCycle Needs documentation.

Return type:

bool

class pyTooling.Graph.Subgraph(graph, name=None, vertices=None)[source]

Todo

GRAPH::Subgraph Needs documentation.

Inheritance

Inheritance diagram of Subgraph

Parameters:
property EdgeCount: int

Read-only property to access the number of edges in this graph.

Returns:

The number of edges in this graph.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

HasCycle()

Todo

GRAPH::BaseGraph::HasCycle Needs documentation.

Return type:

bool

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

IterateEdges(predicate=None)

Iterate all or selected edges of a graph.

If parameter predicate is not None, the given filter function is used to skip edges in the generator.

Parameters:

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

Return type:

Generator[Edge[TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType)], None, None]

Returns:

A generator to iterate all edges.

IterateLeafs(predicate=None)

Iterate all or selected leafs (vertices without outbound edges / without successors) of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices without outbound edges.

See also

IterateRoots()

→ Iterate roots of a graph.

Vertex.IsRoot

→ Check if a vertex is a root vertex in the graph.

Vertex.IsLeaf

→ Check if a vertex is a leaf vertex in the graph.

Iterate all or selected links of a graph.

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

Parameters:

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

Return type:

Generator[Link[TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all links.

IterateRoots(predicate=None)

Iterate all or selected roots (vertices without inbound edges / without predecessors) of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices without inbound edges.

See also

IterateLeafs()

→ Iterate leafs of a graph.

Vertex.IsRoot

→ Check if a vertex is a root vertex in the graph.

Vertex.IsLeaf

→ Check if a vertex is a leaf vertex in the graph.

IterateTopologically(predicate=None)

Iterate all or selected vertices in topological order.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices in topological order.

Raises:

CycleError – Raised if graph is cyclic, thus topological sorting isn’t possible.

IterateVertices(predicate=None)

Iterate all or selected vertices of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices.

property LinkCount: int

Read-only property to access the number of links in this graph.

Returns:

The number of links in this graph.

property Name: str | None

Property to get and set the name (_name).

Returns:

The value of a component.

RemoveEdges(predicate=None)

Remove all or selected edges of a graph.

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

Parameters:

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

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]]) – Filter function accepting any link and returning a boolean.

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]]) – 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]]) – Filter function accepting any link and returning a boolean.

Return type:

None

property VertexCount: int

Read-only property to access the number of vertices in this graph.

Returns:

The number of vertices in this graph.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

_name: Optional[str]

Field storing the object’s name.

__init__(graph, name=None, vertices=None)[source]

Todo

GRAPH::Subgraph::init Needs documentation.

Parameters:
Return type:

None

__del__()[source]

Todo

GRAPH::Subgraph::del Needs documentation.

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]

Todo

GRAPH::Subgraph::str Needs documentation.

Return type:

str

class pyTooling.Graph.View(graph, name=None, vertices=None)[source]

Todo

GRAPH::View Needs documentation.

Inheritance

Inheritance diagram of View

Parameters:
property Graph: Graph

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

Returns:

The graph this object is associated to.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property Name: str | None

Property to get and set the name (_name).

Returns:

The value of a component.

property VertexCount: int

Read-only property to access the number of vertices referenced by this object.

Returns:

The number of vertices this object references.

property Vertices: Set[Vertex]

Read-only property to access the vertices in this component (_vertices).

Returns:

The set of vertices in this component.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[DictKeyType, DictValueType]

Dictionary to store key-value-pairs.

_graph: Graph[GraphDictKeyType, GraphDictValueType,VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType,EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType,LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]

Field storing a reference to the graph.

_name: Nullable[str]

Field storing the object’s name.

_vertices: Set['Vertex[GraphDictKeyType, GraphDictValueType,VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType,EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType,LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]']

Field storing a set of vertices.

__init__(graph, name=None, vertices=None)[source]

Todo

GRAPH::View::init Needs documentation.

Parameters:
Return type:

None

__del__()[source]

Todo

GRAPH::View::del Needs documentation.

__str__()[source]

Todo

GRAPH::View::str Needs documentation.

Return type:

str

class pyTooling.Graph.Component(graph, name=None, vertices=None)[source]

Todo

GRAPH::Component Needs documentation.

Inheritance

Inheritance diagram of Component

Parameters:
property Graph: Graph

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

Returns:

The graph this object is associated to.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property Name: str | None

Property to get and set the name (_name).

Returns:

The value of a component.

property VertexCount: int

Read-only property to access the number of vertices referenced by this object.

Returns:

The number of vertices this object references.

property Vertices: Set[Vertex]

Read-only property to access the vertices in this component (_vertices).

Returns:

The set of vertices in this component.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[DictKeyType, DictValueType]

Dictionary to store key-value-pairs.

_graph: Graph[GraphDictKeyType, GraphDictValueType,VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType,EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType,LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]

Field storing a reference to the graph.

_name: Nullable[str]

Field storing the object’s name.

_vertices: Set['Vertex[GraphDictKeyType, GraphDictValueType,VertexIDType, VertexWeightType, VertexValueType, VertexDictKeyType, VertexDictValueType,EdgeIDType, EdgeWeightType, EdgeValueType, EdgeDictKeyType, EdgeDictValueType,LinkIDType, LinkWeightType, LinkValueType, LinkDictKeyType, LinkDictValueType]']

Field storing a set of vertices.

__init__(graph, name=None, vertices=None)[source]

Todo

GRAPH::Component::init Needs documentation.

Parameters:
Return type:

None

__del__()[source]

Todo

GRAPH::Component::del Needs documentation.

__str__()[source]

Todo

GRAPH::Component::str Needs documentation.

Return type:

str

class pyTooling.Graph.Graph(name=None)[source]

A graph data structure is represented by an instance of Graph holding references to all nodes. Nodes are instances 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

Parameters:

name (str | None)

property EdgeCount: int

Read-only property to access the number of edges in this graph.

Returns:

The number of edges in this graph.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

HasCycle()

Todo

GRAPH::BaseGraph::HasCycle Needs documentation.

Return type:

bool

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

IterateEdges(predicate=None)

Iterate all or selected edges of a graph.

If parameter predicate is not None, the given filter function is used to skip edges in the generator.

Parameters:

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

Return type:

Generator[Edge[TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType)], None, None]

Returns:

A generator to iterate all edges.

IterateLeafs(predicate=None)

Iterate all or selected leafs (vertices without outbound edges / without successors) of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices without outbound edges.

See also

IterateRoots()

→ Iterate roots of a graph.

Vertex.IsRoot

→ Check if a vertex is a root vertex in the graph.

Vertex.IsLeaf

→ Check if a vertex is a leaf vertex in the graph.

Iterate all or selected links of a graph.

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

Parameters:

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

Return type:

Generator[Link[TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all links.

IterateRoots(predicate=None)

Iterate all or selected roots (vertices without inbound edges / without predecessors) of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices without inbound edges.

See also

IterateLeafs()

→ Iterate leafs of a graph.

Vertex.IsRoot

→ Check if a vertex is a root vertex in the graph.

Vertex.IsLeaf

→ Check if a vertex is a leaf vertex in the graph.

IterateTopologically(predicate=None)

Iterate all or selected vertices in topological order.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices in topological order.

Raises:

CycleError – Raised if graph is cyclic, thus topological sorting isn’t possible.

IterateVertices(predicate=None)

Iterate all or selected vertices of a graph.

If parameter predicate is not None, the given filter function is used to skip vertices in the generator.

Parameters:

predicate (Optional[Callable[[Vertex], bool]]) – Filter function accepting any vertex and returning a boolean.

Return type:

Generator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)], None, None]

Returns:

A generator to iterate all vertices.

property LinkCount: int

Read-only property to access the number of links in this graph.

Returns:

The number of links in this graph.

property Name: str | None

Property to get and set the name (_name).

Returns:

The value of a component.

RemoveEdges(predicate=None)

Remove all or selected edges of a graph.

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

Parameters:

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

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]]) – Filter function accepting any link and returning a boolean.

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]]) – 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]]) – Filter function accepting any link and returning a boolean.

Return type:

None

property VertexCount: int

Read-only property to access the number of vertices in this graph.

Returns:

The number of vertices in this graph.

__class_getitem__()

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo[T]: ….

__contains__(key)

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

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.

__init_subclass__()

Function to initialize subclasses.

__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)) – The value to associate to the given key.

Return type:

None

_dict: Dict[TypeVar(DictKeyType, bound= Hashable), TypeVar(DictValueType)]

Dictionary to store key-value-pairs.

_name: Optional[str]

Field storing the object’s name.

__init__(name=None)[source]

Todo

GRAPH::Graph::init Needs documentation.

Parameters:

name (str | None)

Return type:

None

__del__()[source]

Todo

GRAPH::Graph::del Needs documentation.

property Subgraphs: Set[Subgraph]

Read-only property to access the subgraphs in this graph (_subgraphs).

Returns:

The set of subgraphs in this graph.

property Views: Set[View]

Read-only property to access the views in this graph (_views).

Returns:

The set of views in this graph.

property Components: Set[Component]

Read-only property to access the components in this graph (_components).

Returns:

The set of components in this graph.

property SubgraphCount: int

Read-only property to access the number of subgraphs in this graph.

Returns:

The number of subgraphs in this graph.

property ViewCount: int

Read-only property to access the number of views in this graph.

Returns:

The number of views in this graph.

property ComponentCount: int

Read-only property to access the number of components in this graph.

Returns:

The number of components in this graph.

__iter__()[source]

Todo

GRAPH::Graph::iter Needs documentation.

Return type:

Iterator[Vertex[TypeVar(GraphDictKeyType, bound= Hashable), TypeVar(GraphDictValueType), TypeVar(VertexIDType, bound= Hashable), TypeVar(VertexWeightType, bound= Union[int, float]), TypeVar(VertexValueType), TypeVar(VertexDictKeyType, bound= Hashable), TypeVar(VertexDictValueType), TypeVar(EdgeIDType, bound= Hashable), TypeVar(EdgeWeightType, bound= Union[int, float]), TypeVar(EdgeValueType), TypeVar(EdgeDictKeyType, bound= Hashable), TypeVar(EdgeDictValueType), TypeVar(LinkIDType, bound= Hashable), TypeVar(LinkWeightType, bound= Union[int, float]), TypeVar(LinkValueType), TypeVar(LinkDictKeyType, bound= Hashable), TypeVar(LinkDictValueType)]]

GetVertexByID(vertexID)[source]

Todo

GRAPH::Graph::GetVertexByID Needs documentation.

Return type:

Vertex

Parameters:

vertexID (VertexIDType | None)

GetVertexByValue(value)[source]

Todo

GRAPH::Graph::GetVertexByValue Needs documentation.

Return type:

Vertex

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]]) – Filter function accepting any vertex and returning a boolean.

  • copyGraphDict (bool) – If True, copy all graph attached attributes into the new graph.

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

Return type:

Graph

__repr__()[source]

Todo

GRAPH::Graph::repr Needs documentation.

Return type:

str

__str__()[source]

Todo

GRAPH::Graph::str Needs documentation.

Return type:

str