Class AgentModel<A extends Agent>

Type Parameters:
A - the class of the agents

public abstract class AgentModel<A extends Agent> extends Simulation
A simulation of agents in a box (e.g., a swarm): the agents (subclasses of Agent) are displayed as spheres in the 3D view of Bio7 (and in the 3D view of the HTML export). The box goes from 0 to boxWidth (x), boxHeight (y) and boxDepth (z, the height).
public class Walkers extends AgentModel<Walkers.Walker> {
        static class Walker extends Agent {
                Walker(double x, double y, double z) {
                        super(x, y, z);
                }
        }

        public void init() {
                box(100, 100, 50);
                for (int i = 0; i < 100; i++)
                        agents.add(new Walker(random() * 100, random() * 100, random() * 50));
        }

        public void step() {
                for (Walker w : agents)
                        w.z = Math.max(0, Math.min(50, w.z + random() - 0.5));
        }
}
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    An object of the environment: a 3D model (glTF, loaded with loadModel) at a place of the box.

    Nested classes/interfaces inherited from class Simulation

    Simulation.Derivatives
    Modifier and Type
    Class
    Description
    static interface 
    The derivatives of a system of differential equations: dy/dt = f(t, y).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The color of the agents without an own color.
    double
    The radius of the spheres (in the units of the box, 0: 1 % of the box).
    The agents.
    The shape of the agents without an image or a model: "sphere" (default) or "glider" (a glider of triangles which points in the direction of its movement, climbs, dives and banks into turns; its size: agentRadius).
    double
    The size of the box.
    double
    The size of the box.
    double
    The size of the box.
    The floor: "none" (the edges of the box, default), "grid" (lines) or "plane" (a dark floor with a grid).
    int
    The agent (its index) which the custom camera of the 3D view follows from behind (with the split view: the global view beside it); -1: none.
    The color of the links (drawn as lines between the agents; null or "": not drawn).
    double
    The width of the links in pixels.
    boolean
    Soft shadows of the agents on the floor.

    Fields inherited from class Simulation

    arrangeViews, DEFAULT_SEED, t
    Modifier and Type
    Field
    Description
    boolean
    true (default): the first setup arranges the views in the Custom perspective of Bio7: the display of the model (ImageJ, the 3D view or the WorldWind globe) on the right, its options (e.g., Options3D) top left and the settings left.
    static final int
    The seed of the random numbers (set it in init() with seed(...)).
    int
    The number of the time steps since the setup.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    The distance of two agents (3D): the same name as for the agents of a grid (GridModel.agentDistance).
    void
    box(double width, double height, double depth)
    Sets the size of the box.
    void
    cameraFollow(int index)
    The camera of the 3D view follows the agent with this index (the split view shows the global view beside it); a negative index: no camera (the same as the field followAgent, camera_follow in Python and R).
    void
    Removes all links.
    void
    Removes all objects of the environment.
    double
    The clustering coefficient of an agent: the share of the pairs of its linked agents which are linked too (0 with less than 2).
    The groups of the agents which are connected by links (each in the order of the list; isolated agents are a group).
    int
    degree(A a)
    The number of links of the agent.
    protected void
    Displays the model (ImageJ image or 3D view).
    double
    The distance of two agents (3D); the same as agentDistance(Agent, Agent).
    int[]
    The links as pairs of the indices of the agents in the list (i, j with i invalid input: '<' j; i ascending).
    The objects of the environment (a copy).
    index(double cellSize)
    A spatial index of the agents (their positions now; the size of the cells: e.g., the radius of the searches): fast searches of the neighbors of many agents (see SpatialIndex).
    void
    Keeps the agent in the box (the position is limited to the box).
    void
    Places the agents on a circle in the middle of the box (in the order of the list; z: the middle of the box).
    void
    layoutSpring(int iterations)
    Arranges the network in x and y (a spring layout of Fruchterman and Reingold: the links pull, all agents push each other away), in the box; z is kept.
    void
    link(A a, A b)
    Links two agents (undirected; no link of an agent with itself, a link once).
    void
    link(A a, A b, String color)
    Links two agents with a color of the link (e.g., "#d62728" for a path of an infection).
    linkColorOf(A a, A b)
    The color of the link of two agents (null: linkColor or no link).
    int
    The number of links (between agents of the list).
    boolean
    linked(A a, A b)
    True if the agents are linked.
    void
    linkNearby(double radius)
    Links all agents within the distance (a network of the neighborhood, with a spatial index).
    The agents linked with the agent (in the order of the links).
    void
    linkRandom(double p)
    A random network: each pair of agents is linked with the probability p (Erdos-Renyi).
    int[]
    The links as pairs of the indices of the agents in the list: i0, j0, i1, j1, ...
    void
    A scale-free network (Barabasi-Albert): the first m + 1 agents are linked with each other, each further agent links with m agents before it, chosen with a probability proportional to their number of links.
    void
    linkSmallWorld(int k, double p)
    A small-world network (Watts-Strogatz): a ring of the agents (in the order of the list), each linked with its k nearest (k / 2 on each side), then each link is moved to a random agent with the probability p.
    nearest(A agent, double radius)
    The nearest other agent within the radius (null if none).
    int[]
    neighborPairs(double distance)
    All pairs of agents closer than the distance (with a spatial index: fast for thousands of agents) as indices of the list: i0, j0, i1, j1, ...
    neighbors(A agent, double radius)
    The other agents within the radius of the agent (in the order of the list).
    int
    placeModel(String model, double x, double y, double z, double heading, double size)
    Places a 3D model (glTF, loaded with loadModel) in the environment, e.g., a house, a tree or a rock: it stays until it is removed (not drawn again in each step).
    int
    placeModel(String model, double x, double y, double z, double heading, double size, String animation)
    Places a 3D model with an animation (its name or number, "none": still), see placeModel.
    protected void
    Prepares the display before init() (called in the thread of the user interface).
    void
    Removes all links of the agent (e.g., before it is removed from the list).
    void
    removeModel(int index)
    Removes the object of the environment with the index (placeModel); the later ones move up by one.
    void
    run(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.opengl.util.gl2.GLUT glut)
    The main OpenGL method with the OpenGL context as parameters!
    void
    setLinkColor(A a, A b, String color)
    Sets the color of an existing link (null: linkColor).
    int
    shortestPath(A a, A b)
    The number of links on the shortest path between two agents (-1: not connected).
    void
    unlink(A a, A b)
    Removes the link of two agents.
    void
    Moves the agent to the other side of the box if it left it (x and y: a torus, z: limited).

    Methods inherited from class Simulation

    chance, chart, chart, chartBars, chartXY, clamp, click, correlation, cosDeg, determinant, distance, distance3, dot, drag, drawBox, drawCircle, drawCircle, drawImage, drawImage, drawLine, drawLine, drawLine3, drawPath, drawPath, drawPath3, drawPillar, drawPoint3, drawPolygon, drawPolygon, drawPolygon3, drawRect, drawRect, drawSphere, drawText, drawText, fractalNoise, getCharts, getDrawing, getImageFiles, getModelFiles, getSeries, getStartSeed, headingOf, init, inverse, isStopped, key, lerp, linearRegression, loadImage, loadModel, logistic, logisticGrowth, mapRange, matMul, matVec, max, mean, mean, median, min, noise, norm, normalCdf, normalPdf, quantile, random, random, randomAt, randomAt, randomBinomial, randomElement, randomExponential, randomGaussian, randomGaussian, randomInt, randomInt, randomPoisson, randomWeighted, record, rk4, run, sd, seed, setStartSeed, settings, setup, shuffle, sinDeg, solve, sq, startAfterCreation, step, stop, sum, sum, transpose, variance, wrapAround
    Modifier and Type
    Method
    Description
    boolean
    chance(double p)
    true with the probability p (e.g., chance(0.1): in 10 % of the calls).
    void
    chart(String name, double value)
    A value of a series of the first chart (one value per step; the Charts view of Bio7 and the HTML page).
    void
    chart(String chart, String name, double value)
    A value of a series of another chart with a title (a second, third, ...
    void
    chartBars(String chart, String[] labels, double[] values)
    A bar chart with a title: the labels and the values (replaced in each call, e.g., a histogram).
    void
    chartXY(String chart, String name, double x, double y)
    A point (x, y) of a series of an XY chart with a title (e.g., a phase plot of two populations).
    static double
    clamp(double value, double min, double max)
    The value limited to [min, max].
    void
    click(double x, double y)
    A click of the mouse in the view of the model (override it): for a grid the position in cells (the cell ((int) x, (int) y), y from the top as in get(x, y)), for an agent model the point on the floor of the box.
    static double
    correlation(double[] x, double[] y)
    The correlation coefficient of Pearson.
    static double
    cosDeg(double deg)
    The cosine of an angle in degrees (the same digits in Bio7 and in the browser, e.g., for a movement in the heading).
    static double
    determinant(double[][] a)
    The determinant of a matrix.
    static double
    distance(double x1, double y1, double x2, double y2)
    The distance of two points in 2D.
    static double
    distance3(double x1, double y1, double z1, double x2, double y2, double z2)
    The distance of two points in 3D.
    static double
    dot(double[] a, double[] b)
    The dot product of two vectors.
    void
    drag(double x, double y)
    A drag of the mouse in the view of the model (override it), e.g., to paint cells: called for the position where the drag started and for each further position (a grid: each new cell).
    void
    drawBox(double x, double y, double z, double w, double h, double d, String fill, String stroke)
    A box in 3D (an agent model): the corner x, y, z (the lowest values), the width (x), the height (y) and the depth (z, upwards) as in box(...); fill: the color of the sides, stroke: the color of the edges (null: none), e.g., a house or a tower.
    void
    drawCircle(double x, double y, double radius, String fill, String stroke)
    A circle (a geospatial agent model: the radius in km).
    void
    drawCircle(double x, double y, double radius, String fill, String stroke, double z)
    A circle at the height z above the floor (an agent model).
    void
    drawImage(String name, double x, double y, double size, double angle)
    An image (loaded with loadImage) centered at x, y: the size (the larger side, in cells of a grid, in pixels on a map or the globe) and the angle in degrees (clockwise, e.g., the heading of an animal).
    void
    drawImage(String name, double x, double y, double size, double angle, double z)
    An image at the height z above the floor (an agent model: the lower edge of the image, standing).
    void
    drawLine(double x1, double y1, double x2, double y2, String color, double width)
    A line (the width in pixels).
    void
    drawLine(double x1, double y1, double x2, double y2, String color, double width, double z)
    A line at the height z above the floor (an agent model).
    void
    drawLine3(double x1, double y1, double z1, double x2, double y2, double z2, String color, double width)
    A line in 3D (an agent model: x, y, z of the box).
    void
    drawPath(double[] xs, double[] ys, String color, double width)
    A line through the points (e.g., the track of an agent).
    void
    drawPath(double[] xs, double[] ys, String color, double width, double z)
    A line through the points at the height z above the floor (an agent model).
    void
    drawPath3(double[] xs, double[] ys, double[] zs, String color, double width)
    A line through the points in 3D (an agent model; the width in pixels), e.g., a flight path.
    void
    drawPillar(double x, double y, double radius, double height, String color)
    A pillar in 3D (an agent model: a vertical cylinder from the floor at x, y of the box with the radius and the height, e.g., an obstacle; color: e.g., "#9aa6b8").
    void
    drawPoint3(double x, double y, double z, double size, String color)
    A point in 3D (an agent model): a small sphere with the diameter size, e.g., a marker.
    void
    drawPolygon(double[] xs, double[] ys, String fill, String stroke)
    A polygon (the fill and the color of the line, null: none; e.g., a pasture or a territory).
    void
    drawPolygon(double[] xs, double[] ys, String fill, String stroke, double z)
    A polygon at the height z above the floor (an agent model).
    void
    drawPolygon3(double[] xs, double[] ys, double[] zs, String fill, String stroke)
    A flat polygon in 3D (an agent model; the points should lie in a plane): the fill and the color of the outline (null: none), e.g., a roof or a ramp.
    void
    drawRect(double x, double y, double w, double h, String fill, String stroke)
    A rectangle (x, y: the upper left corner of a grid).
    void
    drawRect(double x, double y, double w, double h, String fill, String stroke, double z)
    A rectangle at the height z above the floor (an agent model).
    void
    drawSphere(double x, double y, double z, double radius, String fill)
    A sphere in 3D (an agent model): the center and the radius, e.g., a balloon or a tree crown.
    void
    drawText(double x, double y, String text, String color, double size)
    A text (the size in cells of a grid, in pixels on a map or the globe).
    void
    drawText(double x, double y, String text, String color, double size, double z)
    A text at the height z above the floor (an agent model, e.g., a label above an object).
    static double
    fractalNoise(double x, double y, int octaves)
    A fractal noise (0 - 1): the sum of octaves of noise (finer details with more octaves).
    List<com.eco.bio7.simulation.ChartData>
    Copies of all charts (the first chart has the title "").
    List<com.eco.bio7.simulation.Shape>
    The shapes of the current step (a copy).
    The images loaded with loadImage (the name and the file).
    The 3D models loaded with loadModel (the name and the file).
    Map<String, List<double[]>>
    The values of the series of the first chart (name: [step, value] pairs).
    int
    The seed of the setup (default 42; the field Seed of the settings in Bio7).
    static double
    headingOf(double dx, double dy)
    The heading of a movement (dx, dy) in degrees: 0 the direction of y, clockwise (as the angle of drawImage and the heading of the agents).
    abstract void
    Creates the start state (called by the Setup button and after the compilation).
    static double[][]
    inverse(double[][] a)
    The inverse matrix (NaN if the matrix is singular).
    boolean
    True if stop() was called in the last step (or in init()).
    void
    key(String key)
    A key pressed in the view of the model (override it): a character ("a", "A", "1", " ") or the name of a special key ("ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter", "Escape", "Backspace", "Delete", "Tab"; the names of the key of JavaScript).
    static double
    lerp(double a, double b, double t)
    The linear interpolation between a and b (t = 0: a, t = 1: b).
    static double[]
    linearRegression(double[] x, double[] y)
    The linear regression y = a + b x: the intercept a, the slope b and the coefficient of determination r².
    void
    loadImage(String name, String file)
    Loads an image (PNG with transparency, JPEG) for drawImage and the agents (agent.image = name).
    void
    loadModel(String name, String file)
    Loads a 3D model (glTF: .glb or .gltf, also animated; Wavefront OBJ with the materials and textures of its .mtl file, y up; STL, binary or ASCII, z up) for the agents (agent.model = name, agent.animation = the name of an animation) and placeModel.
    static double
    logistic(double x)
    The logistic function 1 / (1 + e^-x) (e.g., a smooth switch from 0 to 1).
    static double
    logisticGrowth(double n, double r, double k)
    The logistic growth of a population per time unit: r * n * (1 - n / k).
    static double
    mapRange(double value, double inMin, double inMax, double outMin, double outMax)
    The value of the range [inMin, inMax] in the range [outMin, outMax] (linear).
    static double[][]
    matMul(double[][] a, double[][] b)
    The product of two matrices (rows of columns).
    static double[]
    matVec(double[][] a, double[] v)
    The product of a matrix and a vector (e.g., a Leslie matrix and the age classes).
    static double
    max(double[] values)
    The maximum of the values (-Infinity if empty).
    static double
    mean(double[] values)
    The mean of the values (0 if empty).
    static double
    mean(int[] values)
    The mean of the values (0 if empty).
    static double
    median(double[] values)
    The median of the values.
    static double
    min(double[] values)
    The minimum of the values (Infinity if empty).
    static double
    noise(double x, double y)
    A smooth noise (0 - 1) at x, y (value noise: e.g., a landscape, the grass of a pasture; the same in the browser).
    static double
    norm(double[] a)
    The length of a vector.
    static double
    normalCdf(double x, double mean, double sd)
    The distribution function of the normal distribution (an accuracy of about 1e-7).
    static double
    normalPdf(double x, double mean, double sd)
    The density of the normal distribution.
    static double
    quantile(double[] values, double p)
    The quantile p (0 - 1) of the values (linear interpolation of the sorted values).
    double
    A random number in [0, 1) (the same numbers in Java and in the HTML export).
    double
    random(double min, double max)
    A random number in [min, max).
    double
    randomAt(int index)
    A random number in [0, 1) for an index (e.g., of a cell or an agent) in this time step: computed from the seed, the time step and the index (no common sequence), so it can be used in parallel threads (e.g., IntStream.range(0, height).parallel().forEach(...)) and gives the same numbers in any order of the threads, in Java and in JavaScript.
    double
    randomAt(int index, int k)
    A random number in [0, 1) for an index and a number k of the draw (several numbers for one index in a step).
    int
    randomBinomial(int n, double p)
    A random number of successes of n trials with the probability p.
    <T> T
    A random element of the list (null if empty).
    double
    randomExponential(double rate)
    An exponentially distributed random number (e.g., a waiting time) with the rate.
    double
    A normally distributed random number (mean 0, standard deviation 1).
    double
    randomGaussian(double mean, double sd)
    A normally distributed random number with the mean and the standard deviation.
    int
    randomInt(int n)
    A random integer in [0, n).
    int
    randomInt(int min, int max)
    A random integer in [min, max) (min included, max excluded).
    int
    randomPoisson(double lambda)
    A Poisson distributed random integer (e.g., the number of events) with the mean lambda.
    int
    randomWeighted(double[] weights)
    A random index chosen with the weights (e.g., a cell with more grass is chosen more often), -1 if all are 0.
    void
    record(String name, double value)
    Records a value of the current step for an Experiment (a column of its table, besides the values of the line charts).
    static double[]
    rk4(Simulation.Derivatives f, double t, double[] y, double dt)
    One step of the Runge-Kutta method (4th order) for dy/dt = f(t, y), e.g., a Lotka-Volterra model:
    void
    run()
    The main method which is called from the calculation thread!
    static double
    sd(double[] values)
    The standard deviation of the values.
    void
    seed(int seed)
    Sets the seed of the random numbers (e.g., in init()).
    void
    setStartSeed(int seed)
    Sets the seed of the next setup (the field Seed of the settings).
    org.eclipse.swt.widgets.Composite
    settings(org.eclipse.swt.widgets.Composite parent)
    An own panel for the settings in Bio7 (null: the settings of the Param fields and Action methods are created).
    void
    The setup method to initialize values etc.!
    void
    shuffle(List<?> list)
    Shuffles the list randomly (e.g., the agents for a random order of the updates).
    static double
    sinDeg(double deg)
    The sine of an angle in degrees (the same digits in Bio7 and in the browser).
    static double[]
    solve(double[][] a, double[] b)
    The solution x of A x = b (Gaussian elimination with partial pivoting; NaN if A is singular).
    static double
    sq(double value)
    The square of the value.
    void
    Starts the model after its creation by the compiler of Bio7: the setup in the thread of the user interface.
    abstract void
    One time step (called by the Play/Pause button).
    void
    Ends the simulation after this step, e.g., if (infected == 0) stop(); in step(): Bio7 pauses the simulation (Play continues it), the HTML page stops, an Experiment ends the run (its last step is recorded).
    static double
    sum(double[] values)
    The sum of the values.
    static double
    sum(int[] values)
    The sum of the values.
    static double[][]
    transpose(double[][] a)
    The transposed matrix.
    static double
    variance(double[] values)
    The variance of the values (n - 1, 0 for less than two values).
    static double
    wrapAround(double value, double size)
    The value on a torus of the size (e.g., wrapAround(-1, 100) = 99).

    Methods inherited from class Model

    close, draw, getGLProfile, run, setup, setup
    Modifier and Type
    Method
    Description
    void
    A method to allow closing operations with a compiled Model class called,e.g., from the CustomView implementation.
    void
    The draw method for the Points panel with the Graphics context to draw directly on the panel with available Java routines!
    The OpenGL profile of the 3D view for this model, e.g., GLProfile.GL4 or GLProfile.GL3 (the names of com.jogamp.opengl.GLProfile).
    void
    run(com.jogamp.opengl.GLAutoDrawable drawable)
    The main OpenGL method with the drawable of the 3D view (see getGLProfile).
    void
    setup(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.opengl.util.gl2.GLUT glut)
    The setup OpenGL method with the OpenGL context as parameters!
    void
    setup(com.jogamp.opengl.GLAutoDrawable drawable)
    The setup OpenGL method with the drawable of the 3D view (see getGLProfile), e.g., to create shaders and buffers.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • agents

      public ArrayList<A extends Agent> agents
      The agents.
    • boxWidth

      public double boxWidth
      The size of the box.
    • boxHeight

      public double boxHeight
      The size of the box.
    • boxDepth

      public double boxDepth
      The size of the box.
    • agentRadius

      public double agentRadius
      The radius of the spheres (in the units of the box, 0: 1 % of the box).
    • agentColor

      public String agentColor
      The color of the agents without an own color.
    • agentShape

      public String agentShape
      The shape of the agents without an image or a model: "sphere" (default) or "glider" (a glider of triangles which points in the direction of its movement, climbs, dives and banks into turns; its size: agentRadius).
    • floor

      public String floor
      The floor: "none" (the edges of the box, default), "grid" (lines) or "plane" (a dark floor with a grid).
    • shadows

      public boolean shadows
      Soft shadows of the agents on the floor.
    • followAgent

      public int followAgent
      The agent (its index) which the custom camera of the 3D view follows from behind (with the split view: the global view beside it); -1: none. Only in Bio7 (the HTML export shows the orbit camera).
    • linkColor

      public String linkColor
      The color of the links (drawn as lines between the agents; null or "": not drawn).
    • linkWidth

      public double linkWidth
      The width of the links in pixels.
  • Constructor Details

    • AgentModel

      public AgentModel()
  • Method Details

    • placeModel

      public int placeModel(String model, double x, double y, double z, double heading, double size)
      Places a 3D model (glTF, loaded with loadModel) in the environment, e.g., a house, a tree or a rock: it stays until it is removed (not drawn again in each step). Returns its index (removeModel).
    • placeModel

      public int placeModel(String model, double x, double y, double z, double heading, double size, String animation)
      Places a 3D model with an animation (its name or number, "none": still), see placeModel.
    • removeModel

      public void removeModel(int index)
      Removes the object of the environment with the index (placeModel); the later ones move up by one.
    • clearModels

      public void clearModels()
      Removes all objects of the environment.
    • getModels

      public List<AgentModel.Placed> getModels()
      The objects of the environment (a copy).
    • box

      public void box(double width, double height, double depth)
      Sets the size of the box.
    • distance

      public double distance(Agent a, Agent b)
      The distance of two agents (3D); the same as agentDistance(Agent, Agent).
    • agentDistance

      public double agentDistance(Agent a, Agent b)
      The distance of two agents (3D): the same name as for the agents of a grid (GridModel.agentDistance).
    • cameraFollow

      public void cameraFollow(int index)
      The camera of the 3D view follows the agent with this index (the split view shows the global view beside it); a negative index: no camera (the same as the field followAgent, camera_follow in Python and R).
    • neighborPairs

      public int[] neighborPairs(double distance)
      All pairs of agents closer than the distance (with a spatial index: fast for thousands of agents) as indices of the list: i0, j0, i1, j1, ... (i invalid input: '<' j, ordered by i and j; as neighbor_pairs in Python and R and as links()).
    • neighbors

      public ArrayList<A> neighbors(A agent, double radius)
      The other agents within the radius of the agent (in the order of the list).
    • index

      public SpatialIndex<A> index(double cellSize)
      A spatial index of the agents (their positions now; the size of the cells: e.g., the radius of the searches): fast searches of the neighbors of many agents (see SpatialIndex). Build it again after the agents moved (e.g., at the start of each step).
    • nearest

      public A nearest(A agent, double radius)
      The nearest other agent within the radius (null if none).
    • link

      public void link(A a, A b)
      Links two agents (undirected; no link of an agent with itself, a link once).
    • link

      public void link(A a, A b, String color)
      Links two agents with a color of the link (e.g., "#d62728" for a path of an infection).
    • unlink

      public void unlink(A a, A b)
      Removes the link of two agents.
    • removeLinks

      public void removeLinks(A a)
      Removes all links of the agent (e.g., before it is removed from the list).
    • clearLinks

      public void clearLinks()
      Removes all links.
    • linked

      public boolean linked(A a, A b)
      True if the agents are linked.
    • linkNeighbors

      public ArrayList<A> linkNeighbors(A a)
      The agents linked with the agent (in the order of the links). Remove the links of an agent (removeLinks) when it is removed from the list.
    • degree

      public int degree(A a)
      The number of links of the agent.
    • linkColorOf

      public String linkColorOf(A a, A b)
      The color of the link of two agents (null: linkColor or no link).
    • setLinkColor

      public void setLinkColor(A a, A b, String color)
      Sets the color of an existing link (null: linkColor).
    • links

      public int[] links()
      The links as pairs of the indices of the agents in the list: i0, j0, i1, j1, ... (i invalid input: '<' j; i ascending); the same as getLinks().
    • getLinks

      public int[] getLinks()
      The links as pairs of the indices of the agents in the list (i, j with i invalid input: '<' j; i ascending).
    • linkCount

      public int linkCount()
      The number of links (between agents of the list).
    • linkRandom

      public void linkRandom(double p)
      A random network: each pair of agents is linked with the probability p (Erdos-Renyi).
    • linkSmallWorld

      public void linkSmallWorld(int k, double p)
      A small-world network (Watts-Strogatz): a ring of the agents (in the order of the list), each linked with its k nearest (k / 2 on each side), then each link is moved to a random agent with the probability p.
    • linkScaleFree

      public void linkScaleFree(int m)
      A scale-free network (Barabasi-Albert): the first m + 1 agents are linked with each other, each further agent links with m agents before it, chosen with a probability proportional to their number of links.
    • linkNearby

      public void linkNearby(double radius)
      Links all agents within the distance (a network of the neighborhood, with a spatial index).
    • components

      public ArrayList<ArrayList<A>> components()
      The groups of the agents which are connected by links (each in the order of the list; isolated agents are a group).
    • shortestPath

      public int shortestPath(A a, A b)
      The number of links on the shortest path between two agents (-1: not connected).
    • clustering

      public double clustering(A a)
      The clustering coefficient of an agent: the share of the pairs of its linked agents which are linked too (0 with less than 2).
    • layoutCircle

      public void layoutCircle()
      Places the agents on a circle in the middle of the box (in the order of the list; z: the middle of the box).
    • layoutSpring

      public void layoutSpring(int iterations)
      Arranges the network in x and y (a spring layout of Fruchterman and Reingold: the links pull, all agents push each other away), in the box; z is kept. Call it once (e.g., 100 iterations in init()) or a few iterations in each step (a moving layout).
    • keepInBox

      public void keepInBox(Agent a)
      Keeps the agent in the box (the position is limited to the box).
    • wrapInBox

      public void wrapInBox(Agent a)
      Moves the agent to the other side of the box if it left it (x and y: a torus, z: limited).
    • prepareDisplay

      protected void prepareDisplay()
      Description copied from class: Simulation
      Prepares the display before init() (called in the thread of the user interface).
      Overrides:
      prepareDisplay in class Simulation
    • display

      protected void display()
      Description copied from class: Simulation
      Displays the model (ImageJ image or 3D view).
      Specified by:
      display in class Simulation
    • run

      public void run(com.jogamp.opengl.GL2 gl, com.jogamp.opengl.glu.GLU glu, com.jogamp.opengl.util.gl2.GLUT glut)
      Description copied from class: Model
      The main OpenGL method with the OpenGL context as parameters!
      Overrides:
      run in class Model
      Parameters:
      gl -
      glu -
      glut -