TrypColonies

Documentation for TrypColonies.

TrypColonies.agentType
agent

A struct representing an agent in a grid. It holds the agent's current position in the grid as well as its direction of movement.

Fields

  • x_pos::Int64: The x-coordinate of the agent's position in the grid.
  • y_pos::Int64: The y-coordinate of the agent's position in the grid.
  • dir_x::Float64: The x-component of the agent's direction vector.
  • dir_y::Float64: The y-component of the agent's direction vector.
source
TrypColonies.parametersType
parameters

Defines the parameters for the simulation with default values and possible options for certain fields.

Fields

  • size::Tuple{Int,Int}: The dimensions of the simulation grid (width, height). Default is (1000, 1000).
  • agent_number::Int64: The number of agents in the simulation. Default is 4000.
  • interaction_radius::Int64: The radius within which agents interact. Default is 7.
  • velocity::Float64: The initial velocity of agents. Default is 5.
  • noise_dis::Any: The distribution used for noise. Default is Normal.
  • noise_strength::Number: The strength of the noise. Default is 0.5.
  • timesteps::Int64: The number of timesteps the simulation runs. Default is 300.
  • boundary_conditions::String: The type of boundary conditions. Default is "periodic". Possible values are "reflective" and "periodic".
  • geometry::String: The geometry of the simulation area. Default is "nowalls". Possible values are "nowalls", "circle", "channel", "square", and "circle_small".
  • velocity_dis::Any: The distribution used for agent velocities. Default is Normal.
  • velocity_variance::Float64: The variance in agent velocities. Default is 2.
  • start_config::String: The initial configuration of agents. Default is "random". Possible values are "random" and "square".
  • radius_tanget::Int64: The tangential radius for interactions. Default is 6.
  • radius_collision::Int64: The collision radius for agents. Default is 5.
  • boundary_moveable::Bool: Whether the boundary is moveable. Default is false.
  • path_tracing::Bool: Whether to trace the path of agents. Default is true.
  • sliding_boundary::Bool: Whether the boundary allows sliding. Default is false.
  • grid_strength::Int64: The strength of the grid. Default is 10.
  • grid_recover_rate::Float64: The rate at which the grid recovers strength. Default is 0.1.

Usage Notes

  • Use reflective boundary conditions only when agents cannot leave the grid space; otherwise, the simulation may crash silently.
  • The geometry field allows for simulating different environmental layouts, which can significantly affect agent behavior and interactions.
  • The start_config field determines the initial placement of agents, which can influence the dynamics of the simulation from the outset.

This struct is used to configure and initialize the simulation environment, affecting how agents move, interact, and evolve over time.

source
TrypColonies.plot_parametersType
plot_parameters

A structure defining parameters for plotting with default values.

Fields

  • framerate: The number of frames per second in the animation. Default is 60.
  • theme: The plotting theme, using Attributes. Default is theme_ggplot2().
  • fontsize: The font size for text elements. Default is 22.
  • arrow_tip_size: The size of the arrow tips. Default is 12.
  • arrow_tail_length: The length of the arrow tails. Default is 5.
  • correlation_function: The function used to calculate correlation. Default is order_parameter.
  • refresh_delay: The delay between refreshes in seconds. Default is 0.05.
  • res: The resolution of the plot as a tuple (width, height). Default is (1400, 2000).
  • Color_arrows: The color scheme for arrows. Default is the full range of ColorSchemes.hsv.
  • Color_heatmap: The color scheme for heatmaps. Default is indices 50 to 100 of ColorSchemes.bone.
  • timesteps_corfunc: The number of timesteps for the correlation function. Default is 100.
  • cor_func: The correlation function for circles. Default is order_parameter_circle.

Usage

This struct is used to configure the visual aspects and functionalities of plots, including animations, color schemes, and correlation calculations.

source
TrypColonies.calc_pathFunction

Calculates reflection of agent on wall, calls itself up to 2 times recursivley if multiple reflections occur

#reflection_calculus

source
TrypColonies.create_circleMethod

create_circle

