In [58]:
path = joinpath(Pkg.dir(),"Sugarscape", "src", "chapterII.jl")
Out[58]:
In [59]:
include(path)
In [60]:
sc = ChapterII
Out[60]:
In [61]:
sc.run(1)
@time scape = sc.run(500)
Out[61]:
In [62]:
sc.plot(scape)
Out[62]:
In [63]:
function run_carrypop(N; kwargs...)
carrypop = Int[]
scape = sc.init_scape(sc.init_capacity(); kwargs...)
push!(carrypop, sum(map(sc.alive,scape.agents)))
for cnt = 1:N
sc.timestep(scape; kwargs...)
push!(carrypop, sum(map(sc.alive,scape.agents)))
end
scape,carrypop
end
Out[63]:
In [64]:
scape, carrypop = run_carrypop(500)
PyPlot.plot(carrypop)
PyPlot.title("Carrying capacity")
PyPlot.xlabel("time steps")
Out[64]:
In [65]:
using DataFrames
In [69]:
function carrying(;sim_steps=3, time_steps=500)
carry = DataFrame(vision=Int[], metabolism=Int[], population = Int[])
for vision = 1:10, metabolism = 1:3, sims = 1:sim_steps
scape = sc.run(time_steps; init_vision=()->rand(1:(2vision-1)), init_metabolism=()->rand(1:(2metabolism-1)))
push!(carry, [vision, metabolism, sum(map(sc.alive, scape.agents))])
end
carry
end
Out[69]:
In [70]:
carry = carrying();
Out[70]:
In [92]:
using Gadfly
In [104]:
carry_aggr = by(carry, [:vision, :metabolism],df -> DataFrame(pop = mean(df[:population])))
plot(carry_aggr, x=:vision, y=:pop, color=:metabolism, Geom.line)
Out[104]:
In [108]:
plot(carry_aggr, x=:vision, y=:pop, color=:metabolism, Geom.line)
Out[108]:
In [112]:
import StatsBase
In [115]:
StatsBase.hist(scape.agents,10)