sampo.scheduler.utils.local_optimization#

Overview#

Classes#

OrderLocalOptimizer

Helper class that provides a standard way to create an ABC using

ScheduleLocalOptimizer

Base class for building local optimization methods applicable to the schedule.

SwapOrderLocalOptimizer

This performs just small shuffle that not breaks topological order.

ParallelizeScheduleLocalOptimizer

This method finds near placed works and turns it to run in parallel.

Function#

get_swap_candidates(node, node_index, candidates, node2ind, processed)

Abstract function to find nodes that can be swapped

optimize_local_sequence(seq, start_ind, end_ind, work_estimator)

-

Classes#

class sampo.scheduler.utils.local_optimization.OrderLocalOptimizer#

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

abstract optimize(node_order: list[sampo.schemas.graph.GraphNode], area: range) list[sampo.schemas.graph.GraphNode]#
class sampo.scheduler.utils.local_optimization.ScheduleLocalOptimizer(timeline_type: type[sampo.scheduler.timeline.base.Timeline])#

Bases: abc.ABC

Base class for building local optimization methods applicable to the schedule.

abstract optimize(scheduled_works: dict[sampo.schemas.graph.GraphNode, sampo.schemas.schedule.ScheduledWork], node_order: list[sampo.schemas.graph.GraphNode], contractors: list[sampo.schemas.contractor.Contractor], landscape_config: sampo.schemas.landscape.LandscapeConfiguration, spec: sampo.schemas.schedule_spec.ScheduleSpec, worker_pool: sampo.schemas.contractor.WorkerContractorPool, work_estimator: sampo.schemas.time_estimator.WorkTimeEstimator, assigned_parent_time: sampo.schemas.time.Time, area: range) dict[sampo.schemas.graph.GraphNode, sampo.schemas.schedule.ScheduledWork]#

Optimizes works scheduled_works, referenced by node_order and area parameters.

Result writes to scheduled_works in-place. :param node_order: :param contractors: :param landscape_config: :param spec: :param worker_pool: :param work_estimator: :param assigned_parent_time: :param scheduled_works: :param area:

class sampo.scheduler.utils.local_optimization.SwapOrderLocalOptimizer#

Bases: OrderLocalOptimizer

This performs just small shuffle that not breaks topological order.

optimize(node_order: list[sampo.schemas.graph.GraphNode], area: range) list[sampo.schemas.graph.GraphNode]#

Change order of nodes (not breaks topological order) by swapping several nodes.

class sampo.scheduler.utils.local_optimization.ParallelizeScheduleLocalOptimizer(timeline_type: type[sampo.scheduler.timeline.base.Timeline])#

Bases: ScheduleLocalOptimizer

This method finds near placed works and turns it to run in parallel. It will take effect only if it’s launched after scheduling.

recalc_schedule(node_order: Iterable[sampo.schemas.graph.GraphNode], contractors: list[sampo.schemas.contractor.Contractor], landscape_config: sampo.schemas.landscape.LandscapeConfiguration, spec: sampo.schemas.schedule_spec.ScheduleSpec, node2swork: dict[sampo.schemas.graph.GraphNode, sampo.schemas.schedule.ScheduledWork], worker_pool: sampo.schemas.contractor.WorkerContractorPool, assigned_parent_time: sampo.schemas.time.Time, work_estimator: sampo.schemas.time_estimator.WorkTimeEstimator) dict[sampo.schemas.graph.GraphNode, sampo.schemas.schedule.ScheduledWork]#

Recalculates duration and start-finish times in the whole given seq. This will be useful to call after parallelize_local_sequence method or other methods that can change the appointed set of workers.

Parameters:
  • node_order – scheduled works to process

  • contractors

  • landscape_config

  • spec

  • node2swork

  • worker_pool

  • assigned_parent_time

  • work_estimator – an optional WorkTimeEstimator object to estimate time of work

optimize(scheduled_works: dict[sampo.schemas.graph.GraphNode, sampo.schemas.schedule.ScheduledWork], node_order: list[sampo.schemas.graph.GraphNode], contractors: list[sampo.schemas.contractor.Contractor], landscape_config: sampo.schemas.landscape.LandscapeConfiguration, spec: sampo.schemas.schedule_spec.ScheduleSpec, worker_pool: sampo.schemas.contractor.WorkerContractorPool, work_estimator: sampo.schemas.time_estimator.WorkTimeEstimator, assigned_parent_time: sampo.schemas.time.Time, area: range) dict[sampo.schemas.graph.GraphNode, sampo.schemas.schedule.ScheduledWork]#

Finds near placed works and turns it to run in parallel.

Parameters:
  • scheduled_works

  • node_order

  • contractors

  • landscape_config

  • spec

  • worker_pool

  • work_estimator

  • assigned_parent_time

  • area

Returns:

Functions#

sampo.scheduler.utils.local_optimization.get_swap_candidates(node: sampo.schemas.graph.GraphNode, node_index: int, candidates: Iterable[sampo.schemas.graph.GraphNode], node2ind: dict[sampo.schemas.graph.GraphNode, int], processed: set[sampo.schemas.graph.GraphNode]) list[sampo.schemas.graph.GraphNode]#

Abstract function to find nodes that can be swapped with given node without breaking topological order

Parameters:
  • node – target node

  • node_index – index of target node in global sequence

  • candidates – list of candidates to swapping

  • node2ind – a dict from node to its index

  • processed – a set of nodes that should not be swapped yet

sampo.scheduler.utils.local_optimization.optimize_local_sequence(seq: list[sampo.schemas.graph.GraphNode], start_ind: int, end_ind: int, work_estimator: sampo.schemas.time_estimator.WorkTimeEstimator)#

Attributes#

sampo.scheduler.utils.local_optimization.PRIORITY_SHUFFLE_RADIUS = 0.5#