Creates a circular pattern within a given grid matrix, setting values within the circle to 0. The circle's size is determined by the relative_size parameter, which scales the circle's radius relative to the grid's smallest dimension.

Parameters:

  • grid::Matrix{Int64}: The grid within which the circle will be created. It is modified in place.
  • relative_size::Float64=0.7 (optional): A scaling factor for the circle's radius, relative to the grid's smallest dimension. Must be less than 1.0.

Behavior:

  • The function first validates that relative_size is less than 1.0. If not, it throws an error.
  • It calculates the circle's radius based on the grid's smallest dimension and the relative_size.
  • It then iterates over a square of side length 2*radius centered in the grid. For each point within this square,

it calculates the distance from the center. If this distance is less than or equal to the radius, the grid's corresponding value is set to 0.

Example Usage:

grid = zeros(Int64, 100, 100) # Create a 100x100 grid
create_circle(grid, relative_size=0.5) # Create a circle in the grid with a radius 50% of the grid's smallest dimension

This function is useful for creating circular obstacles or areas within a grid-based simulation or game environment.

source
TrypColonies.create_gridMethod
create_grid(Parameters::parameters) -> Matrix{Int64}

Create a grid based on the specified parameters. The function initializes a grid of zeros and modifies it according to the geometry specified in Parameters. The grid can be shaped into a square, channel, circle, or a smaller circle, with negative values (defined by Parameters.grid_strength) in the entire grid except for the specified geometry shape.

Arguments

- `Parameters::parameters`: A struct containing the grid parameters. It must have the following fields:
- `size::Tuple{Int64, Int64}`: The dimensions of the grid.
- `geometry::String`: The shape of the grid, which can be "square", "channel", "circle", or "circle_small".
- `grid_strength::Int64`: The negative value to be applied to the grid's border or outside the specified shape.

Returns

  • Matrix{Int64}: The generated grid with the specified geometry and dimensions.

Examples

params = parameters(size=(100, 100), geometry="square", grid_strength=5)
grid = create_grid(params)

This function supports creating grids with different geometries to simulate various environments or constraints.

source
TrypColonies.create_noise_disMethod
`create_noise_dis(parameters::parameters)`

Create a noise distribution object based on the simulation parameters.

Arguments

  • parameters::parameters: A struct containing the simulation parameters. This must include:
    • noise_dis: The type of distribution to use for noise. Expected to be either Uniform or Normal.
    • noise_strength: A parameter (η) that defines the strength of the noise. For a Uniform distribution, it defines the range [-η, η]. For a Normal distribution, it defines the standard deviation σ with a mean of 0.

Returns

  • A distribution object corresponding to the specified noise distribution and strength. If noise_strength is 0,

it returns a Normal distribution with mean 0 and standard deviation 0.

Example

parameters = parameters(noise_dis=Uniform, noise_strength=0.5)
noise_distribution = create_noise_dis(parameters)
This will create a Uniform(-0.5, 0.5) distribution for noise.

Notes

The function supports creating Uniform and Normal distributions based on the noise_dis parameter in parameters. If noise_strength (η) is set to 0, the function defaults to creating a Normal(0.0, 0.0) distribution, effectively adding no noise.

source
TrypColonies.create_para_structMethod
create_para_struct(settings::Dict) -> Any

Constructs a parameters struct from a dictionary of settings, dynamically generating the struct fields and their values based on the input dictionary. This function uses metaprogramming to parse and evaluate a string representation of the struct initialization.

Arguments

  • settings::Dict: A dictionary where keys are the names of the parameters (as symbols or strings) and values are the

corresponding values for these parameters. The values can be of any type, including String.

Returns

  • A new instance of the parameters struct with fields and values corresponding to the entries in the settings dictionary.

If some keys are missing in the dictionary, the default values from the parameters struct definiton will be used.

Examples

settings = Dict(:radius_collision => 2, :size => (10,))
para_struct = create_para_struct(settings)

This will create an instance of the parameters struct with radius_collision set to 2, size set to (10,10).

