### Dynamic Iteration Example Setup Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Demonstrates the setup for dynamic and lazy iteration in Agents.jl, highlighting how iterators can be affected by model changes. ```julia using Agents # We don't need to make a new agent type here, ``` -------------------------------- ### Core Simulation Loop for Manual Data Collection Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Provides an example of the core loop used in `run!`. It shows how to manually initialize dataframes for agent and model data, collect data at specified intervals, and advance the simulation step by step. ```julia df_agent = init_agent_dataframe(model, adata) df_model = init_model_dataframe(model, mdata) t0 = abmtime(model) t = t0 while until(t, t0, n, model) if should_we_collect(t, model, when) collect_agent_data!(df_agent, model, adata) end if should_we_collect(t, model, when_model) collect_model_data!(df_model, model, mdata) end step!(model, 1) t = abmtime(model) end return df_agent, df_model ``` -------------------------------- ### Install and Apply Runic.jl Formatter Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md Install the Runic.jl package and apply the formatter to your developed code in the Agents.jl repository. ```bash julia --project=@runic --startup-file=no -e 'using Pkg; Pkg.add("Runic")' julia --project=@runic --startup-file=no -e 'using Runic; exit(Runic.main(ARGS))' -- --inplace path/to/developed/Agents ``` -------------------------------- ### Add Documenter Package Source: https://github.com/juliadynamics/agents.jl/blob/main/CONTRIBUTING.md Install the Documenter package by running this command in a Julia REPL session. This package is required for building the documentation. ```julia import Pkg; Pkg.add("Documenter") ``` -------------------------------- ### Plotting Distances Example Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Includes a Julia file for plotting distances, likely used in conjunction with space-related examples. ```julia include("distances_example_plot.jl") # hide ``` -------------------------------- ### Install Agents.jl Package Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/index.md Use this command in the Julia REPL to add the Agents.jl package to your project. Ensure you are using the latest stable version for all features. ```julia using Pkg; Pkg.add("Agents") ``` -------------------------------- ### Include Performance Test Script Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md Includes a performance test script for variable agent types. Ensure the Agents.jl package is installed and accessible. ```julia using Agents x = pathof(Agents) t = joinpath(dirname(dirname(x)), "test", "performance", "variable_agent_types_simple_dynamics.jl") include(t) ``` -------------------------------- ### Space Utility Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Utility functions for interacting with the model's space, such as normalizing positions and getting space size. ```julia normalize_position spacesize ``` -------------------------------- ### Include Multi-Agent vs Union Performance Test Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md Includes a performance test script comparing multi-agent and Union type approaches. Ensure the Agents.jl package is installed and accessible. ```julia using Agents x = pathof(Agents) t = joinpath(dirname(dirname(x)), "test", "performance", "multiagent_vs_union.jl") include(t) ``` -------------------------------- ### Build and Preview Documentation Source: https://github.com/juliadynamics/agents.jl/blob/main/CONTRIBUTING.md Build and preview the documentation locally by running this command from the terminal. Ensure you have already added the Documenter package. ```shell julia docs/make.jl ``` -------------------------------- ### Display Complete Dependency Overview Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/index.md Provides a complete overview of all dependencies and their versions, including those in the manifest. Requires the Pkg module. ```julia using Pkg # hide Pkg.status(; mode = PKGMODE_MANIFEST) # hide ``` -------------------------------- ### Initialize and Manipulate Agents in a Grid Space Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Demonstrates initializing a 4-dimensional grid space model, adding agents to specific positions, and removing agents. It highlights the importance of collecting iterators before modification during iteration to avoid unexpected behavior. ```julia model = StandardABM(GridAgent{4}, GridSpace((5, 5, 5, 5))) add_agent!((1, 1, 1, 1), model) add_agent!((1, 1, 1, 1), model) add_agent!((2, 1, 1, 1), model) for id in ids_in_position((1, 1, 1, 1), model) remove_agent!(id, model) end collect(allids(model)) ``` -------------------------------- ### Display Direct Dependencies Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/index.md Shows the direct dependencies used to build the documentation. Requires the Pkg module. ```julia using Pkg # hide Pkg.status() # hide ``` -------------------------------- ### EventQueueABM and AgentEvent Documentation Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Documentation for EventQueueABM and AgentEvent, used for continuous-time agent-based models with event scheduling. ```julia EventQueueABM AgentEvent add_event! ``` -------------------------------- ### Create Agent-Based Model Video Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `abmvideo` to generate a video recording of your agent-based model simulation. This is helpful for presentations and sharing results. ```julia abmvideo ``` -------------------------------- ### Display Machine and Julia Version Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/index.md Displays the machine and Julia version information used for building the documentation. Requires the InteractiveUtils module. ```julia using InteractiveUtils # hide versioninfo() # hide ``` -------------------------------- ### Discrete Space Types Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Documentation for discrete space implementations: GraphSpace, GridSpace, and GridSpaceSingle. ```julia GraphSpace GridSpace GridSpaceSingle ``` -------------------------------- ### Explore Agent-Based Model Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `abmexploration` to launch an interactive exploration interface for your agent-based model. This allows for parameter sweeping and visualization. ```julia abmexploration ``` -------------------------------- ### Agent Iteration and Data Collection Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Demonstrates agent iteration, handling dynamic collections, and manual data collection using Agents.jl functions. ```APIDOC ## Agent Iteration and Data Collection This section covers how to iterate over agents, manage dynamic collections to avoid iteration issues, and perform manual data collection. ### Iteration with Dynamic Collections When iterating over collections that can change during iteration (like agent IDs in a position), it's crucial to `collect` the iterator first to ensure a stable, non-dynamic version. ```julia # Example of removing agents during iteration model = StandardABM(GridAgent{4}, GridSpace((5, 5, 5, 5))) add_agent!((1, 1, 1, 1), model) add_agent!((1, 1, 1, 1), model) add_agent!((2, 1, 1, 1), model) # Incorrect iteration leading to partial removal for id in ids_in_position((1, 1, 1, 1), model) remove_agent!(id, model) end # Correct approach: collect the iterator first ids_to_remove = collect(ids_in_position((1, 1, 1, 1), model)) for id in ids_to_remove remove_agent!(id, model) end ``` ### Lazy Iteration Example (`nearby_ids`) Functions like `nearby_ids` can return iterators. Operations like `sort!` require a concrete collection, so `collect` should be used. ```julia a = random_agent(model) # This will error because sort! cannot operate on an iterator # sort!(nearby_ids(random_agent(model), model)) # Correct approach: collect the iterator before sorting sorted_nearby_agents = sort!(collect(nearby_agents(a, model))) ``` ### Manual Data Collection Provides functions for custom data collection loops, offering an alternative to the `run!` function. ```julia # Functions for manual data collection init_agent_dataframe collect_agent_data! init_model_dataframe collect_model_data! dataname # Example core loop of run! model = StandardABM(GridAgent{4}, GridSpace((5, 5, 5, 5))) adata = [] # agent data collection list mdata = [] # model data collection list df_agent = init_agent_dataframe(model, adata) df_model = init_model_dataframe(model, mdata) t0 = abmtime(model) t = t0 while until(t, t0, n, model) # assuming until, n, when, when_model are defined if should_we_collect(t, model, when) collect_agent_data!(df_agent, model, adata) end if should_we_collect(t, model, when_model) collect_model_data!(df_model, model, mdata) end step!(model, 1) t = abmtime(model) end return df_agent, df_model ``` ``` -------------------------------- ### Distributed Computing Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Instructions on how to use the `Distributed` module for parallel simulations with `ensemblerun!`. ```APIDOC ## How to use `Distributed` To leverage the `parallel=true` option of [`ensemblerun!`](@ref), you need to ensure that the `Agents` package is loaded and your fundamental types are defined on all processors. Refer to the [Performance Tips](@ref) page for more details on parallelization. ```julia # Ensure Agents is loaded on all processors # Define your agent and model types before calling ensemblerun!(..., parallel=true) ``` ``` -------------------------------- ### StandardABM Documentation Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Documentation for the StandardABM type, used for discrete-time agent-based models. ```julia StandardABM ``` -------------------------------- ### Populate Model from CSV Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `populate_from_csv!` to initialize or update agent properties by reading data from a CSV file. Ensure the CSV columns match agent properties. ```julia AgentsIO.populate_from_csv! ``` -------------------------------- ### Schedulers Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Documentation on using schedulers to control agent scheduling and execution order within simulations. ```APIDOC ## Schedulers Schedulers define the order in which agents are processed during a simulation step. Agents.jl provides predefined schedulers and allows for custom scheduler implementations. ### Predefined Schedulers Some useful schedulers are available as part of the Agents.jl API: ```@docs Schedulers Agents.schedule Schedulers.fastest Schedulers.ByID Schedulers.Randomly Schedulers.Partially Schedulers.ByProperty Schedulers.ByType ``` ### Advanced Scheduling with Custom Schedulers Custom scheduling logic can be implemented using function-like objects. This allows for dynamic or condition-based agent ordering. **Example Custom Scheduler:** ```julia mutable struct MyScheduler n::Int # step number w::Float64 end function (ms::MyScheduler)(model::ABM) ms.n += 1 # increment internal counter by 1 each time its called # be careful to use a *new* instance of this scheduler when plotting! if ms.n < 10 return allids(model) # order doesn't matter in this case else ids = collect(allids(model)) # filter all ids whose agents have `w` less than some amount filter!(id -> model[id].w < ms.w, ids) return ids end end # Usage example: # ms = MyScheduler(100, 0.5) # step!(model, agentstep, modelstep, 100; scheduler = ms) ``` ``` -------------------------------- ### Continuous Space Types Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Documentation for continuous space implementations: ContinuousSpace and OpenStreetMapSpace. ```julia ContinuousSpace OpenStreetMapSpace ``` -------------------------------- ### Implement Custom Serialization for Model Properties Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md Implement custom serialization for model properties by defining methods for `AgentsIO.to_serializable` and `AgentsIO.from_serializable`. This is useful for non-serializable data like functions or for space-efficient serialization. ```julia AgentsIO.to_serializable ``` ```julia AgentsIO.from_serializable ``` -------------------------------- ### Reinforcement Learning ABM Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for setting up and training reinforcement learning agents within an ABM. ```julia ReinforcementLearningABM set_rl_config! create_policy_network create_value_network train_model! get_trained_policies copy_trained_policies! ``` -------------------------------- ### AgentBasedModel Core API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Core structures and functions for creating and managing AgentBasedModel instances. ```APIDOC ## AgentBasedModel Core API ### Description Core structures and functions for creating and managing AgentBasedModel instances. ### Methods - `AgentBasedModel` - `StandardABM` - `EventQueueABM` - `ReinforcementLearningABM` - `Agents.step!(::AgentBasedModel, args...) ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Include Model Definitions with @everywhere include Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md For larger models, define the core components in a separate file and then include it using `@everywhere include("filename.jl")`. This helps in organizing code and reducing the repeated use of `@everywhere`. ```julia @everywhere include("schelling.jl") ``` -------------------------------- ### AgentBasedModel Step Function Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md This function advances the AgentBasedModel by one step. It is a core function for running simulations. ```julia AgentBasedModel Agents.step!(::AgentBasedModel, args...) ``` -------------------------------- ### Agent Type Macros Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Macros for defining different types of agents, including minimal agent types. ```julia @agent @multiagent AbstractAgent SoAType ``` ```julia NoSpaceAgent GraphAgent GridAgent ContinuousAgent OSMAgent ``` -------------------------------- ### Plot Agent-Based Model Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `abmplot` to create static visualizations of your agent-based model. It requires specifying the model and how to represent agents and spaces. ```julia abmplot ``` -------------------------------- ### Path-finding Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md APIs and functionalities for path-finding algorithms within agent-based models. ```APIDOC ## Path-finding Agents.jl includes a pathfinding module for calculating routes and movement within the simulation space. ### Path-finding Algorithms and Metrics ```@docs Pathfinding Pathfinding.AStar Pathfinding.penaltymap ``` ### Path-finding Planning and Moving Functions to plan and execute movement along calculated routes: ```@docs Pathfinding.plan_route! Pathfinding.plan_best_route! Pathfinding.move_along_route! Pathfinding.is_stationary Pathfinding.nearby_walkable Pathfinding.random_walkable ``` ### Pathfinding Metrics Provides various metrics for pathfinding calculations: ```@docs Pathfinding.DirectDistance Pathfinding.MaxDistance Pathfinding.PenaltyMap ``` **Custom Metrics:** Building a custom metric is straightforward if the provided ones do not meet your needs. Consult the [Developer Docs](@ref) for detailed instructions. ``` -------------------------------- ### Data Collection and Analysis Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Core functions for running simulations and collecting data, including `run!`, `ensemblerun!`, and `paramscan`. ```APIDOC ## Data collection and analysis The central simulation function is [`run!`](@ref). This section also covers functions that aid in making custom data collection loops. ### Core Simulation Functions ```@docs run! ensemblerun! paramscan ``` ### Manual Data Collection Helpers These functions assist in creating custom data collection loops when not using the `run!` function. ```@docs init_agent_dataframe collect_agent_data! init_model_dataframe collect_model_data! dataname ``` ``` -------------------------------- ### Load Checkpoint Function Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `load_checkpoint` to restore a previously saved agent-based model state from a file. This allows for resuming simulations. ```julia AgentsIO.load_checkpoint ``` -------------------------------- ### Agent and Model Access Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for retrieving and accessing agents and model properties. ```julia getindex(::ABM, ::Integer) getproperty(::ABM, ::Symbol) random_id random_agent nagents allagents allids hasid abmproperties abmrng abmscheduler abmspace abmtime abmevents ``` -------------------------------- ### Sort Nearby Agents by Collecting Iterator Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Illustrates how to sort agents nearby a given agent. It shows the correct way to use `collect` to convert the iterator returned by `nearby_agents` into a sortable list, preventing errors. ```julia a = random_agent(model) sort!(collect(nearby_agents(a, model))) ``` -------------------------------- ### Extend Agents.abmheatmap! for Custom Heatmap Extraction Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md Extend `Agents.abmheatmap!` to extract a finite heatmap matrix from a continuous space. This is particularly useful for `ContinuousSpace`. ```julia Agents.abmheatmap! ``` ```julia Agents.abmplot_heatarray ``` -------------------------------- ### Moving Agents Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for moving agents within the model space, including random walks and path-based movement. ```julia move_agent! walk! randomwalk! get_direction ``` -------------------------------- ### Adding Agents Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for adding agents to the model, including adding agents at specific positions or replicating them. ```julia add_agent! add_agent_own_pos! replicate! random_position ``` -------------------------------- ### Extend agentsplot! for Custom Agent Visualization Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md If your space type does not visualize agents using the default scattered marker approach, extend the `agentsplot!` function for custom agent rendering. ```julia Agents.agentsplot! ``` -------------------------------- ### Define a New Pathfinder Cost Metric Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md To define a new cost metric for A* pathfinding, create a struct that subtypes `Pathfinding.CostMetric` and provide a `delta_cost` function for it. ```julia Pathfinding.CostMetric ``` ```julia Pathfinding.delta_cost ``` -------------------------------- ### Custom Scheduler Logic Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Defines a custom scheduler `MyScheduler` that changes its behavior based on the simulation step. It demonstrates how to implement a mutable struct with a callable method to control agent scheduling, including conditional logic. ```julia mutable struct MyScheduler n::Int # step number w::Float64 end function (ms::MyScheduler)(model::ABM) ms.n += 1 # increment internal counter by 1 each time its called # be careful to use a *new* instance of this scheduler when plotting! if ms.n < 10 return allids(model) # order doesn't matter in this case else ids = collect(allids(model)) # filter all ids whose agents have `w` less than some amount filter!(id -> model[id].w < ms.w, ids) return ids end end ``` ```julia ms = MyScheduler(100, 0.5) step!(model, agentstep, modelstep, 100; scheduler = ms) ``` -------------------------------- ### Use @everywhere for Distributed Definitions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md When using distributed computing, ensure that all necessary definitions and package usages are available on all worker processes by prefixing them with `@everywhere`. This includes package imports and function/struct definitions. ```julia using Distributed @everywhere using Agents @everywhere function initialized @everywhere @agent struct SchellingAgent(...) ... @everywhere function agent_step!(...) = ... @everywhere adata = ... ``` -------------------------------- ### Group Definitions with @everywhere begin...end Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md To reduce the verbosity of using `@everywhere` for multiple lines, group them within an `@everywhere begin...end` block. This is useful for importing multiple packages or defining several related functions. ```julia @everywhere begin using Agents using Random using Statistics: mean using DataFrames end ``` -------------------------------- ### Available Spaces API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md API for various space types available in Agents.jl, including discrete and continuous spaces. ```APIDOC ## Available Spaces API ### Description API for various space types available in Agents.jl, including discrete and continuous spaces. ### Methods #### Discrete Spaces - `GraphSpace` - `GridSpace` - `GridSpaceSingle` #### Continuous Spaces - `ContinuousSpace` - `OpenStreetMapSpace` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Clone Agents.jl Repository Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md Clone the Agents.jl repository using a single branch to save space, especially if documentation with media is included. ```bash git clone https://github.com/JuliaDynamics/Agents.jl.git --single-branch ``` -------------------------------- ### Run Model with Offline Logging Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `offline_run!` to execute a model simulation while periodically saving data to disk instead of keeping it in memory. This is suitable for long-running simulations or when memory is limited. ```julia offline_run! ``` -------------------------------- ### Extend spaceplot! for Pre-plotting Elements Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md For spaces that require plotting specific elements before agents (e.g., OSMSpace), extend the `spaceplot!` function. ```julia Agents.spaceplot! ``` -------------------------------- ### Space Utility Functions API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Utility functions for interacting with and querying the model's space. ```APIDOC ## Space Utility Functions API ### Description Utility functions for interacting with and querying the model's space. ### Methods - `normalize_position` - `spacesize` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Agent/Model Retrieval and Access API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for retrieving and accessing agents and model properties. ```APIDOC ## Agent/Model Retrieval and Access API ### Description Functions for retrieving and accessing agents and model properties. ### Methods - `getindex(::ABM, ::Integer)` - `getproperty(::ABM, ::Symbol)` - `random_id` - `random_agent` - `nagents` - `allagents` - `allids` - `hasid` - `abmproperties` - `abmrng` - `abmscheduler` - `abmspace` - `abmtime` - `abmevents` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Agent-Based Model Observable Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `ABMObservable` to create observable objects for agent-based model properties, enabling reactive updates in visualizations or other parts of your application. ```julia ABMObservable ``` -------------------------------- ### Iteration Note Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Information regarding the dynamic and lazy nature of iteration in Agents.jl. ```APIDOC ## Iteration Note ### Description Information regarding the dynamic and lazy nature of iteration in Agents.jl. Most iteration in Agents.jl is **dynamic** and **lazy**, when possible, for performance reasons. **Dynamic** means that when iterating over the result of e.g. the [`ids_in_position`](@ref) function, the iterator will be affected by actions that would alter its contents. Specifically, imagine the scenario ```@example docs using Agents # We don't need to make a new agent type here, ``` ``` -------------------------------- ### Agent Movement API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for moving agents within the model's space, including movement along paths. ```APIDOC ## Agent Movement API ### Description Functions for moving agents within the model's space, including movement along paths. ### Methods - `move_agent!` - `walk!` - `randomwalk!` - `get_direction` ### Movement with Paths For `OpenStreetMapSpace`, and `GridSpace`/`ContinuousSpace` using `Pathfinding`, it is possible to move along planned routes. See the functions `plan_route!`, `plan_best_route!`, `move_along_route!` of the respective submodules. ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Extend Space Methods for New Space Types Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md To create a new space type, you must extend specific methods like `random_position`, `add_agent_to_space!`, `remove_agent_from_space!`, and `nearby_ids` to integrate with the Agents.jl API. ```julia random_position(model::ABMS) add_agent_to_space!(agent, model::ABMS), remove_agent_from_space!(agent, model::ABMS) nearby_ids(pos, model::ABMS, r; kw...) ``` -------------------------------- ### Nearby Agents Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for finding agents in proximity to a given agent or position. ```julia nearby_ids nearby_agents nearby_positions random_nearby_id random_nearby_agent random_nearby_position ``` -------------------------------- ### Save Checkpoint Function Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `save_checkpoint` to save the current state of an agent-based model to a file. This is useful for resuming simulations later. ```julia AgentsIO.save_checkpoint ``` -------------------------------- ### Higher-Order Interactions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md APIs for calculating higher-order interactions (pair-wise, triplet-wise, etc.) across the agent population. ```APIDOC ## Higher-order interactions These methods provide an interface for calculating pair-wise, triplet-wise, or higher interactions across the agent population. ### Available Functions ```@docs iter_agent_groups map_agent_groups index_mapped_groups ``` ``` -------------------------------- ### Dump Model Data to CSV Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `dump_to_csv` to export agent data to a CSV file. This function is helpful for analyzing model states or for external processing. ```julia AgentsIO.dump_to_csv ``` -------------------------------- ### Add Parallel Processes in Julia Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md Use `addprocs` to increase the number of available processing cores for distributed computing. This is a prerequisite for parallelizing model evolution with Agents.jl. ```julia using Distributed addprocs(4) ``` -------------------------------- ### Extend step! for New Model Types Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md When creating a new model type, extending the `step!` function is a mandatory requirement to define the time evolution or dynamic rule. ```julia src/core/model_abstract.jl ``` -------------------------------- ### Extend space_axis_limits for Custom Space Visualization Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/devdocs.md Extend the `space_axis_limits` function to enable visualization of custom space types within the Agents.jl plotting infrastructure. ```julia Agents.space_axis_limits ``` -------------------------------- ### Discrete Space Exclusives API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to discrete space implementations. ```APIDOC ## Discrete Space Exclusives API ### Description Functions specific to discrete space implementations. ### Methods - `positions` - `npositions` - `ids_in_position` - `id_in_position` - `agents_in_position` - `random_id_in_position` - `random_agent_in_position` - `fill_space!` - `has_empty_positions` - `empty_positions` - `empty_nearby_positions` - `random_empty` - `add_agent_single!` - `move_agent_single!` - `swap_agents!` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Agent Types API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md API for defining and working with different types of agents, including minimal agent types. ```APIDOC ## Agent Types API ### Description API for defining and working with different types of agents, including minimal agent types. ### Methods - `@agent` - `@multiagent` - `AbstractAgent` - `SoAType` - `NoSpaceAgent` - `GraphAgent` - `GridAgent` - `ContinuousAgent` - `OSMAgent` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Agent Manipulation API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for adding, removing, and replicating agents within the model. ```APIDOC ## Agent Manipulation API ### Description Functions for adding, removing, and replicating agents within the model. ### Methods - `add_agent!` - `add_agent_own_pos!` - `replicate!` - `random_position` - `remove_agent!` - `remove_all!` - `Agents.sample!` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Scale Polygon Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `scale_polygon` to resize a polygon by a given scaling factor. This function applies a uniform or non-uniform scaling transformation. ```julia scale_polygon ``` -------------------------------- ### Continuous Space Exclusives API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to the ContinuousSpace implementation. ```APIDOC ## Continuous Space Exclusives API ### Description Functions specific to the ContinuousSpace implementation. ### Methods - `nearest_neighbor` - `get_spatial_property` - `get_spatial_index` - `interacting_pairs` - `elastic_collision!` - `chebyshev_distance` - `euclidean_distance` - `manhattan_distance` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Translate Polygon Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `translate_polygon` to shift the position of a polygon by a specified vector. This is a geometric transformation utility. ```julia translate_polygon ``` -------------------------------- ### Nearby Agents API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for finding agents in proximity to a given agent or position. ```APIDOC ## Nearby Agents API ### Description Functions for finding agents in proximity to a given agent or position. ### Methods - `nearby_ids` - `nearby_agents` - `nearby_positions` - `random_nearby_id` - `random_nearby_agent` - `random_nearby_position` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Removing Agents Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions for removing agents from the model, including removing all agents or a sample. ```julia remove_agent! remove_all! Agents.sample! ``` -------------------------------- ### OpenStreetMapSpace Exclusives API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to the OpenStreetMapSpace implementation. ```APIDOC ## OpenStreetMapSpace Exclusives API ### Description Functions specific to the OpenStreetMapSpace implementation. ### Methods - `OSM` - `OSM.test_map` - `OSM.random_road_position` - `OSM.plan_route!` - `OSM.plan_random_route!` - `OSM.move_along_route!` - `OSM.distance` - `OSM.lonlat` - `OSM.nearest_node` - `OSM.road_length` - `OSM.route_length` - `OSM.get_geoloc` - `OSM.same_position` - `OSM.same_road` - `OSM.closest_node_on_edge` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Rotate Polygon Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `rotate_polygon` to rotate a polygon around a specified center point by a given angle. This is a common geometric transformation. ```julia rotate_polygon ``` -------------------------------- ### ContinuousSpace Exclusive Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to ContinuousSpace, including nearest neighbor search and distance calculations. ```julia nearest_neighbor get_spatial_property get_spatial_index interacting_pairs elastic_collision! chebyshev_distance euclidean_distance manhattan_distance ``` -------------------------------- ### DiscreteSpace Exclusive Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to DiscreteSpace, including position queries, agent retrieval, and space manipulation. ```julia positions npositions ids_in_position id_in_position agents_in_position random_id_in_position random_agent_in_position fill_space! has_empty_positions empty_positions empty_nearby_positions random_empty add_agent_single! move_agent_single! swap_agents! ``` -------------------------------- ### GraphSpace Exclusives API Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to the GraphSpace implementation. ```APIDOC ## GraphSpace Exclusives API ### Description Functions specific to the GraphSpace implementation. ### Methods - `add_edge!` - `rem_edge!` - `add_vertex!` - `rem_vertex!` ### Endpoint N/A (Core Julia functions) ### Parameters N/A ### Request Body N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Type-Stable Model Properties with Mutable Struct Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md Define model properties using a mutable struct with type annotations for each field. This ensures type stability and improves performance compared to using a generic `Dict` with mixed types. ```julia @kwdef mutable struct Parameters par1::Int = 1 par2::Float64 = 1.0 par3::String = "Test" end properties = Parameters() model = StandardABM(MyAgent; properties = properties) ``` -------------------------------- ### Update Agent-Based Model Plot Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Use `abmplot!` to update an existing agent-based model plot. This is useful for creating animations or interactive visualizations. ```julia abmplot! ``` -------------------------------- ### Detect Type Instability with @code_warntype Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/performance_tips.md Use the `@code_warntype` macro to identify type instabilities in your Julia code. Type instability can significantly impact performance, especially within model stepping functions. ```julia @code_warntype model_step!(model) ``` -------------------------------- ### OpenStreetMapSpace Exclusive Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to OpenStreetMapSpace for interacting with map data, routing, and geolocations. ```julia OSM OSM.test_map OSM.random_road_position OSM.plan_route! OSM.plan_random_route! OSM.move_along_route! OSM.distance OSM.lonlat OSM.nearest_node OSM.road_length OSM.route_length OSM.get_geoloc OSM.same_position OSM.same_road OSM.closest_node_on_edge ``` -------------------------------- ### GraphSpace Exclusive Functions Source: https://github.com/juliadynamics/agents.jl/blob/main/docs/src/api.md Functions specific to GraphSpace for managing graph structures (edges and vertices). ```julia add_edge! rem_edge! add_vertex! rem_vertex! ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.