From 9c0a9e671e731c9102136faa7089013d590469ee Mon Sep 17 00:00:00 2001 From: "Ali R. Vahdati" <3798865+kavir1698@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:27:32 +0200 Subject: [PATCH] Allow fractional `food_sources` --- Manifest.toml | 2 +- docs/src/model_description.md | 2 +- src/simulation.jl | 4 ++-- test/params.jl | 4 ++-- test/simulation_tests.jl | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index f5ec4b5..c555c3e 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.9.3" manifest_format = "2.0" -project_hash = "258ed9e440181bed6256b11f7984f152ada90bbe" +project_hash = "e4622a3cb46b2a8d5e23230aa9eea61f09a488ce" [[deps.Agents]] deps = ["CSV", "CommonSolve", "DataFrames", "DataStructures", "Distributed", "Distributions", "Downloads", "Graphs", "JLD2", "LazyArtifacts", "LightOSM", "LinearAlgebra", "Pkg", "ProgressMeter", "Random", "Rotations", "Scratch", "StaticArrays", "StatsBase"] diff --git a/docs/src/model_description.md b/docs/src/model_description.md index cbd69b1..6014bc8 100644 --- a/docs/src/model_description.md +++ b/docs/src/model_description.md @@ -50,7 +50,7 @@ This dictionary should be named "model_parameters". * __space__:A tuple of two integers (e.g., `(3,2)`) determining the size of space. If you do not want any spatial structure, use `(1,1)`. * __metric__: Either "chebyshev" or "euclidean". Determines how many neighbors a space site has. "chebyshev" metric means that the r-neighborhood of a position includes all positions within the hypercube with a side length of 2 * floor(r) and centered at the origin position. "euclidean" metric means that the r-neighborhood of a position includes all positions whose Cartesian indices have Euclidean distance ≤ r from the Cartesian index of the given position. * __periodic__: A Boolean value (true or false) determining whether the boundaries of the space are connected or not. -* __resources__: A vector of matrices where each matrix has the size of the space and determines the amount of resources per site. The vector is as long as the number of model steps (generations) plus 1 (for time zero). +* __resources__: A vector of matrices where each matrix has the size of the space and determines the amount of resources per site. The vector is as long as the number of model steps (generations) plus 1 (for time zero). The elements should be floating point numbers. * __interactions__: A species-species interaction matrix of floating-point numbers determining how individuals from different species interact. Each value represents the strength of interaction (between 0 and 1). The sign (+/-) indicates the direction of interaction, where a positive value means similar individuals interact more strongly, and a negative value means dissimilar individuals tend to interact more. * __food\_sources__: A species-species food matrix of floating-point numbers determining what each species feeds on (consumption rate). Non-zero values on the diagonal indicate that the food resource is from the environment. Off-diagonal values indicate that a species (in the rows) feeds on another species (in the columns). Numbers can be zero or any positive number. The magnitude of the number determines how much energy the predator gains by eating the prey. All species use 1 unit of energy per time step. * __seed__: Either an integer or `nothing` for a random number. diff --git a/src/simulation.jl b/src/simulation.jl index ab3832c..e1c89b7 100644 --- a/src/simulation.jl +++ b/src/simulation.jl @@ -47,8 +47,8 @@ struct Params{F<:AbstractFloat,I<:Int,N<:AbstractString} names::Dict{I,N} food_sources::Matrix{F} interactions::Matrix{F} - resources::Matrix{I} - resources_org::Vector{Matrix{I}} + resources::Matrix{F} + resources_org::Vector{Matrix{F}} recombination::Vector{Poisson{F}} initial_energy::Vector{F} bottlenecks::Vector{Vector{Matrix{F}}} diff --git a/test/params.jl b/test/params.jl index 36ed115..133d1af 100644 --- a/test/params.jl +++ b/test/params.jl @@ -3,9 +3,9 @@ space = (2, 2) function env_resources(time::Int) if time < 7 - return [2000 1980; 1830 1900] + return [2000.0 1980.0; 1830.0 1900.0] else - return [2000 1980; 1830 1900] .+ 50 + return [2000.0 1980.0; 1830.0 1900.0] .+ 50 end end diff --git a/test/simulation_tests.jl b/test/simulation_tests.jl index 417324a..6d60216 100644 --- a/test/simulation_tests.jl +++ b/test/simulation_tests.jl @@ -5,7 +5,7 @@ @test !haskey(model.agents, 1) == true EvoDynamics.consume_food!(model[2], model) - @test model.resources == [1999 1980; 1830 1900] + @test model.resources == [1999.0 1980.0; 1830.0 1900.0] @test EvoDynamics.coord2vertex((2, 1), model) == 2 @test EvoDynamics.coord2vertex((1, 2), model) == 3 @@ -111,8 +111,8 @@ end EvoDynamics.interact!(agent, agent2, model) @test agent.isalive == false - @test length(EvoDynamics.target_species_ids(agent, model)) == 2 - @test length(EvoDynamics.target_species_ids(agent2, model)) == 2 + @test length(EvoDynamics.target_species_ids(agent, model)) == 4 + @test length(EvoDynamics.target_species_ids(agent2, model)) == 4 # reproduction nagentsbefore = EvoDynamics.nagents(model)