source
TrypColonies.create_veloctiy_disMethod
create_velocity_dis(parameters::parameters) -> Distribution

Creates a velocity distribution for agents based on the simulation parameters.

Arguments

  • parameters::parameters: A struct containing the simulation parameters, which must include:
    • velocity_dis: The type of distribution to use (Uniform or Normal).
    • velocity_variance: The variance of the velocity distribution.
    • velocity: The mean velocity of the agents.

Returns

  • Distribution: A truncated distribution object representing the velocity distribution of agents. The distribution is truncated at the lower bound of 0 to ensure that velocity values are non-negative.

Behavior

  • If both velocity and velocity_variance are 0, a Normal distribution with mean 0 and variance 0 is returned.
  • If velocity_dis is Uniform, a truncated Uniform distribution ranging from (velocity - variance) to (velocity + variance) is created.
  • If velocity_dis is Normal, a truncated Normal distribution with the specified mean (velocity) and variance (velocity_variance) is created.
  • The truncation ensures that the resulting velocity values are always non-negative, as negative velocities are not physically meaningful in this context.

Example

parameters = parameters(velocity_dis=Normal, velocity_variance=1.0, velocity=5.0)
velocity_distribution = create_velocity_dis(parameters)
source
TrypColonies.find_free_neighbour_pointsMethod
find_free_neighbour_points(grid::Matrix{Int64}, tryp::agent, Parameters::parameters) -> Tuple{Bool, Int64, Int64}

Finds a free neighboring point around a given agent's position in a grid, considering specified boundary conditions.

Arguments

  • grid::Matrix{Int64}: A 2D grid representing the environment, where 0 indicates a free space and other values indicate occupied spaces.
  • tryp::agent: An agent object with fields x_pos and y_pos indicating its current position in the grid.
  • Parameters::parameters: A parameters object containing simulation parameters, including boundary_conditions which can be "periodic" and size indicating the size of the grid.

Returns

  • sucess::Bool: A boolean indicating whether a free neighboring point was found.
  • X_pos_new::Int64: The x-coordinate of the found free neighboring point. Returns the agent's original x-coordinate if no free point is found.
  • Y_pos_new::Int64: The y-coordinate of the found free neighboring point. Returns the agent's original y-coordinate if no free point is found.

Description

This function attempts to find a free (unoccupied) neighboring point around the agent's current position. It randomly shuffles the directions to check for free spaces to ensure unbiased movement direction. If the boundary_conditions are set to "periodic", it will apply periodic boundary corrections to wrap around the grid edges. The function returns whether a free space was found and the coordinates of that space.

source
TrypColonies.find_right_tangent_pointsMethod

Finds and returns the two most distant tangent points from a given array of tangent points.

This function is designed to process an array of tangent points, each represented as a Vector{Int64} containing two elements (coordinates). It calculates the pairwise distances between all points in the array using a helper function length_vec to determine the length of the vector formed by two points. The function then identifies and returns the pair of points that are the most distant from each other, which are considered the "right" tangent points for further processing.

Arguments

  • tangent_points::Vector{Vector{Int64}}: An array of points, each point is a vector of two integers representing its coordinates.

Returns

  • Vector{Vector{Int64}}: An array containing the two most distant tangent points from the input array.

Example

tangent_points = [[1, 2], [3, 4], [5, 6]]
right_tangent_points = find_right_tangent_points(tangent_points)
# right_tangent_points will contain the two points that are furthest apart
source
TrypColonies.find_surounding_pointsMethod

Returns all grid points surrounding the collision point in a radius of r The discretization going from the continuous circle to the discrete points on the grid is done with the stepwidth: steps

source
TrypColonies.find_tangent_pointsMethod

Reurn the gridpoints from the list of gridpoints in circle, which are the first ones of the boundary by checking when there is a change in the value list of points from -1 to 0 or vice versa. The last gridpoint that has the value -1 will be used as the probable point on the boundary between occupied and free space.

source
TrypColonies.get_reflected_vecMethod

Return the normalized reflected vector from the tangent to the next boundary of a given grid point. Function includes a fallback option, if no unambiguous tangent is defined by two points, the original orientation is just reversed.

