pydistsim.algorithm.base_algorithm.BaseAlgorithm

class BaseAlgorithm(simulation: Simulation, **kwargs)[source]

Bases: ObserverManagerMixin

Abstract 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_observers

apply_restrictions

Apply all applicable restrictions.

check_restrictions

Check if the restrictions are satisfied.

clear_observers

is_halted

Check if the distributed algorithm has come to an end or deadlock.

is_initialized

notify_observers

reset

Reset the algorithm to its initial state.

step

Attributes

algorithm_restrictions

Tuple of restrictions that must be satisfied for the algorithm to run.

default_params

network

required_params

algorithm_restrictions = ()

Tuple of restrictions that must be satisfied for the algorithm to run.

apply_restrictions()[source]

Apply all applicable restrictions.

check_restrictions()[source]

Check if the restrictions are satisfied. Does not apply ApplicableRestrictions.

is_halted()[source]

Check if the distributed algorithm has come to an end or deadlock.

reset()[source]

Reset the algorithm to its initial state.