To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 273d228e authored by Victor's avatar Victor
Browse files

The code is not working, we are still testing every piece of code one by one

parent 5b94cf5c
......@@ -4,21 +4,28 @@ module ABMEv
using Distributions,LinearAlgebra,Reexport,StatsBase
using LightGraphs
using UnPack
using DocStringExtensions
include("ABMEv_Agent.jl")
include("ABMEv_Space.jl")
include("ABMEv_WF.jl")
include("ABMEv_Gillepsie.jl")
include("ABMEv_CFM.jl")
include("ABMEv_runworld.jl")
include("ABMEv_Agent.jl")
include("ABMEv_world.jl")
include("ABMEv_Sim.jl")
include("ABMEv_metrics.jl")
include("ABMEv_plot.jl")
include("ABMEv_utils.jl")
include("algo/ABMEv_WF.jl")
include("algo/ABMEv_Gillepsie.jl")
include("algo/ABMEv_CFM.jl")
include("ABMEv_runworld.jl")
@reexport using Distributions, DataFrames
export GraphSpace,ContinuousSegment,DiscreteSegment,RealSpace,
AbstractSpacesTuple
export update_rates!
export MixedAgent,StdAgent,Agent,get_fitness,get_x,get_t,get_dim,get_nancestors,get_xarray,get_xhist,
export MixedAgent,StdAgent,Agent,get_fitness,get_x,get_t,get_dim,
get_nancestors,get_xarray,get_xhist,
get_thist,get_geo,get_b,get_d,increment_x!,get_inc_reflected,world2df,
split_move,split_merge_move,tin,new_world_G
export copy,runWorld_store_WF,runWorld_store_G,clean_world #,runWorld_G!,runWorld_WF!,
......
......@@ -5,6 +5,10 @@ hasrates(::Type{Rates{T}}) where {T} = T # not sure we need it
abstract type AbstractAgent{A<:Ancestors,R<:Rates} end # tc for time contingency, fit for fitness coeff
AbstractAgentM = Union{Missing,AbstractAgent}
"""
$(TYPEDEF)
"""
mutable struct Agent{A<:Ancestors,R<:Rates,T,U,V} <: AbstractAgent{A,R}
# history of traits for geotraits
pos::Array{T,1}
......@@ -146,7 +150,7 @@ end
This function increments agent by random numbers specified in p
ONLY FOR CONTINUOUS DOMAINS
"""
function increment_x!(a::AbstractAgent{A,R},s<:AbstractSpacesTuple,p<:Dict{String,Any},t<:T) where {A<:Ancestors{true},R,T}
function increment_x!(a::AbstractAgent{A,R},s::AbstractSpacesTuple,p::Dict{String,Any},t::T) where {A<:Ancestors{true},R,T}
@unpack D,mu = p
_x = get_x(a)
inc = similar(_x)
......@@ -159,7 +163,7 @@ function increment_x!(a::AbstractAgent{A,R},s<:AbstractSpacesTuple,p<:Dict{Strin
a.x_history = push!(a.x_history, _x + inc);
end
function increment_x!(a::AbstractAgent{A,R},s<:AbstractSpacesTuple,p<:Dict{String,Any},t<:T) where {A<:Ancestors{false},R,T}
function increment_x!(a::AbstractAgent{A,R},s::AbstractSpacesTuple,p::Dict{String,Any},t::T) where {A<:Ancestors{false},R,T}
@unpack D,mu = p
_x = get_x(a)
inc = get_inc.(_x,D,s)
......
abstract type AbstractAlg end
# this used to be world
mutable struct Simulation{A<:AbstractAgentM, S<:AbstractSpacesTuple,T<:Number,N<:Number}
......
using LightGraphs
"""
abstract type AbstractSpace{Dim,T,F} end
`Dim` is the dimension of the space, `T` is the element type, `ife` is a bool which is `true`
......@@ -16,22 +15,35 @@ Base.eltype(::AbstractSpace{Dim,T,I}) where {Dim,T,I} = T
SpaceType=Union{Nothing, AbstractSpace} # not sure what is this used for
"""
$(TYPEDEF)
"""
struct GraphSpace{T} <: AbstractSpace{1,T,IsFinite{true}}
g::AbstractGraph{T}
end
abstract type AbstractSegment{T} <: AbstractSpace{1,T,IsFinite{true}} end
"""
$(TYPEDEF)
"""
struct ContinuousSegment{T} <: AbstractSegment{T}
s::T
e::T
end
"""
$(TYPEDEF)
"""
struct DiscreteSegment{T} <: AbstractSegment{T}
s::T
e::T
end
struct Real1DSpace{T} <: AbstractSpace{1,T,IsFinite{false}} end
"""
$(TYPEDEF)
"""
struct RealSpace{N,T} <: AbstractSpace{N,T,IsFinite{false}} end
# TODO: find a way to put a type on get_inc
# TODO: there is probably a better way of dealing with get_inc
......@@ -56,32 +68,15 @@ function get_inc(x,D,s::DiscreteSegment{T}) where {T}
end
function get_inc(x,D,s::GraphSpace{T}) where {T}
niter = round(rand(T) < D)
inc = D * rand(T)
return round(reflect1D(x,inc,s))
end
"""
function increment_x!(a::Agent{MixedAgent,U},t::U,p::Dict) where U
This function increments first trait of agent with integer values, that are automatically reflected between 1 and p["nodes"].
Other traits are incremented as usual.
TODO : make it work for a graph type landscape, where domain is not a line anymore.
"""
function increment_x!(a::Agent{MixedAgent,U},t,p::Dict) where U
tdim = length(p["D"])
inc = [round(get_inc_reflected(get_x(a,1),p["D"][1] *randn(),1,p["nodes"]))]
if tdim > 1
inc = vcat(inc,(rand(tdim-1) < p["mu"][2:end]) .* p["D"][2:end] .* randn(tdim-1))
end
a.x_history = hcat(a.x_history, get_x(a) + reshape(inc,:,1));
push!(a.t_history,t)
niter = round(S*rand(T))
return last(randomwalk(s.g,x,niter))
end
"""
function get_inc_reflected(x::Number,inc::Number,s=-1,e=1)
Here we increment the trajectory of trait 1 such that it follows a reflected brownian motion (1D)
"""
function reflect1D(x::Number,inc::Number,s<:AbstractSegment)
function reflect1D(x::Number,inc::Number,s::AbstractSegment)
if x + inc < s
inc = 2 * ( s.s - x ) - inc
elseif x + inc > e
......
abstract type AbstractAlg end
function solve(m::Model;dt_saving=nothing,callbacks=nothing)
end
"""
update_rates_std!(world,p::Dict,t::Float64)
......
......@@ -19,12 +19,12 @@ agents(world) = skipmissing(world.agents)
size(world) = size(world.agents) - count(ismissing,world.agents)
maxsize(w::World) = length(w.agents)
_findfreeidx(w::World) = findfirst(findfirst(ismissing,w.agents))
addAgent!(w::World,a<:AbstractAgent) = begin
addAgent!(w::World,a::AbstractAgent) = begin
idx = _findfreeidx(w)
w.agents[idx] = a
return nothing
end
removeAgent!(w::world,i::Int) = begin
removeAgent!(w::World,i::Int) = begin
world[i] = missing
return nothing
end
......
......@@ -6,7 +6,7 @@ struct Gillepsie <: AbstractAlg end
function give_birth(a::Agent,t,p::Dict)
Used for Gillepsie setting
"""
function give_birth(mum_idx::Int,w::World{AbstractAgent{A,R},S,T}) where {A <: Ancestors{true}}
function give_birth(mum_idx::Int,w::World{AbstractAgent{A,R},S,T}) where {A <: Ancestors{true},R,S,T}
new_a = copy(w[mum_idx])
increment_x!(new_a,space(w),parameters(w),time(w))
return new_a
......
##### SPACES #####
using LightGraphs
using Test
using Revise,ABMEv
mysegment = DiscreteSegment(1,10)
mygraph = GraphSpace(SimpleGraph(10,10))
myline = Real1DSpace{Float64}()
myspace = (mysegment,mygraph,myline)
myline = RealSpace{2,Float64}()
mycontinuoussegment = ContinuousSegment(-1,1)
myspace = (mysegment,mygraph,myline,mycontinuoussegment)
myspace2 = (mysegment,mygraph,myline)
@test isfinite(mysegment) true
@test isfinite(mygraph) true
@test isfinite(myline) false
@test isfinite(mycontinuoussegment) true
@test typeof(myspace) <: AbstractSpacesTuple
##### AGENTS #######
a1 = Agent(myspace)
a1bis = Agent(myspace2)
a2 = Agent(myspace,ancestors = true)
a3 = Agent(myspace,(1,1,1.))
a4 = Agent(myspace,(1,1,1.),rates=true)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment