pydistsim.algorithm.base_algorithm.BaseAlgorithm
- class BaseAlgorithm(simulation: Simulation, **kwargs)[source]
Bases:
ObserverManagerMixinAbstract base class for all algorithms.
Currently there are two main subclasses: * NodeAlgorithm used for distributed algorithms * NetworkAlgorithm used for centralized algorithms
When writing new algorithms make them subclass either of NodeAlgorithm or NetworkAlgorithm.
Every algorithm instance has a set of required and default params: * Required params must be given to algorithm initializer as a keyword
arguments.
- Default params can be given to algorithm initializer as a keyword
arguments, if not their class defines default value.
Note: On algorithm initialization all params are converted to instance attributes.
For example:
- class SomeAlgorithm(NodeAlgorithm):
required_params = (‘rp1’,) default_params = {‘dp1’: ‘dv1’,}
>>> net = DirectedNetwork() >>> alg = SomeAlgorithm(net, rp1='rv1') >>> alg.rp1 'rv1' >>> alg.dp1 'dv1'
Params in algorithm subclasses are inherited from its base classes, that is, required params are extended and default are updated: * required_params are union of all required params of their ancestor
classes.
default_params are updated so default values are overridden in subclasses
Methods
__init__add_observersApply all applicable restrictions.
Check if the restrictions are satisfied.
clear_observersCheck if the distributed algorithm has come to an end or deadlock.
is_initializednotify_observersReset the algorithm to its initial state.
stepAttributes
Tuple of restrictions that must be satisfied for the algorithm to run.
default_paramsnetworkrequired_params- algorithm_restrictions = ()
Tuple of restrictions that must be satisfied for the algorithm to run.