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
object
SubLeaderElectionFast
Assembly: .dll
Syntax
public class SubLeaderElectionFast : Subroutine
Constructors
|
Edit this page
View Source
SubLeaderElectionFast(Particle)
Declaration
public SubLeaderElectionFast(Particle p)
Parameters
Fields
|
Edit this page
View Source
cand1
Declaration
private BinAttributeBool cand1
Field Value
|
Edit this page
View Source
cand2
Declaration
private BinAttributeBool cand2
Field Value
|
Edit this page
View Source
candidateColor
Declaration
private static readonly Color candidateColor
Field Value
|
Edit this page
View Source
controlColor
Declaration
private BinAttributeBool controlColor
Field Value
|
Edit this page
View Source
counter
Declaration
private BinAttributeInt counter
Field Value
|
Edit this page
View Source
finished
Declaration
private BinAttributeBool finished
Field Value
|
Edit this page
View Source
finishedColor
Declaration
private static readonly Color finishedColor
Field Value
|
Edit this page
View Source
head1
Declaration
private BinAttributeBool head1
Field Value
|
Edit this page
View Source
head2
Declaration
private BinAttributeBool head2
Field Value
|
Edit this page
View Source
helperColor
Declaration
private static readonly Color helperColor
Field Value
|
Edit this page
View Source
kappa
Declaration
private BinAttributeInt kappa
Field Value
|
Edit this page
View Source
retiredColor
Declaration
private static readonly Color retiredColor
Field Value
|
Edit this page
View Source
state
Declaration
private ParticleAttribute<int> state
Field Value
Methods
|
Edit this page
View Source
ActivateReceive()
First half of the subroutine activation. Receives beeps
sent by ActivateSend() in the last round.
Declaration
public void ActivateReceive()
|
Edit this page
View Source
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()
|
Edit this page
View Source
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.
|
|
Edit this page
View Source
IsFinished()
Checks whether the subroutine is finished.
Declaration
Returns
Type |
Description |
bool |
true if and only if the
subroutine has finished.
|
|
Edit this page
View Source
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.
|
|
Edit this page
View Source
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