Search Results for

    Show / Hide Table of Contents

    Class InitializationMethod

    Base class for algorithms that initialize a particle system. Inherit from this class and implement a method called Generate to create an initialization algorithm.

    An initialization algorithm creates a system of InitializationParticles, which is used as a template to initialize the system of Particles in which the simulation is carried out.

    Inheritance
    object
    InitializationMethod
    BinOpTestInitializer
    ChiralityAndCompassInitializer
    CollisionTestAlgoInitializer
    CollisionTestAlgo2Initializer
    ExpandedCircuitTestInitializer
    JMTestInitializer
    LeaderElectionInitializer
    LineFormationInitializer
    ObjectTestInitializer
    PASCTestAlgoInitializer
    SingleSourceSPInitializer
    SmartMaterialInitializer
    SubroutineTestInitializer
    SubroutineTest2Initializer
    InitRandomWithHoles
    Namespace: AS2
    Assembly: .dll
    Syntax
    public abstract class InitializationMethod

    Constructors

    | Edit this page View Source

    InitializationMethod(ParticleSystem)

    Declaration
    public InitializationMethod(ParticleSystem system)
    Parameters
    Type Name Description
    ParticleSystem system

    Fields

    | Edit this page View Source

    system

    The system in which particles are created.

    Declaration
    private ParticleSystem system
    Field Value
    Type Description
    ParticleSystem

    Methods

    | Edit this page View Source

    AddObjectToSystem(ParticleObject)

    Adds a copy of the given object o to the system. Note that you cannot make any changes to an object once it has been added to the system.

    Declaration
    public void AddObjectToSystem(ParticleObject o)
    Parameters
    Type Name Description
    ParticleObject o

    The object to be added.

    | Edit this page View Source

    AddParticle(Vector2Int, Direction, Chirality, Compass)

    Adds a new particle with the given parameters to the system.

    Declaration
    public InitializationParticle AddParticle(Vector2Int position, Direction headDir = Direction.NONE, Initialization.Chirality chirality = Chirality.CounterClockwise, Initialization.Compass compassDir = Compass.E)
    Parameters
    Type Name Description
    Vector2Int position

    The initial tail position of the particle.

    Direction headDir

    The initial global head direction of the particle. NONE means that the particle is contracted.

    Initialization.Chirality chirality

    The chirality of the particle.

    Initialization.Compass compassDir

    The compass direction of the particle.

    Returns
    Type Description
    InitializationParticle

    The new initialization particle.

    | Edit this page View Source

    CreateObject(Vector2Int, int)

    Creates a new object occupying the given position. When the object is finished, submit it to the system by calling AddObjectToSystem(ParticleObject).

    Declaration
    public ParticleObject CreateObject(Vector2Int pos, int identifier = 0)
    Parameters
    Type Name Description
    Vector2Int pos

    The first grid position occupied by the new object.

    int identifier

    The identifier of the new object. Does not have to be unique.

    Returns
    Type Description
    ParticleObject

    A new object with the given identifier occupying the given position pos.

    | Edit this page View Source

    GenerateRandomConnectedPositions(Vector2Int, int, float, bool, Func<Vector2Int, bool>, bool, bool, float)

    Randomly generates a set of connected grid positions according to the given constraints.

    The algorithm performs a breadth-first search starting at the given startPos. In each iteration, one of the open neighbors is chosen randomly to place a position or mark a position as a hole. If there are no more open neighbor positions, one of the marked hole positions is chosen instead. Before placing a new position, it is checked whether doing this would close an inner boundary in case this is not allowed.

    Declaration
    public List<Vector2Int> GenerateRandomConnectedPositions(Vector2Int startPos, int numPositions, float holeProb = 0.3, bool fillHoles = false, Func<Vector2Int, bool> excludeFunc = null, bool allowExcludedHoles = true, bool prioritizeInner = false, float lambda = 0.1)
    Parameters
    Type Name Description
    Vector2Int startPos

    The start position of the shape. This position is always part of the resulting set, even if it should be excluded.

    int numPositions

    The desired number of grid positions in the generated set.

    float holeProb

    The probability of a random candidate position selected to be kept unoccupied.

    bool fillHoles

    If true, the system of positions is not allowed to have inner boundaries.

    Func<Vector2Int, bool> excludeFunc

    A function that marks grid positions as excluded such that no excluded position is contained in the resulting set. Note that it is possible that the resulting set is smaller than desired if there is not enough room for all positions.

    bool allowExcludedHoles

    If fillHoles is true, this controls whether inner boundaries that surround empty regions containing excluded positions are allowed.

    bool prioritizeInner

    If true, new positions are not selected uniformly at random from the set of candidate locations, but using an exponential distribution that prioritizes positions close to the startPos.

    float lambda

    The lambda parameter of the exponential distribution if prioritizeInner is true. Larger values lead to a stronger bias towards positions close to startPos. Very small values can lead to a bias towards positions further away.

    Returns
    Type Description
    List<Vector2Int>

    A list of grid positions forming a connected system according to the specified constraints.

    | Edit this page View Source

    GenerateRandomWithHoles(int, float, Chirality, Compass)

    Generates a system with a fixed number of particles using a randomized breadth-first-search algorithm that leaves out some positions to insert holes. It is guaranteed that the desired number of particles is placed because if all available locations are marked as holes, one of them is chosen at random to be replaced with a particle and keep the algorithm going. All particles are contracted.

    Declaration
    public void GenerateRandomWithHoles(int numParticles = 50, float holeProb = 0.3, Initialization.Chirality chirality = Chirality.CounterClockwise, Initialization.Compass compassDir = Compass.E)
    Parameters
    Type Name Description
    int numParticles

    The number of particles to place.

    float holeProb

    The probability of a grid position becoming a hole when it is first encountered. Note that the final system might still have holes if this is set to 0.

    Initialization.Chirality chirality

    The chirality setting for all particles.

    Initialization.Compass compassDir

    The compass setting for all particles.

    | Edit this page View Source

    GetParticles()

    Returns an array of all currently placed particles. This is useful for cases where particle parameters have to be set after the particles were placed and where chirality and compass directions were chosen randomly.

    Declaration
    public InitializationParticle[] GetParticles()
    Returns
    Type Description
    InitializationParticle[]

    An array containing all current particles.

    | Edit this page View Source

    HoleValidSearch(Vector2Int, Vector2Int, Vector2Int, HashSet<Vector2Int>, Func<Vector2Int, bool>)

    Random placement helper that checks whether a hole that would be closed by placing a new position is allowed or not. Uses a BFS to search for a goal node that is a corner of the occupied system's bounding box or for any excluded position.

    Declaration
    private bool HoleValidSearch(Vector2Int startNode, Vector2Int goalNode, Vector2Int openingPos, HashSet<Vector2Int> occupied, Func<Vector2Int, bool> excludeFunc)
    Parameters
    Type Name Description
    Vector2Int startNode

    The node from which the search should be started.

    Vector2Int goalNode

    The closest corner of the occupied system's bounding rectangle. If the search ever visits this position's x or y coordinate, the hole is considered to be open to the outer boundary.

    Vector2Int openingPos

    The grid node where the new position should be placed, used to limit the search to this side of the hole.

    HashSet<Vector2Int> occupied

    The set of occupied positions.

    Func<Vector2Int, bool> excludeFunc

    The function that marks positions as excluded. Must not be null.

    Returns
    Type Description
    bool

    true if and only if the search reaches the bounding rectangle of the occupied system or an excluded node.

    | Edit this page View Source

    IsPositionHoleOpening(Vector2Int, HashSet<Vector2Int>, Func<Vector2Int, bool>, bool)

    Random placement helper that checks whether placing a position would close an inner boundary that should not be closed.

    Declaration
    private bool IsPositionHoleOpening(Vector2Int pos, HashSet<Vector2Int> occupied, Func<Vector2Int, bool> excludeFunc, bool allowExcludedHoles)
    Parameters
    Type Name Description
    Vector2Int pos

    The new position to be placed.

    HashSet<Vector2Int> occupied

    The set of already occupied positions.

    Func<Vector2Int, bool> excludeFunc

    A function marking some grid nodes as excluded.

    bool allowExcludedHoles

    Determines whether inner boundaries around empty regions that contain excluded positions are allowed.

    Returns
    Type Description
    bool

    true if and only if placing pos would close an inner boundary that should not be closed.

    | Edit this page View Source

    PlaceParallelogram(Vector2Int, Direction, int, bool, int, Chirality, Compass)

    Adds contracted particles in the shape of a parallelogram. The particles are added row by row, where length determines how many particles are in a row and height determines how many rows there are. Rows are offset to form an acute angle at the start location if acuteAngle is true, i.e., the offset direction is the main direction rotated by 60� in counter-clockwise direction. Otherwise, the offset direction will be rotated by 120� and the angle becomes obtuse.

    Declaration
    public void PlaceParallelogram(Vector2Int startPos, Direction mainDir, int length, bool acuteAngle = true, int height = 1, Initialization.Chirality chirality = Chirality.CounterClockwise, Initialization.Compass compass = Compass.E)
    Parameters
    Type Name Description
    Vector2Int startPos

    The position at which the first particle will be placed.

    Direction mainDir

    The direction in which rows grow.

    int length

    The number of particles in each row.

    bool acuteAngle

    If true, the parallelogram's angle at the first particle is acute (60�), otherwise, it is obtuse (120�).

    int height

    The number of rows.

    Initialization.Chirality chirality

    The chirality setting for all particles.

    Initialization.Compass compass

    The compass setting for all particles.

    | Edit this page View Source

    RemoveParticleAt(Vector2Int)

    Removes the InitializationParticle at the given position.

    Declaration
    public void RemoveParticleAt(Vector2Int position)
    Parameters
    Type Name Description
    Vector2Int position

    The grid position from which a particle should be removed. If an expanded particle occupies this position, its other occupied position will be free as well.

    | Edit this page View Source

    TryGetParticleAt(Vector2Int, out InitializationParticle)

    Tries to get the InitializationParticle at the given position.

    Declaration
    public bool TryGetParticleAt(Vector2Int position, out InitializationParticle particle)
    Parameters
    Type Name Description
    Vector2Int position

    The grid position at which to look for the particle.

    InitializationParticle particle

    The particle at the given position, if it exists, otherwise null.

    Returns
    Type Description
    bool

    true if and only if a particle was found at the given position.

    • Edit this page
    • View Source
    In this article
    Back to top AmoebotSim 2.0 Documentation v1.11
    Copyright © 2025 AmoebotSim 2.0 Authors
    Generated by DocFX