Package com.eco.bio7.simulation
A model extends one of the model classes and implements init() (the
start state) and step() (one time step):
GridModel: a grid of cells with integer states (ImageJ)ValueGridModel: a grid of double values with a color map (ImageJ)AgentModel: agents in a 3D box (the 3D view)GeoGridModel: a georeferenced grid with data read by GDAL (ImageJ, the WorldWind globe, a map in the HTML page)GeoAgentModel: agents on the Earth (the WorldWind globe, a map in the HTML page)
Param are
settings (sliders, number fields, checkboxes, choices, text fields), methods
with Action are buttons. The methods of all
models (random numbers, mathematics, statistics, differential equations,
charts, parallel random numbers) are inherited from
Simulation.
All models can show images (loadImage, drawImage, Agent.image), animated 3D
models of glTF (loadModel, Agent.model, Agent.animation; Gltf;
also OBJ with its materials and STL, converted to glTF), shapes drawn in
each step (Shape: drawLine, drawPath,
drawPolygon, drawCircle, drawRect, drawText; in agent models also at a
height z and the 3D shapes drawPoint3, drawPath3, drawBox, drawSphere,
drawPolygon3 and drawPillar) and several charts
(ChartData: chart, chartXY, chartBars; the
Charts view of Bio7). The mathematical functions (vectors, matrices,
regression, quantiles, the normal distribution, noise) give the same results
in Bio7 and in the HTML page. The first setup arranges the views in the
Custom perspective: the settings on the left, the editor above the display
of the model and the charts beside the display.
The 3D scene of an agent model: the shape of the agents (spheres or
gliders), a floor, shadows, a camera which follows an agent and objects of
the environment (placeModel). Agents can be linked to networks (link,
linkRandom, linkSmallWorld, linkScaleFree, linkNearby, components,
shortestPath, clustering, layoutSpring; drawn as lines), and a
SpatialIndex finds the neighbors of many
agents fast.
A model can react to the mouse and the keyboard of its view (the ImageJ
image of a grid, the 3D view of an agent model, the HTML export):
Simulation.click(double, double),
Simulation.drag(double, double) (in the 3D
view with Shift) and Simulation.key(String),
called between the steps.
Grid models can carry agents (GridAgent:
addAgent, forward, face, agentsAt, agentsNear), drawn on top of the grid.
A model ends a run with stop(); the field Seed of the settings (and of the
page) sets the seed of the setup.
An Experiment runs a model several times
without a display (a sweep of the parameters, repetitions with other seeds,
parallel threads) and returns a table (CSV, a data frame in R) of the
values of the line charts and of record(name, value); in Bio7 also the
button "Experiment..." of the settings (Java, Python and R models).
The wizard "Bio7 Simulation Project" creates a model (in Java, Python or R),
"Export Simulation as HTML..." (the menu of the Play/Pause button, the
Settings view or the context menu of the Java and R editors) exports it
(SimulationExport). The examples are in the
project Bio7_Java_Examples (packages simulation and simulation.api).
Python and R: the same models can be written as scripts with the
module bio7sim of the embedded Python (from bio7sim import *, numpy
arrays) or the functions of bio7sim of the embedded R (grid_model(),
matrices and data frames). simulation(model) at the end of the script
starts a Java model of the same kind
(ScriptSimulation): the same displays
(ImageJ, the 3D view, the WorldWind globe), the same settings, the same
geospatial data of GDAL. The HTML export
(ScriptExport) runs the script in the web
browser with Pyodide or webR (loaded from the internet) with the same
results. The examples are in the projects Bio7_Python_Examples and
Bio7_R_Examples (folder Simulation).
-
ClassDescriptionMarks a method of a simulation model (public, without parameters) as an action: a button in the settings of Bio7 and of the HTML export (e.g., "Add a glider").An agent of an
AgentModel: a position (x, y, z in the units of the box of the model, z is the height) and an optional color (e.g., "#d62728", null: the color of the model).AgentModel<A extends Agent>A simulation of agents in a box (e.g., a swarm): the agents (subclasses ofAgent) are displayed as spheres in the 3D view of Bio7 (and in the 3D view of the HTML export).An object of the environment: a 3D model (glTF, loaded with loadModel) at a place of the box.Runs a model several times without a display (batch runs): a sweep of the parameters (all combinations of the given values), repetitions with other seeds and a number of steps.The result of an experiment: a row for each recorded step of each run.An agent of aGeoAgentModel: a geographic position (longitude and latitude in degrees, WGS84), a color (e.g., "#d62728", null: the color of the model), a size (the radius of the point in pixels, 0: the size of the model), an optional label, an altitude and a heading (for the 3D shapes on the WorldWind globe).GeoAgentModel<A extends GeoAgent>A simulation of agents on the Earth (e.g., migrating animals, cities in an epidemic, ships): the agents (GeoAgent) have a longitude and a latitude and are displayed as points on the WorldWind globe of Bio7 (the WorldWind perspective is opened) and on a map in the HTML export (online base maps).A simulation on a georeferenced grid (a geospatial model, e.g., a wildfire on a terrain, a runoff or a species dispersal): the grid and its data layers are read with GDAL in Bio7 (rasters and vectors in any format of GDAL, e.g., GeoTIFF, GeoPackage, Shapefile, GeoJSON) and resampled or rasterized to the cells.An agent on the grid of aGridModel,ValueGridModelorGeoGridModel(a turtle on the patches): the position in cells (x to the right, y down; the centre of the cell (i, j) is i + 0.5, j + 0.5), the heading (degrees, 0 up, clockwise) and its look: a color with a shape ("circle", "arrow" in the heading or "square"), or an image (loadImage, turned to the heading).A simulation on a grid of cells (e.g., a cellular automaton like the Game of Life): the cells have integer states which are displayed with the colors of the palette in an ImageJ image (and in the 2D view of the HTML export).Marks a field of a simulation model as a setting: the HTML export shows it as a control (a slider with min and max, else a number field, a checkbox for a boolean, a choice with options, else a text field).The base class of the simulation models of the simulation API (seeGridModel,ValueGridModelandAgentModel).The derivatives of a system of differential equations: dy/dt = f(t, y).Exports a simulation model of the simulation API (a Java source file of a subclass ofGridModelorAgentModel) as an interactive HTML page: the model is translated to JavaScript (JavaToJs), runs with the JavaScript version of the API and is displayed with the page ofHtmlSimulation(a 2D grid or a 3D view, the settings of the Param fields, Play/Pause, Step, Reset, the speed and a chart).The options of the page.The result of a translation: the page or the errors.SpatialIndex<A extends Agent>A fast search of the agents near a position: the agents are sorted into the cells of a grid (the positions when the index is built).A simulation on a grid of values (e.g., a diffusion or a reaction-diffusion model): each cell has a double value which is displayed with a color map from min to max in an ImageJ image (and in the 2D view of the HTML export).