source
TrypColonies.initialize_system!Method
initialize_system!(grid::Matrix{Int64}, Parameters::parameters) -> Tuple{Matrix{Int64}, Vector{Vector{agent}}, Vector{SparseMatrixCSC{Int64, Int64}}}

Initialize the simulation system based on the provided parameters and grid. This function prepares the initial state of agents, their configurations across timesteps, and records the initial grid changes.

Arguments

  • grid: A matrix representing the initial state of the grid.
  • Parameters: A struct containing simulation parameters, including the starting configuration and the number of timesteps.

Returns

A tuple containing:

  • The updated grid matrix after applying the initial configuration.
  • A vector of vectors, where each inner vector represents the state of agents at a specific timestep.
  • A vector of sparse matrices, each representing the changes in the grid at each timestep.

Behavior

  • Depending on the start_config parameter, agents are placed in a square configuration or distributed randomly across the grid.
  • The initial state of agents is copied across all specified timesteps.
  • The initial changes to the grid are recorded in a sparse matrix format for efficient storage, especially useful in non-interactive simulations.

Examples

grid = zeros(Int64, 10, 10)
Parameters = parameters("square", 100) # Create parameters struct with square start configuration and 100 timesteps
grid, agent_list_full, grid_vec_sparse = initialize_system!(grid, Parameters)
source
TrypColonies.make_para_dict_listMethod
make_para_dict_list(sweep_dict_original::Dict)

Generate a list of parameter dictionaries for simulation runs based on the original sweep parameters dictionary.

Arguments

  • sweep_dict_original::Dict: A dictionary containing the original sweep parameters. It must include keys for sweep_parameter, parameter_steps,

iterations, and parameter_increment. The sweep_parameter key should match one of the keys in the dictionary that will be varied across simulations.

Returns

  • Array{Dict}: An array of dictionaries, each representing a set of parameters for a single simulation run.

The specified sweep parameter is incremented across these dictionaries according to the parameter_steps and parameter_increment specified in the original dictionary.

Throws

  • An error if the sweep_parameter specified in sweep_dict_original does not exist in the dictionary keys.

Example

sweep_dict_original = Dict(
    "sweep_parameter" => "agent_number",
    "parameter_steps" => 5,
    "iterations" => 10,
    "parameter_increment" => 2,
    "other_param" => 1
)
para_dict_list = make_para_dict_list(sweep_dict_original)

This function is useful for creating parameter sweeps for simulations, where one wants to vary a single parameter across a range of values while keeping other parameters constant.

source
TrypColonies.make_sys_interactive!Method

make_sys_interactive!

Transforms a grid system into an interactive one by initializing a circular buffer to store agent states, allowing for dynamic updates.

Parameters:

  • grid: The grid on which agents operate. This function does not modify the grid but returns it for consistency in the interface.
  • agent_list_full: A list (vector) of agents. These agents are the initial state of the system.
  • buffer_length::Int=5 (optional): The length of the circular buffer. This determines how many past states of the agent list can be stored. Default is 5.

Returns:

  • grid: The same grid passed as input, returned unchanged.
  • agent_list_cicular: A circular buffer filled with deep copies of the first agent in agent_list_full.

This buffer allows for storing and accessing past states of the system.

Example Usage:

