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 16f6fd9f authored by Victor's avatar Victor
Browse files

all test run smoothly

parent ce88d252
Pipeline #93149 failed with stage
in 13 minutes and 57 seconds
name = "ABMEv"
uuid = "837ac870-fb52-4b0c-9a0e-030f2f36f5ed"
authors = ["Victor Boussange "]
version = "3.3.0"
version = "3.4.0"
[deps]
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
......
......@@ -25,14 +25,9 @@ eltype(a::Agent{A,R,T,U,V}) where {A,R,T,U,V} = T
# infers position type and zeros
function _initpos(s::S) where {S<:AbstractSpacesTuple}
T = collect(eltype.(s))
TT = collect(T)
_nd = ndims.(s)
for (i,n) in enumerate(_nd)
if n > 1
TT[i] = Vector{TT[i]}
end
end
T = eltype.(s)
TT = _get_types_dim(s)
pos = Union{TT...}[]
for i in 1:length(TT)
if _nd[i] > 1
......@@ -68,13 +63,7 @@ end
# this allows to initilise agents from any time steps knowing ancestors traits
function Agent(s::S,pos_t::Vector,t::Vector{U};ancestors=false,rates=true) where {S <: AbstractSpacesTuple, U <: AbstractFloat}
T = eltype.(s)
TT = collect(T) # we need an array to convert thereafter position
_nd = ndims.(s)
for (i,n) in enumerate(_nd)
if n > 1
TT[i] = Vector{T[i]}
end
end
TT = _get_types_dim(s)
length(pos_t) == length(t) ? nothing : ArgumentError("length of `pos` should match length of `t`")
# we convert all
pos2_t = Vector{Union{TT...}}[]
......@@ -84,7 +73,7 @@ function Agent(s::S,pos_t::Vector,t::Vector{U};ancestors=false,rates=true) where
try
push!(pos2,convert(TT[i],p))
catch e
throw(ArgumentError("Position provided does not match with underlying space"))
throw(ArgumentError("Position at dimension $i provided does not match with underlying space"))
end
end
push!(pos2_t,pos2)
......
......@@ -169,3 +169,15 @@ function _reflect1D(x::Number,inc::Number,s::AbstractSegment)
end
_reflect1D(x,inc,s)
end
function _get_types_dim(s::S) where S<:AbstractSpacesTuple
T = eltype.(s)
TT = collect(T)
_nd = ndims.(s)
for (i,n) in enumerate(_nd)
if n > 1
TT[i] = Vector{TT[i]}
end
end
return TT
end
# this used to be the worldalive
# TODO: do a constructor that ensures the parameters numerics are of the same type as the agents
mutable struct World{A<:AbstractAgent, S<:AbstractSpacesTuple,T<:Number}
agents::Vector{A}
space::S
......@@ -9,22 +8,32 @@ mutable struct World{A<:AbstractAgent, S<:AbstractSpacesTuple,T<:Number}
end
#constructor
function World(w::Vector{A},s::S,p::Dict,t::T=0.) where {A<:AbstractAgent,S<:AbstractSpacesTuple,T}
function World(w::Vector{A},s::S,p::Dict;t::T=0.) where {A<:AbstractAgent,S<:AbstractSpacesTuple,T}
# if typeof(p["D"]) != eltype(skipmissing(w)[1])
# throw(ArgumentError("Diffusion coefficient does not match with underlying space\n `D::Tuple`"))
# end
if typeof(first(w)) !== A
throw(ArgumentError("eltype(w) should be equal to typeof(first(w)), which is not the case.\n
Try to generate the array of Agents in an other way"))
end
@unpack D,mu = p
for _m in mu
if typeof(m) !<: Float
if !(typeof(_m) <: AbstractFloat)
throw(ArgumentError("elements of mu should be of type AbstractFloat\n
to decide if mutations occur from a uniform probability law"))
end
end
length(mu) == ndims(s) ? nothing : "Dimension of parameter mu should correspond to dimension of underlying space"
length(D) == ndims(s) ? nothing : "Dimension of parameter D should correspond to dimension of underlying space"
length(mu) == length(s) ? nothing : throw(ArgumentError("Length of parameter mu should correspond to dimension of underlying space"))
length(D) == length(s) ? nothing : throw(ArgumentError("Length of parameter D should correspond to dimension of underlying space"))
SS = eltype.(s)
_SS = _get_types_dim(s)
D2 = Union{_SS...}[]
for (i,Di) in enumerate(D)
try
push!(D2, convert(_SS[i],Di))
catch e
throw(ArgumentError("`D` at dimension $i does not match with underlying space"))
end
end
p["D"] = D2
World{A,S,T}(w,s,p,t)
end
......
......@@ -14,15 +14,16 @@ a2 = [Agent(myspace2,σ .* randn(2) .- .5,ancestors=true) for i in 1:K0]
a3 = [Agent(myspace3, [rand(Int16.(1:10)), 1e-1.* randn(2) .+ 5.5 ],ancestors=true) for i in 1:K0]
a4 = [Agent(myspace4, [1.,rand(Int64(1):Int64(1000))],ancestors=true) for i in 1:K0]
D = (1.,);
mu = [1.,1.]
D = [1.];
mu = [1.]
NMax = 1000
p1 = Dict{String,Any}();@pack! p1 = D,mu,NMax
D = (1.,1.);
D = [1.,1.];
mu = [1.,1.]
p2 = Dict{String,Any}();@pack! p2 = D,mu,NMax
D = (Int16(0.),(0.,0.))
D = [Int16(0.),[0.,0.]]
p3 = Dict{String,Any}();@pack! p3 = D,mu,NMax
D = (0.,0.)
D = [0.,0.]
p4 = Dict{String,Any}();@pack! p4 = D,mu,NMax
w1 = World(a1,myspace1,p1)
......@@ -91,7 +92,7 @@ multispace = (DiscreteSegment{Int8}(1,9),RealSpace{3,Float64}(),)
K0 = 10000;
multia = [Agent(multispace, [rand(Int8(1):Int8(10)),randn(3) ],ancestors=true) for i in 1:K0]
D = [Int8(1),fill(1.,3)]
mu = [1]
mu = [1.,1.]
NMax = 1000
multip = Dict{String,Any}();@pack! multip = D,mu,NMax
multiw = World(multia,multispace,multip)
......
......@@ -26,5 +26,4 @@ w0 = World(myagents,myspace,p,0.)
@testset "Hamming distances" begin
@test typeof(get_xhist_mat(agents(w0))[1] )<: Array
@test get_pairwise_average_isolation(w0) > 0
@test get_local_pairwise_average_isolation(w0) > 0
end
......@@ -6,8 +6,8 @@ myspace = (GraphSpace(SimpleGraph(10,10)),RealSpace{1,Float64}())
myagents = [Agent(myspace,ancestors=true,rates=true) for i in 1:10]
d(X,Y,t) = gaussian(X[1],Y[1],1)
b(X,Y,t) = gaussian(X[1],0,1)
D = (Int64(1),Float64(1.))
mu = [1,1]
D = [Int16(1),Float64(1.)]
mu = [1.,1.]
NMax = 100
p = Dict{String,Any}();@pack! p = d,b,D,mu,NMax
......@@ -16,7 +16,8 @@ p = Dict{String,Any}();@pack! p = d,b,D,mu,NMax
@test eltype(myagents) <: AbstractAgentM
@test typeof(myagents) <: Vector{A} where {A<:AbstractAgentM}
w = World(myagents,myspace,p,0.)
w = ABMEv.World(myagents,myspace,p)
@test typeof(w.p["D"][1]) == Int64
@test size(w) 10
newa = give_birth(1,w)
addAgent!(w,newa)
......
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