Class LineFormationParticleSync
Basic line formation algorithm that assumes a connected system
as well as common chirality and compass alignment. Designed to
work in the fully synchronous execution model where all particles
are activated in each round.
The algorithm uses only 1 pin per edge.
Inheritance
LineFormationParticleSync
Assembly: .dll
Syntax
public class LineFormationParticleSync : ParticleAlgorithm
Constructors
LineFormationParticleSync(Particle)
Declaration
public LineFormationParticleSync(Particle p)
Parameters
Fields
beepInLastRound
Declaration
private ParticleAttribute<bool> beepInLastRound
Field Value
constructionDir
Declaration
public ParticleAttribute<Direction> constructionDir
Field Value
finishedColor
Declaration
private static Color finishedColor
Field Value
flwrColor
Declaration
private static Color flwrColor
Field Value
followDir
Declaration
public ParticleAttribute<Direction> followDir
Field Value
handoverBeepDirection
Declaration
private ParticleAttribute<Direction> handoverBeepDirection
Field Value
hasChosenRoot
Declaration
private ParticleAttribute<bool> hasChosenRoot
Field Value
idleColor
Declaration
private static Color idleColor
Field Value
inlineColor
Declaration
private static Color inlineColor
Field Value
leaderColor
Declaration
private static Color leaderColor
Field Value
localLineComplete
Declaration
private ParticleAttribute<bool> localLineComplete
Field Value
moveDir
Declaration
public ParticleAttribute<Direction> moveDir
Field Value
rootColor
Declaration
private static Color rootColor
Field Value
rootHandoverAvailable
Declaration
public ParticleAttribute<bool> rootHandoverAvailable
Field Value
state
Declaration
public ParticleAttribute<LineFormationParticleSync.LFState> state
Field Value
Properties
GenerationMethod
Declaration
public static string GenerationMethod { get; }
Property Value
Name
Declaration
public static string Name { get; }
Property Value
PinsPerEdge
The number of pins on each edge.
This number must be the same constant for all
particles.
Declaration
public override int PinsPerEdge { get; }
Property Value
Overrides
Methods
ActivateBeep()
This is the second part of the main activation logic of the
particle. It is called exactly once in each round, after the
movements scheduled in ActivateMove() have been
executed, and should contain the algorithm code that
implements the look-compute-beep cycle.
Inside of this method, particles are allowed to change their
pin configuration and send beeps and messages on the updated
configuration.
Note that beeps and messages sent in the current round will
be readable in both the ActivateMove() and
ActivateBeep() calls in the next round.
Declaration
public override void ActivateBeep()
Overrides
ActivateMove()
This is one part of the main activation logic of the particle.
It is called exactly once in each round and should contain the
algorithm code that implements the look-compute-move cycle.
After the movements are executed, ActivateBeep()
is called within the same round.
Inside of this method, particles are allowed to release bonds,
define which bonds should be marked, and schedule movements.
Only the last movement operation scheduled in this method will
be applied.
Declaration
public override void ActivateMove()
Overrides
CheckLocalCompleteness()
Checks if the line is locally complete.
Declaration
private bool CheckLocalCompleteness()
Returns
Type |
Description |
bool |
true if and only if the only neighbors
are LEADER or INLINE particles directly in or directly opposite
of the construction direction.
|
ComputeRootMoveDir()
Declaration
private int ComputeRootMoveDir()
Returns
ComputeRootMoveDir(Neighbor<LineFormationParticleSync>)
Computes the next movement direction of the contracted ROOT
particle and determines whether it is about to enter the end
position of the line.
Declaration
private int ComputeRootMoveDir(Neighbor<LineFormationParticleSync> nbr)
Parameters
Returns
Type |
Description |
int |
1 if we are about to enter the end position of
the line from the left side, 2 if we are about to enter
from the right side, and 0 otherwise.
|
DrawPath(ParticleSystem, Particle)
Declaration
[StatusInfo("Draw FLWR Path", "Draws the follower path from the currently selected FLWR particle to its ROOT parent.", false)]
public static void DrawPath(ParticleSystem system, Particle selected)
Parameters
DrawSpanningTree(ParticleSystem, Particle)
Declaration
[StatusInfo("Draw Spanning Tree", "Draws the entire spanning tree, i.e., the parent edges for all FLWR particles.", true)]
public static void DrawSpanningTree(ParticleSystem system, Particle selected)
Parameters
FlwrBeep()
Declaration
FlwrMove()
Declaration
HaveBlockingTailNeighbor()
Declaration
private bool HaveBlockingTailNeighbor()
Returns
IdleActivate()
Declaration
private void IdleActivate()
Init(bool)
Declaration
public void Init(bool leader = false)
Parameters
Type |
Name |
Description |
bool |
leader |
|
InlineActivate()
Declaration
private void InlineActivate()
IsFinished()
Checks whether this particle has finished its algorithm.
Override this method to return true
when a particle
is done executing the algorithm. Once all particles in the
system are finished, the simulation will stop automatically.
When a particle's state results in this method returning
true
, its activation methods should not change its
state any more.
Declaration
public override bool IsFinished()
Returns
Type |
Description |
bool |
true if and only if this particle has
finished its algorithm.
|
Overrides
LeaderActivate()
Declaration
private void LeaderActivate()
PullIfSentBeep()
Assuming that we are expanded, check if we have received a
beep on one of our tail edges incident to a contracted FLWR.
If we have, that means that we have sent that beep and we can
now pull the particle at that edge.
Will perform the pull handover immediately.
Declaration
private bool PullIfSentBeep()
Returns
Type |
Description |
bool |
true if and only if we can perform the pull
handover due to a beep on the corresponding edge.
|
RootActivate()
Declaration
private void RootActivate()
RootBeep()
Declaration
RootMove()
Declaration
SendBeepForPull()
Assuming that we are expanded, search for a contracted FLWR particle
that is following our tail and send a beep in its direction if we
find one. Schedules the beep using handoverBeepDirection
so it can be sent in the next beep phase.
In the next round, PullIfSentBeep() can be used to check
if and where we have sent a beep and perform the corresponding pull
handover.
Declaration
private bool SendBeepForPull()
Returns
Type |
Description |
bool |
true if and only if we can send a beep to a contracted
FLWR following our tail.
|
SendBeepToWaitingRoot()
Procedure of LEADER and INLINE particles to decide which of
the up to 2 waiting ROOT particles may move to the end
position of the line. If this situation is detected and a
decision can be made, a beep is sent to the chosen ROOT.
Declaration
private bool SendBeepToWaitingRoot()
Returns
Type |
Description |
bool |
true if and only if a ROOT particle was
chosen or no ROOT particle will ever be chosen because the
next position in the line is already occupied by an INLINE
particle.
|
TryToBecomeInline()
Declaration
private bool TryToBecomeInline()
Returns
TryToBecomeInline(Neighbor<LineFormationParticleSync>)
Declaration
private bool TryToBecomeInline(Neighbor<LineFormationParticleSync> nbr)
Parameters
Returns
TryToBecomeRootOrInline()
Searches for a neighbor in state INLINE or LEADER and goes to
state INLINE if we are at the end of the line or state ROOT if
we are not. If no such neighbor is found, the state does not
change.
Declaration
private int TryToBecomeRootOrInline()
Returns
Type |
Description |
int |
2 if we are now INLINE, 1 if we are now
a ROOT, 0 otherwise.
|