grid = create_grid(Parameters))
agent_list_full = [Agent(1, 2, 0.5, 0.5), Agent(2, 3, -0.5, -0.5)] # List of agents
grid, agent_list_circular = make_sys_interactive!(grid, agent_list_full, buffer_length=10)
source
TrypColonies.path_tracingMethod
  • Function Name: path_tracing
  • Description: This function simulates the movement of an agent (tryp) through a grid, step by step, to determine the point at which it first encounters a wall. It returns the X and Y positions on the grid where the first wall is encountered, along with the distance already walked.
  • Parameters:
    • grid::Matrix{Int64}: The grid through which the agent moves, represented as a matrix of integers.
    • tryp::agent: The agent attempting to move through the grid. It contains properties like direction (dir_x, dir_y) and position (x_pos, y_pos).
    • velocity: The speed at which the agent attempts to move through the grid.
    • parameters::parameters: Additional parameters affecting the simulation, such as boundary conditions.
  • Returns: The function returns a tuple containing the X and Y indices of the first wall grid point encountered and the remaining distance the agent can walk.
  • Algorithm:
    1. Initialize the agent's direction and position.
    2. Iterate through the steps based on the agent's velocity.
    3. Update the agent's position at each step, rounding to the nearest grid point.
    4. If periodic boundary conditions are specified, adjust the position accordingly.
    5. Check if the current grid point is a wall (grid[Y_step_i, X_step_i] < 0). If so, move the agent back to the previous position and adjust for periodic boundary conditions if necessary.
    6. Return the final position and the distance walked before encountering the wall.
source
TrypColonies.periodic_boundary_correctionMethod
periodic_boundary_correction(x_pos::Int64, y_pos::Int64, size::Tuple{Int64,Int64}) -> Tuple{Int64, Int64}

Corrects the positions (x_pos, y_pos) of an object within a 2D grid to ensure they fall within the grid's boundaries, assuming periodic boundary conditions. This means that if an object moves beyond one edge of the grid, it re-enters the grid from the opposite edge, similar to a toroidal (doughnut-shaped) space.

Arguments

  • x_pos::Int64: The x-coordinate of the object's position.
  • y_pos::Int64: The y-coordinate of the object's position.
  • size::Tuple{Int64,Int64}: A tuple representing the size of the grid, where the first element is the width (x dimension) and the second element is the height (y dimension).

Returns

  • Tuple{Int64, Int64}: The corrected position of the object as a tuple of (x_pos, y_pos).

Examples

# Given a grid of size 10x10
grid_size = (10, 10)

# An object at position (11, 5) would wrap around to (1, 5)
periodic_boundary_correction(11, 5, grid_size) # returns (1, 5)

# An object at position (0, 10) would wrap around to (10, 10)
periodic_boundary_correction(0, 10, grid_size) # returns (10, 10)
source
TrypColonies.reconstruct_grid!Method
reconstruct_grid!(Grid_vec_sparse::Vector{SparseMatrixCSC{Int64, Int64}}, Timestep::Int, start_grid::AbstractArray{Int})

Update start_grid in-place by adding the non-zero values from a specific timestep's sparse matrix in Grid_vec_sparse.

Arguments

  • Grid_vec_sparse: A vector of sparse matrices (SparseMatrixCSC{Int64, Int64}), each representing the grid at a different timestep.
  • Timestep: The specific timestep (index into Grid_vec_sparse) from which to take the non-zero values.
  • start_grid: An array to be updated in-place. It represents the grid before updating, and it will be modified to include the non-zero values from the specified timestep's sparse matrix.

Description

This function iterates over all non-zero elements of the sparse matrix at the specified Timestep in Grid_vec_sparse. For each non-zero element, it increments the corresponding element in start_grid by the value of the non-zero element. This operation modifies start_grid in-place, effectively reconstructing or updating the grid state by applying the changes from the specified timestep.

Examples

# Example usage
Grid_vec_sparse = [sparse([1, 2], [1, 2], [1, 1]), sparse([1, 2], [1, 2], [2, 2])]
Timestep = 2
start_grid = zeros(Int, 2, 2)

reconstruct_grid!(Grid_vec_sparse, Timestep, start_grid)
# start_grid is now [0 2; 0 2] (2x2 matrix of integers
source
TrypColonies.reconstruct_grid_from_scratchFunction
reconstruct_grid_from_scratch(Grid_vec_sparse::Vector{SparseMatrixCSC{Int64, Int64}}, Timestep::Int = length(Grid_vec_sparse)) -> Matrix{Int64}

Reconstructs the grid state from scratch up to a specified timestep using a sequence of sparse matrices.

