sampo.schemas.graph#

Overview#

Classes#

EdgeType

Class to define a certain type of edge in graph

GraphEdge

The edge of graph with start and finish vertexes

GraphNode

Class to describe Node in graph

WorkGraph

Class to describe graph of works

Attributes#

GraphNodeDict

-

Classes#

class sampo.schemas.graph.EdgeType#

Bases: enum.Enum

Class to define a certain type of edge in graph

InseparableFinishStart = 'IFS'#
LagFinishStart = 'FFS'#
StartStart = 'SS'#
FinishFinish = 'FF'#
FinishStart = 'FS'#
static is_dependency(edge) bool#
class sampo.schemas.graph.GraphEdge#

The edge of graph with start and finish vertexes

start: GraphNode#
finish: GraphNode#
lag: float | None = 0#
type: EdgeType | None#
class sampo.schemas.graph.GraphNode(work_unit: sampo.schemas.works.WorkUnit, parent_works: list[GraphNode] | list[tuple[GraphNode, float, EdgeType]])#

Bases: sampo.schemas.serializable.JSONSerializable[GraphNode]

Class to describe Node in graph

property edges_to: list[GraphEdge]#
property edges_from: list[GraphEdge]#

Return all successors of current vertex :return: list of successors

property work_unit: sampo.schemas.works.WorkUnit#
property id: str#
__del__()#
__hash__() int#

Return hash(self).

__repr__() str#

Return repr(self).

__getstate__()#
__setstate__(state)#
_serialize() sampo.schemas.serializable.T#

Converts all the meaningful information from this instance to a generic representation :return: A generic representation

classmethod _deserialize(representation: sampo.schemas.serializable.T) dict#

Creates class instance from a representation :param representation: Representation produced by _serialize method :return: New class instance

update_work_unit(work_unit: sampo.schemas.works.WorkUnit) None#
add_parents(parent_works: list['GraphNode'] or list[tuple['GraphNode', float, EdgeType]]) None#

Two-sided linking of successors and predecessors

Parameters:

parent_works – list of parent works

invalidate_parents_cache()#
invalidate_children_cache()#
is_inseparable_parent() bool#
is_inseparable_son() bool#
traverse_children(topologically: bool = False)#

DFS from current vertex to down :param topologically: is DFS need to go in topologically way :return:

inseparable_son() GraphNode | None#

Return inseparable son (amount of inseparable sons at most 1) :return: inseparable son

inseparable_parent() GraphNode | None#

Return predecessor of current vertex in inseparable chain :return: inseparable parent

parents() list[GraphNode]#

Return list of predecessors of current vertex :return: list of parents

parents_set() set[GraphNode]#

Return unique predecessors of current vertex :return: set of parents

children() list[GraphNode]#

Return list of successors of current vertex :return: list of children

children_set() set[GraphNode]#

Return unique successors of current vertex :return: set of children

neighbors()#

Get all edges that have types SS with current vertex :return: list of neighbours

get_inseparable_chain() list[GraphNode] | None#

Gets an ordered list of whole chain of nodes, connected with edges of type INSEPARABLE_FINISH_START = ‘INSEPARABLE’, IF self NODE IS THE START NODE OF SUCH CHAIN. Otherwise, None.

Returns:

list of GraphNode or None

get_inseparable_chain_with_self() list[GraphNode]#

Gets an ordered list of whole chain of nodes, connected with edges of type INSEPARABLE_FINISH_START = ‘INSEPARABLE’.

Returns:

list of inseparable chain with starting node

_get_inseparable_children() list[GraphNode]#

Recursively gets a child, connected with INSEPARABLE_FINISH_START edge, its inseparable child, etc. As any node may contain an inseparable connection with only one of its children, there is no need to choose. If no children are connected inseparably, returns None.

Returns:

list[GraphNode]. Empty, if there is no inseparable children

_add_child_edge(child: GraphEdge)#

Append new edge with child

Parameters:

child

Returns:

current graph node

min_start_time(node2swork: dict[GraphNode, sampo.schemas.scheduled_work.ScheduledWork]) sampo.schemas.time.Time#
class sampo.schemas.graph.WorkGraph#

Bases: sampo.schemas.serializable.JSONSerializable[WorkGraph]

Class to describe graph of works

start: GraphNode#
finish: GraphNode#
nodes: list[GraphNode]#
adj_matrix: scipy.sparse.dok_matrix#
dict_nodes: GraphNodeDict#
vertex_count: int#
__post_init__() None#
reinit()#
__hash__()#

Return hash(self).

__getitem__(item: str) GraphNode#
__getstate__()#
__setstate__(state)#
__del__()#
_serialize() sampo.schemas.serializable.T#

Converts all the meaningful information from this instance to a generic representation :return: A generic representation

classmethod _deserialize(representation: sampo.schemas.serializable.T) sampo.schemas.serializable.JS#

Creates class instance from a representation :param representation: Representation produced by _serialize method :return: New class instance

_to_adj_matrix() tuple[list[GraphNode], scipy.sparse.dok_matrix, dict[str, GraphNode]]#

Build adjacency matrix from current graph

Attributes#

sampo.schemas.graph.GraphNodeDict#