sampo.utilities.sampler#
Submodules#
Overview#
Class to describe Node in graph |
|
Class to define a certain type of edge in graph |
|
Requirements related to renewable human resources |
|
Class that describe vertex in graph (one work/task) |
|
Abstract base class for generic types. |
|
- |
|
- |
|
- |
|
- |
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_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
- 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.EnumClass 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:
BaseReqRequirements 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
- 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.IdentifiableClass 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#