Arguments

  • Grid_vec_sparse: A vector of SparseMatrixCSC{Int64, Int64} objects, each representing the grid changes at a specific timestep.
  • Timestep: (Optional) The timestep up to which the grid should be reconstructed. Defaults to the last available timestep in Grid_vec_sparse.

Returns

A Matrix{Int64} representing the reconstructed grid state up to the specified timestep.

Description

This function reconstructs the grid state by starting with the grid state at the first timestep and then applying changes from each subsequent timestep up to the specified Timestep. It uses the reconstruct_grid! function to apply changes in-place to the grid state.

Examples

# Assuming [`Grid_vec_sparse`] is a vector of sparse matrices representing grid changes at each timestep
reconstructed_grid = reconstruct_grid_from_scratch(Grid_vec_sparse)
# `reconstructed_grid` now contains the grid state reconstructed up to the last timestep
source
TrypColonies.save_grid_changes!Method
save_grid_changes!(Grid_1::Union{Matrix{Int64}, Real}, Grid_2::Matrix{Int64}, Grid_vec::Vector{SparseMatrixCSC{Int64, Int64}})

Subtracts Grid_1 from Grid_2 and appends the result to Grid_vec.

Arguments

  • Grid_1: A matrix of integers or a real number. Represents the initial state of the grid.
  • Grid_2: A matrix of integers. Represents the updated state of the grid.
  • Grid_vec: A vector of sparse integer matrices. This vector is updated with the changes.

Notes

  • This function modifies Grid_vec in place by appending the difference between Grid_2 and Grid_1.
  • If Grid_1 is a real number, it is subtracted from each element of Grid_2 before the result is appended to Grid_vec.
source
TrypColonies.scale_color_mapMethod

This function counteracts the dynamic scaling of colormaps in Makie if min and max values change over the course of an animation. It is given a Max value (min value = 0) and shrinks the colormap dynamically if the data does not reach the max value.

source
TrypColonies.strenghten_boundary!Method
strengthen_boundary!(grid::Matrix{Int64}, Parameters::parameters)

Strengthens the boundaries of a grid based on the provided parameters.

Arguments

  • grid: A matrix representing the simulation grid, where negative values typically indicate boundary cells.
  • Parameters: An instance of the parameters struct containing simulation parameters.

Behavior

This function iterates over each cell in the grid. If a cell is part of the boundary (indicated by a negative value) and its strength is less than the absolute value of Parameters.grid_strength, the function attempts to strengthen the boundary by decreasing its value.

The amount by which the boundary is strengthened is determined by a random draw from a Poisson distribution with a mean of Parameters.grid_recover_rate. If this strengthening would result in a boundary strength exceeding the absolute value of Parameters.grid_strength, the boundary strength is set to -Parameters.grid_strength.

Requirements

  • Parameters.grid_recover_rate must be greater than 0.0 for the function to modify the grid.

If Parameters.grid_recover_rate is 0.0 or less, the function will not alter the grid.

  • The function modifies the grid in place, meaning the original grid will be changed after the function call.

Example

grid = Matrix{Int64}(undef, 100, 100) # Initialize a 100x100 grid
Parameters = parameters(...) # Initialize parameters with appropriate values
strengthen_boundary!(grid, Parameters) # Strengthen the grid boundaries based on the parameters
source
TrypColonies.sweep_and_save_parallel_tFunction
sweep_and_save_parallel_t(para_dict_list::Array{Dict}, full_data_path::String, offset::Int=100000)

Execute a parameter sweep in parallel, simulating each parameter set in para_dict_list, and save the simulation results to disk.

Arguments

  • para_dict_list::Array{Dict}: An array of dictionaries, each representing a set of parameters for a single simulation run.
  • full_data_path::String: The base path where simulation results will be saved. Each simulation's results are saved in a separate file within this directory.
  • offset::Int=100000 (optional): An offset added to the file names to avoid overwriting existing files and to ensure proper sorting.

The first file will be named offset + 1.jls, the second offset + 2.jls, and so on.

Behavior

For each set of parameters in para_dict_list, this function:

  1. Initializes the simulation environment and agents based on the parameters.
  2. Runs the simulation for the specified number of timesteps.
  3. Saves the final state of the agents and the environment to a Julia serialization file (*.jls) in the specified directory.

