Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
ABMEv
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
bvictor
ABMEv
Commits
de690e73
Commit
de690e73
authored
Jan 24, 2021
by
Victor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aggreg_last_dt : added option to save cb at specified time steps
parent
7f19ee0d
Pipeline
#84298
failed with stage
in 18 minutes and 19 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
4 deletions
+43
-4
src/ABMEv_Sim.jl
src/ABMEv_Sim.jl
+9
-0
src/ABMEv_runworld.jl
src/ABMEv_runworld.jl
+17
-2
test/simulation.jl
test/simulation.jl
+17
-2
No files found.
src/ABMEv_Sim.jl
View file @
de690e73
...
...
@@ -53,6 +53,15 @@ function add_entry!(s::Simulation{A,S,T,F},w::World) where {A,S,T,F}
return
nothing
end
function
add_entry_cb_only!
(
s
::
Simulation
{
A
,
S
,
T
,
F
},
w
::
World
)
where
{
A
,
S
,
T
,
F
}
push!
(
s
.
agentarray
,[
Agent
(
w
.
space
)])
# pushing NA agents
push!
(
s
.
tspan
,
w
.
t
)
if
!
(
F
==
Nothing
)
push!
(
s
.
df_agg
,
Dict
(
s
.
cb
.
names
.=>
[
f
(
w
)
for
f
in
s
.
cb
.
agg
]))
end
return
nothing
end
#TODO : code it
function
get_xnt
(
s
::
Simulation
;
trait
=
1
)
return
[
getindex
.
(
wa
,
trait
)
for
wa
in
s
.
agentarray
],[
fill
(
t
,
size
(
s
[
j
]))
for
(
j
,
t
)
in
enumerate
(
s
.
tspan
)]
...
...
src/ABMEv_runworld.jl
View file @
de690e73
...
...
@@ -4,25 +4,35 @@
Run `w` with algorithm `alg`, until `tend` is reached. User needs to provide `b` the birth function,
which takes as arguments `X,t`, and provide `d` the death function, with arguments `X,Y,t`.
Returns a `Simulation` type.
-
`worldall` stores the world every `p["
dt_saving
"]`
time steps.
-
if `dt_saving` specified, world is saved every
time steps.
If `dt_saving` not specified, `sim` contains an array of two elements,
first corresponding to initial conditions and last corresponding to world in the last time step.
- if `t_saving_cb::Array{Float64}` specified, callbacks are computed at each steps time specified in the array.
This functionality is as of now only compatible with `dt_saving` not specified.
- `cb` correspond to callbacks function. Look at the documentation for more information
- the run stops if the number of agents reaches`p["
NMax
"]`.
"""
function
run!
(
w
::
World
{
A
,
S
,
T
},
alg
::
L
,
tend
::
Number
,
b
,
d
;
dt_saving
=
nothing
,
t_saving_cb
=
nothing
,
cb
=
(
names
=
String
[],
agg
=
nothing
))
where
{
A
,
S
,
T
,
L
<:
AbstractAlg
}
# argument check
_check_timedep
(
b
,
d
)
(
!
isnothing
(
dt_saving
)
&&
!
isnothing
(
dt_saving
))
?
ArgumentError
(
"For now, can not specify both `dt_saving` and `t_saving_cb`"
)
:
nothing
isnothing
(
dt_saving
)
?
dt_saving
=
tend
+
1.
:
nothing
isnothing
(
t_saving_cb
)
?
t_saving_cb
=
[
tend
+
1.
]
:
nothing
# var init
n
=
size
(
w
);
NMax
=
maxsize
(
w
)
t
=
.
0
i
=
1
;
j
=
1
;
dt
=
0.
isnothing
(
dt_saving
)
?
dt_saving
=
tend
+
1.
:
nothing
sim
=
Simulation
(
w
,
cb
=
cb
)
if
A
<:
AbstractAgent
{
AA
,
Rates
{
true
}}
where
{
AA
}
update_rates!
(
w
,
alg
,
b
,
d
)
end
# start
while
t
<
tend
if
dt
<
0
throw
(
"We obtained negative time step dt =
$
dt at event
$
i"
)
...
...
@@ -37,6 +47,11 @@ function run!(w::World{A,S,T},alg::L,tend::Number,b,d;
@info
"saving world @ t =
$(t)
/
$(tend)
"
add_entry!
(
sim
,
w
)
end
if
t
>=
first
(
t_saving_cb
)
@info
"saving callback only @ t =
$(t)
/
$(tend)
"
add_entry_cb_only!
(
sim
,
w
)
popfirst!
(
t_saving_cb
)
end
dt
=
updateWorld!
(
w
,
alg
,
b
,
d
)
t
+=
dt
i
+=
1
...
...
test/simulation.jl
View file @
de690e73
...
...
@@ -33,14 +33,15 @@ myspace = (RealSpace{1,Float64}(),)
sigma_K
=
.
9
;
sigma_a
=
.
7
;
K0
=
1000
;
b
(
X
)
=
gaussian
(
X
[
1
],
0.
,
sigma_K
)
d
(
X
,
Y
)
=
gaussian
(
X
[
1
],
Y
[
1
],
sigma_a
)
/
K0
b
(
X
,
t
)
=
gaussian
(
X
[
1
],
0.
,
sigma_K
)
d
(
X
,
Y
,
t
)
=
gaussian
(
X
[
1
],
Y
[
1
],
sigma_a
)
/
K0
D
=
(
1e-2
,)
mu
=
[
.
1
]
NMax
=
10000
tend
=
1.5
p
=
Dict
{
String
,
Any
}();
@pack
!
p
=
D
,
mu
,
NMax
## testing cb
myagents
=
[
Agent
(
myspace
,(
0
,),
ancestors
=
true
,
rates
=
true
)
for
i
in
1
:
K0
]
w0
=
World
(
myagents
,
myspace
,
p
,
0.
)
w1
=
copy
(
w0
)
...
...
@@ -53,6 +54,20 @@ eltype(cb.agg)
@test
typeof
(
get_world
(
sim
,
get_size
(
sim
)))
<:
World
@test
typeof
(
sim
[
2
])
<:
Vector
##testing t_saving_cb
myagents
=
[
Agent
(
myspace
,(
0
,),
ancestors
=
true
,
rates
=
true
)
for
i
in
1
:
K0
]
w0
=
World
(
myagents
,
myspace
,
p
,
0.
)
w1
=
copy
(
w0
)
cb
=
(
names
=
[
"gamma_div"
],
agg
=
Function
[
w
->
var
(
Float64
.
(
get_x
(
w
,
1
)))])
eltype
(
cb
.
agg
)
@time
sim
=
run!
(
w1
,
Gillepsie
(),
tend
,
b
,
d
,
cb
=
cb
,
t_saving_cb
=
collect
(
1.0
:
0.1
:
1.5
))
@test
typeof
(
sim
[
"gamma_div"
])
<:
Vector
@test
get_size
(
sim
)
==
length
(
sim
[
"gamma_div"
])
@test
length
(
sim
[
1
])
==
1000
@test
length
(
sim
[
end
])
>
1
@test
length
(
sim
[
2
])
==
1
## testing plot
using
Plots
plot
(
get_tspan
(
sim
),
sim
[
"gamma_div"
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment