Class SubLeaderElectionFast
Fast leader election subroutine. Uses 4 pins to establish 4
global circuits and transmit all coin toss results in a single
round instead of 4. Also skips the first phase because it is
unnecessary.
See SubLeaderElection
for a more detailed description.
Usage:
-
Initialize by calling Init(bool, bool, int). At least
one amoebot in the system should be a candidate.
-
Setup a pin configuration using SetupPC(PinConfiguration).
This only has to be called once and the same pin configuration can be used
for the whole duration of the leader election.
-
Call ActivateSend() to send the beeps and then call
ActivateReceive() in the next round to receive the beeps. Then repeat
this until the procedure is finished.
-
You can check whether the procedure has finished using IsFinished()
and find the elected leader using IsLeader().
Inheritance
SubLeaderElectionFast
Assembly: .dll
Syntax
public class SubLeaderElectionFast : Subroutine
Constructors
SubLeaderElectionFast(Particle)
Declaration
public SubLeaderElectionFast(Particle p)
Parameters
Fields
cand1
Declaration
private BinAttributeBool cand1
Field Value
cand2
Declaration
private BinAttributeBool cand2
Field Value
candidateColor
Declaration
private static readonly Color candidateColor
Field Value
controlColor
Declaration
private BinAttributeBool controlColor
Field Value
counter
Declaration
private BinAttributeInt counter
Field Value
finished
Declaration
private BinAttributeBool finished
Field Value
finishedColor
Declaration
private static readonly Color finishedColor
Field Value
head1
Declaration
private BinAttributeBool head1
Field Value
head2
Declaration
private BinAttributeBool head2
Field Value
helperColor
Declaration
private static readonly Color helperColor
Field Value
kappa
Declaration
private BinAttributeInt kappa
Field Value
retiredColor
Declaration
private static readonly Color retiredColor
Field Value
state
Declaration
private ParticleAttribute<int> state
Field Value
Methods
ActivateReceive()
First half of the subroutine activation. Receives beeps
sent by ActivateSend() in the last round.
Declaration
public void ActivateReceive()
ActivateSend()
Second half of the subroutine activation. Sends beeps to
be received by ActivateReceive() in the next
round. The required pin configuration must have been set
up by SetupPC(PinConfiguration) (not necessarily
in this round).
Declaration
public void ActivateSend()
Init(bool, bool, int)
Initializes the leader election.
Declaration
public void Init(bool isCandidate, bool controlColor = false, int kappa = 3)
Parameters
Type |
Name |
Description |
bool |
isCandidate |
Whether this amoebot is a leader
candidate. There should be at least one candidate in the system.
|
bool |
controlColor |
Whether the subroutine should control the
amoebot color to indicate its progress.
|
int |
kappa |
The number of repetitions to complete.
|
IsFinished()
Checks whether the subroutine is finished.
Declaration
Returns
Type |
Description |
bool |
true if and only if the
subroutine has finished.
|
IsLeader()
Checks whether this amoebot is the elected leader.
Declaration
Returns
Type |
Description |
bool |
true if and only if the subroutine
has finished and this amoebot is the leader.
|
SetupPC(PinConfiguration)
Sets up the pin configuration required for the next
ActivateSend() call. Creates 4 global circuits
using all 4 pins and partition set IDs 0,...,3.
This is not necessary if the pin configuration was not
changed since the first call of this method.
Declaration
public void SetupPC(PinConfiguration pc)
Parameters