pyCBD.scheduling module¶
This file contains all classes to help schedule the CBD simulator at every iteration/time.
- class pyCBD.scheduling.Scheduler(recompute_at=(0, 1), rates=None)[source]¶
Bases:
objectIdentifies an order in which the dependency graph must be traversed/computed.
Warning
This class is a semi-virtual parent class of all schedulers. Therefore, only subclasses should be used.
Note
When creating a custom scheduler (i.e. by subclassing), care must be taken to ensure all strongly connected components are grouped together!
- Parameters
recompute_at (iter) – An iterable of numeric values, identifying the iterations at which the schedule must be recomputed. When
True, the schedule will be recomputed every time. Defaults to(0, 1)(i.e. only at simulation start and iteration 1).rates (dict) – A dictionary of
block path -> rate; indentifying how often they should fire. The rate is a float, which will be compared against the time.Noneidentifies the empty dictionary.
- mustCompute(block, time)[source]¶
Checks if the block must be computed.
- Parameters
block (CBD.Core.BaseBlock) – The block that must be checked.
time (float) – The time at which the computation must occur.
- setRate(block_name, rate)[source]¶
Sets a specific rate for a block. If no rate has been set, it will be assumed the block will be executed every iteration. If a rate was already set for the block, calling this function will overwrite its previous value.
- Parameters
block_name (str) – The name of the block to set the rate of.
rate (float) – The interval of time at which the block must be executed.
- obtain(depGraph, curIt, time)[source]¶
Obtains the schedule at a specific iteration/time, optionally recomputing the value if required.
- Parameters
depGraph (CBD.depGraph.DepGraph) – The dependency graph of the model.
curIt (int) – The current iteration value.
time (float) – The current simulation time.
- class pyCBD.scheduling.TopologicalScheduler(recompute_at=(0, 1), rates=None)[source]¶
Bases:
pyCBD.scheduling.SchedulerDoes a topological sort of the dependency graph, using Tarjan’s algorithm.
Note
This code was previously located in the
pyCBD.depGraph.DepGraphand hence, it was written by Marc Provost.- schedule(depGraph, curIt, time)[source]¶
Obtains the actual schedule.
- Parameters
depGraph (CBD.depGraph.DepGraph) – The dependency graph of the model.
curIt (int) – The current iteration value.
time (float) – The current simulation time.
- topoSort(mapping, depGraph)[source]¶
Performs a topological sort on the graph.
- Parameters
mapping (dict) – Semantic mapping of the dependency graph
depGraph (CBD.depGraph.DepGraph) – The dependency graph