pydcop.algorithms.dsatuto
This module contains a very simple implementation of DSA, for demonstration purpose.
To keep things as simple as possible, we implemented the bare minimum, and avoided some details you would generally care about:
no algorithm parameters (threshold, variants, etc.)
no computation footprint nor message size
- class DsaTutoComputation(computation_definition: ComputationDef)
A very simple DSA implementation.
- Parameters:
variable (Variable) – an instance of Variable, whose this computation is responsible for
constraints (an iterable of constraints objects) – The constraints the variables depends on
computation_definition (ComputationDef) – the definition of the computation, given as a ComputationDef instance.
- on_new_cycle(messages, cycle_id) List | None
Called when switching to a new cycle.
This method must be overridden in derived classes, this is where you write the logic of your synchronous algorithm. It is automatically called when all messages have been received for the current cycle and should be handled. When handling these messages, the computation will generally also send messages to some of its neighbors; this can be achieved either by using post_msg or by returning the list of messages that must be sent for this cycle. Notice that these messages will be delivered in the next cycle.
Notes
You are only allowed to send at most one message to any given neighbor in a cycle. If you send several messages to the same neighbor, a ComputationException will be raised by this neighbor in the next cycle, when receiving them.
- Parameters:
messages (dict) – all the messages received for this cycle (i.e. that have been set by neighbors during the previous cycle). The keys of the dict are the sender of the message, the values are tuple (message, time).
cycle_id (int) – id for this cycle
- Returns:
messages – a list of tuples (target, message) with the messages to be sent to neighbors for this cycle (which they will receive at the next cycle).
- Return type:
list of None
- on_start()
Called when starting the computation.
This method is meant to be overwritten in subclasses.