You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I need to plot buildings as well as road networks for my project so I checked out OSMMakie and followed the example provided in the README. I integrated it into Zombie Outbreak example to test it and it threw a BoundError trying to access 3rd element of a 2 element Vector.
Minimal Working Example
I changed the Zombie example to include building data
# # Zombie Outbreak in a Cityusing Agents
using Random
@agentstructZombie(OSMAgent)
infected::Bool
speed::Float64endfunctioninitialise_zombies(; seed =1234)
map_path = OSM.test_map()
properties =Dict(:dt=>1/60)
model =StandardABM(
Zombie,
OpenStreetMapSpace(map_path);
agent_step! = zombie_step!,
properties = properties,
rng = Random.MersenneTwister(seed)
)
for id in1:100
start =random_position(model) # At an intersection
speed =rand(abmrng(model)) *5.0+2.0# Random speed from 2-7kmph
human =add_agent!(start, Zombie, model, false, speed)
OSM.plan_random_route!(human, model; limit =50) # try 50 times to find a random routeend## We'll add patient zero at a specific (longitude, latitude)
start = OSM.nearest_road((9.9351811, 51.5328328), model)
finish = OSM.nearest_node((9.945125635913511, 51.530876112711745), model)
speed =rand(abmrng(model)) *5.0+2.0# Random speed from 2-7kmph
zombie =add_agent!(start, model, true, speed)
plan_route!(zombie, finish, model)
## This function call creates & adds an agent, see `add_agent!`return model
endfunctionzombie_step!(agent, model)
## Each agent will progress along their route## Keep track of distance left to move this step, in case the agent reaches its## destination early
distance_left =move_along_route!(agent, model, agent.speed * model.dt)
ifis_stationary(agent, model) &&rand(abmrng(model)) <0.1## When stationary, give the agent a 10% chance of going somewhere else
OSM.plan_random_route!(agent, model; limit =50)
## Start on new route, moving the remaining distancemove_along_route!(agent, model, distance_left)
endif agent.infected
## Agents will be infected if they get too close (within 10m) to a zombie.map(i -> model[i].infected =true, nearby_ids(agent, model, 0.01))
endreturnend# ## Visualising the fall of humanity# Notice that to visualize Open Street Maps, the package OSMMakie.jl must be loaded# as well, besides any Makie plotting backend such as CairoMakie.jl.using CairoMakie, OSMMakie
zombie_color(agent) = agent.infected ?:green::blackzombie_size(agent) = agent.infected ?10:8
zombies =initialise_zombies()
# ====== begin changed lines ================# add LightOSM for building datausing LightOSM
# load as Buildings Dict
buildings =buildings_from_file(OSM.test_map());
spaceplotkwargs = (;
buildings = buildings
)
# ====== end changed lines ================abmvideo("outbreak.mp4", zombies;
title ="Zombie outbreak", framerate =15, frames =200,
agent_color = zombie_color, agent_size = zombie_size,
spaceplotkwargs = spaceplotkwargs # also here
)
Agents.jl version
Julia version 1.10.6 (Precompile of AgentsVisualizations fail in 1.11.1)
Agents v6.1.11
CairoMakie v0.12.15
LightOSM v0.3.1
OSMMakie v0.0.10
My Workaround
osm_plot.plots[1].plots[3].inspectable[] =false
Replacing 3 with 2 or commenting it out makes the code compile and display the buildings. I am not sure how inspectables work so that's my current solution to see some buildings.
The text was updated successfully, but these errors were encountered:
Describe the bug
I need to plot buildings as well as road networks for my project so I checked out OSMMakie and followed the example provided in the README. I integrated it into Zombie Outbreak example to test it and it threw a BoundError trying to access 3rd element of a 2 element Vector.
Minimal Working Example
I changed the Zombie example to include building data
Stacktrace
Agents.jl version
Julia version 1.10.6 (Precompile of AgentsVisualizations fail in 1.11.1)
Agents v6.1.11
CairoMakie v0.12.15
LightOSM v0.3.1
OSMMakie v0.0.10
My Workaround
Replacing 3 with 2 or commenting it out makes the code compile and display the buildings. I am not sure how inspectables work so that's my current solution to see some buildings.
The text was updated successfully, but these errors were encountered: