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

Almost all space methods work

parent 273d228e
......@@ -22,7 +22,7 @@ module ABMEv
@reexport using Distributions, DataFrames
export GraphSpace,ContinuousSegment,DiscreteSegment,RealSpace,
AbstractSpacesTuple
AbstractSpacesTuple,get_inc
export update_rates!
export MixedAgent,StdAgent,Agent,get_fitness,get_x,get_t,get_dim,
get_nancestors,get_xarray,get_xhist,
......
......@@ -50,39 +50,43 @@ struct RealSpace{N,T} <: AbstractSpace{N,T,IsFinite{false}} end
function get_inc(D,s::AbstractSpace{Dim,T,I}) where {Dim,T,I<:IsFinite{false}}
if Dim > 1
return D[:] .* rand(T,Dim)
tuple(T.(return D[:] .* rand(Dim)))
else
return D * rand(T)
return T(D * rand())
end
end
get_inc(x,D,s::AbstractSpace{Dim,T,I}) where {Dim,T,I<:IsFinite{false}} = get_inc(D,s)
function get_inc(x,D,s::ContinuousSegment{T}) where {T}
inc = D * rand(T)
return reflect1D(x,inc,s)
inc = D * rand()
return _reflect1D(x,inc,s)
end
function get_inc(x,D,s::DiscreteSegment{T}) where {T}
inc = D * rand(T)
return round(reflect1D(x,inc,s))
inc = D * rand()
return round(T,_reflect1D(x,inc,s))
end
function get_inc(x,D,s::GraphSpace{T}) where {T}
niter = round(S*rand(T))
return last(randomwalk(s.g,x,niter))
niter = round(Int,D*rand())
if niter > 0
return last(randomwalk(s.g,x,niter)) - x
else
return 0
end
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)
if x + inc < s
function _reflect1D(x::Number,inc::Number,s::AbstractSegment)
if x + inc < s.s
inc = 2 * ( s.s - x ) - inc
elseif x + inc > e
elseif x + inc > s.e
inc = 2 * ( s.e - x ) - inc
else
return inc
end
reflect1D(x,inc,s)
_reflect1D(x,inc,s)
end
##### SPACES #####
using LightGraphs
using Test
using Revise,ABMEv
##### SPACES #####
mysegment = DiscreteSegment(1,10)
mygraph = GraphSpace(SimpleGraph(10,10))
myline = RealSpace{2,Float64}()
......@@ -13,9 +13,18 @@ myspace2 = (mysegment,mygraph,myline)
@test isfinite(mysegment) true
@test isfinite(mygraph) true
@test isfinite(myline) false
@test ndims(myline) == 2
@test isfinite(mycontinuoussegment) true
@test typeof(myspace) <: AbstractSpacesTuple
# still does not work
@test get_inc([0.],myline) (0.,0.)
@test get_inc([0.,0.],myline) (0.,0.)
# checking if reflection works
@test mysegment.s < get_inc(5.,100.,mysegment) + 5. < mysegment.e
@test mycontinuoussegment.s < get_inc(0.,100.,mycontinuoussegment) < mycontinuoussegment.e
#checking if graph works
@test get_inc(1,10,mygraph) + 1 vertices(mygraph.g)
##### AGENTS #######
......
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