sampo.utilities.sampler#

Submodules#

Overview#

Classes#

GraphNode

Class to describe Node in graph

EdgeType

Class to define a certain type of edge in graph

WorkerReq

Requirements related to renewable human resources

WorkUnit

Class that describe vertex in graph (one work/task)

MinMax

Abstract base class for generic types.

Sampler

-

Function#

get_worker_reqs_list(rand, volume, worker_count)

-

get_work_unit(rand, name, work_id, volume_type, group, work_volume, req_volume, req_worker_count)

-

get_similar_work_unit(rand, exemplar, scalar, name, work_id)

-

Classes#

class sampo.utilities.sampler.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.utilities.sampler.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.utilities.sampler.WorkerReq#

Bases: BaseReq

Requirements related to renewable human resources

Parameters:
  • kind – type of resource/profession

  • volume – volume of work in time units

  • min_count – minimum number of employees needed to perform the work

  • max_count – maximum allowable number of employees performing the work

  • name – the name of this requirement

kind: str#
volume: sampo.schemas.time.Time#
min_count: int | None = 1#
max_count: int | None#
name: str | None = ''#
scale_all(scalar: float, new_name: str | None = '') WorkerReq#

The function scales the requirement to the size of the work including the total volume and the maximum number of personnel involved.

Parameters:
  • scalar – scalar for multiplication

  • new_name – name for new req

Return new_req:

new object with new volume of the work and extended max_count_commands

scale_volume(scalar: float, new_name: str | None = None) WorkerReq#

The function scales only volume of the work for the requirement.

Parameters:
  • scalar – scalar for multiplication

  • new_name – name for new req

Return new_req:

new object with new volume of the work.

class sampo.utilities.sampler.WorkUnit(id: str, name: str, worker_reqs: list[sampo.schemas.requirements.WorkerReq] = [], equipment_reqs: list[sampo.schemas.requirements.EquipmentReq] = [], material_reqs: list[sampo.schemas.requirements.MaterialReq] = [], object_reqs: list[sampo.schemas.requirements.ConstructionObjectReq] = [], group: str = 'default', is_service_unit=False, volume: float = 0, volume_type: str = 'unit', display_name: str = '', workground_size: int = 100)#

Bases: sampo.schemas.serializable.AutoJSONSerializable[WorkUnit], sampo.schemas.identifiable.Identifiable

Class that describe vertex in graph (one work/task)

__del__()#
need_materials() list[sampo.schemas.resources.Material]#
worker_reqs_serializer(value: list[sampo.schemas.requirements.WorkerReq])#

Return serialized list of worker requirements

Parameters:

value – list of worker requirements

Returns:

list of worker requirements

classmethod worker_reqs_deserializer(value)#

Get list of worker requirements

Parameters:

value – serialized list of work requirements

Returns:

list of worker requirements

__getstate__()#
__setstate__(state)#
class sampo.utilities.sampler.MinMax#

Bases: Generic[T]

Abstract base class for generic types.

A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:

class Mapping(Generic[KT, VT]):
    def __getitem__(self, key: KT) -> VT:
        ...
    # Etc.

This class can then be used as follows:

def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
    try:
        return mapping[key]
    except KeyError:
        return default
min: T#
max: T#
class sampo.utilities.sampler.Sampler(seed: Hashable | None = None)#
worker_reqs(volume: types.MinMax[int] | None = MinMax[int](1, 50), worker_count: types.MinMax[int] | None = MinMax[int](1, 100)) List[sampo.schemas.requirements.WorkerReq]#
work_unit(name: str, work_id: str | None = '', volume_type: str | None = 'unit', group: str | None = 'default', work_volume: types.MinMax[float] | None = MinMax[float](0.1, 100.0), req_volume: types.MinMax[int] | None = MinMax[int](1, 50), req_worker_count: types.MinMax[int] | None = MinMax[int](1, 100)) sampo.schemas.works.WorkUnit#
similar_work_unit(exemplar: sampo.schemas.works.WorkUnit, scalar: float | None = 1.0, name: str | None = '', work_id: str | None = '') sampo.schemas.works.WorkUnit#
graph_node(name: str, edges: List[Tuple[sampo.schemas.graph.GraphNode, float, sampo.schemas.graph.EdgeType]], work_id: str | None = '', volume_type: str | None = 'unit', group: str | None = 'default', work_volume: types.MinMax[float] | None = MinMax[float](0.1, 100.0), req_volume: types.MinMax[int] | None = MinMax[int](1, 50), req_worker_count: types.MinMax[int] | None = MinMax[int](1, 100)) sampo.schemas.graph.GraphNode#
similar_graph_node(exemplar: sampo.schemas.graph.GraphNode, edges: List[Tuple[sampo.schemas.graph.GraphNode, float, sampo.schemas.graph.EdgeType]], scalar: float | None = 1.0, name: str | None = '', work_id: str | None = '') sampo.schemas.graph.GraphNode#

Functions#

sampo.utilities.sampler.get_worker_reqs_list(rand: random.Random, volume: sampo.utilities.sampler.types.MinMax[int] | None = MinMax[int](1, 50), worker_count: sampo.utilities.sampler.types.MinMax[int] | None = MinMax[int](1, 100)) list[sampo.schemas.requirements.WorkerReq]#
sampo.utilities.sampler.get_work_unit(rand: random.Random, name: str, work_id: str | None = '', volume_type: str | None = 'unit', group: str | None = 'default', work_volume: sampo.utilities.sampler.types.MinMax[float] | None = MinMax[float](0.1, 100.0), req_volume: sampo.utilities.sampler.types.MinMax[int] | None = MinMax[int](1, 50), req_worker_count: sampo.utilities.sampler.types.MinMax[int] | None = MinMax[int](1, 100)) sampo.schemas.works.WorkUnit#
sampo.utilities.sampler.get_similar_work_unit(rand: random.Random, exemplar: sampo.schemas.works.WorkUnit, scalar: float | None = 1.0, name: str | None = '', work_id: str | None = '') sampo.schemas.works.WorkUnit#