Skip to content

Commit

Permalink
Allow fractional food_sources
Browse files Browse the repository at this point in the history
  • Loading branch information
kavir1698 committed Oct 24, 2023
1 parent b98e55a commit 9c0a9e6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/model_description.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}
Expand Down
4 changes: 2 additions & 2 deletions test/params.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions test/simulation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9c0a9e6

Please sign in to comment.