提问人:cj_cool 提问时间:11/11/2023 更新时间:11/11/2023 访问量:26
如何控制智能体绘制顺序以将某些智能体放置在彼此之上?
How do I control agent plotting order to place certain agents on top of each other?
问:
我正在尝试制作具有混合代理(绿色补丁和无人机代理)的模型的绘图/动画,并希望将无人机代理绘制在补丁代理之上。我在下面附上了我的代码和图像。一些无人机代理绘制在补丁的顶部,而其他代理则绘制在补丁后面。我想知道是否有解决方案。
我的一个想法是,这与代理的日程安排有关。
function agent_color(a)
if a isa Patch
color = "#007500" # get_color(a.prob_burn)
if a.status == :on_fire
color = :red
elseif a.status == :burnt
color = :gray55
end
elseif a isa UAV
color = :blue
else
end
color
end
const uav_polygon = Makie.Polygon(Point2f[(-.5,-.5), (1,0), (-.5,.5)])
function uav_marker(u::UAV)
t = atan(u.vel[2], u.vel[1])
shape = rotate_polygon(uav_polygon, t)
return shape
end
function agent_shape(a)
if a isa Patch
shape = :hexagon
if a.status == :on_fire
shape = :circle
elseif a.status == :burnt
shape = :rect
end
elseif a isa UAV
shape = uav_marker(a)
else
end
shape
end
figure, _ = Agents.abmplot(forest; ac = agent_color,as = 24, am = agent_shape, scatterkwargs = (strokewidth = 0.1,), figure = (;resolution = (500,500)))
我看了看我是否能找到任何人们这样做的例子,但无法做到。最接近的事情是将其重写为补丁的模型步骤,但六边形网格的性质使它变得困难(除非我要重写我的整个模型)。
答: 暂无答案
评论
Schedulers.ByID()
Schedulers.ByProperty(property)
container = OrderedDict
container = Vector
StandardABM
container = Vector
有效,但导致了与以前相同的结果。绘图顺序由模型中的 ID 顺序决定,该顺序并不总是与 1 到 n 个代理相同。我不确定处理此代理最终被删除的最佳方法,但我确信有一种方法可以在初始化期间更改顺序。谢谢@DanGetzcontainer = OrderDict