The file name includes an index offset to differentiate between simulation runs.

Notes

  • This function uses Julia's multithreading capabilities (Threads.@threads) to run multiple simulations in parallel.

The number of threads is determined by the Julia environment's thread count.

  • It is assumed that create_para_struct, create_grid, initialize_system!, update_directions!, update_position!, and save_grid_changes!

are defined elsewhere and are responsible for the simulation's initialization, updating agents' directions and positions, and saving changes to the grid, respectively.

  • The serialization function s.serialize is used to save the simulation results,

where s is assumed to be a module or object with a serialize method capable of writing Julia objects to disk.

Example

para_dict_list = [
    Dict("parameter1" => value1, "timesteps" => 100),
    Dict("parameter2" => value2, "timesteps" => 200)
]
full_data_path = "path/to/save/results"
sweep_and_save_parallel_t(para_dict_list, full_data_path)

This function is useful for running multiple simulations with different parameters in parallel and saving the results for later analysis.

source
TrypColonies.update_grid!Method
update_grid!(grid::Matrix{Int}, Parameters::parameters, grid_t::Matrix{Int}, grid_vec_sparse::Vector{SparseMatrixCSC{Int64, Int64}})

Updates the simulation grid by strengthening boundaries and saving grid changes.

Arguments

  • grid: The current state of the simulation grid as a matrix of integers.
  • Parameters: A struct containing simulation parameters, such as grid size and boundary strength.
  • grid_t: A reference grid state used for comparison when saving changes.
  • grid_vec_sparse: A vector of sparse matrices where changes to the grid are stored.

Description

This function performs two main operations on the simulation grid:

  1. It calls strengthen_boundary! to modify the grid's boundaries based on the Parameters. This typically involves making the boundaries more negative (stronger) according to a predefined strength parameter.
  2. It calls save_grid_changes! to compare the current grid state (grid) with a reference state (grid_t) and records the differences in grid_vec_sparse. This step is crucial for tracking the evolution of the grid over time in an efficient manner.
source
TrypColonies.update_position!Function
update_position!(grid::Matrix{Int64}, full_agent_list, Parameters::parameters, timestep=1)

Updates the positions of agents on a grid based on their velocities and directions.

Arguments

  • grid::Matrix{Int64}: A 2D grid representing the environment where each cell can be empty (0), occupied by an agent (positive non-zero) or part of unmoveable space (negative non-zero).
  • full_agent_list: A collection of agents. Can be a CircularBuffer{Vector{agent}} for interactive/infinite simulations or a simple Vector{agent} for static/finite simulations.
  • Parameters::parameters: A struct containing simulation parameters, including velocity distribution, boundary conditions, and whether path tracing is enabled.
  • timestep=1: The current timestep of the simulation. Defaults to 1.

Behavior

  • Determines the velocity distribution for agents based on the provided parameters.
  • Draws a random velocity for each agent from the distribution.
  • Decides on the agent list to use based on the type of simulation (interactive/infinite vs. static/finite).
  • Iterates through each agent, calculating their new position based on their velocity and direction.
  • If path_tracing is disabled, agents move directly to their new position if it's empty, respecting boundary conditions.
  • If path_tracing is enabled, calculates a path for the agent and moves them along this path and interacts with the non movable space, also respecting boundary conditions and handling sliding boundary conditions if enabled.
  • Updates the grid to reflect the new positions of the agents.
  • Updates the non movable space if the boundary is moveable.

Note

  • This function modifies the grid and full_agent_list in place.
  • Agents are assumed to be immutable; thus, to update an agent's position, a new agent with the updated position is created and replaced in the list.
source
TrypColonies.@hMacro

@h methodname

Outputs documentations in jupyternotenbooks in VScode as markdown without bugs.

Example of how to use the @h macro:

@h res_scaling(img_int_vec; factor = 3, plots = 1)

Outputs documentations in jupyternotenbooks in VScode as markdown without bugs.

source