CBD.scheduling module

This file contains all classes to help schedule the CBD simulator at every iteration/time.

class CBD.scheduling.Scheduler(recompute_at=(0, 1), rates=None)[source]

Bases: object

Identifies 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. None identifies 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.

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.

class CBD.scheduling.TopologicalScheduler(recompute_at=(0, 1), rates=None)[source]

Bases: CBD.scheduling.Scheduler

Does a topological sort of the dependency graph, using Tarjan’s algorithm.

Note

This code was previously located in the CBD.depGraph.DepGraph and 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

dfsSort(depGraph, object, sortedList)[source]

Performs a depth first search, collecting the objects in topological order.

Parameters
  • depGraph (CBD.depGraph.DepGraph) – The dependency graph

  • object – The currently visited object

  • sortedList (list) – Partially sorted list of objects

dfsCollect(depGraph, object, component, curIt)[source]

Collects members of a strong component.

Parameters
  • depGraph (CBD.depGraph.DepGraph) – The dependency graph

  • object – Node currently visited

  • component (list) – Current component

  • curIt (int) – The current iteration