如何控制智能体绘制顺序以将某些智能体放置在彼此之上?

How do I control agent plotting order to place certain agents on top of each other?

提问人:cj_cool 提问时间:11/11/2023 更新时间:11/11/2023 访问量:26

问:

我正在尝试制作具有混合代理(绿色补丁和无人机代理)的模型的绘图/动画,并希望将无人机代理绘制在补丁代理之上。我在下面附上了我的代码和图像。一些无人机代理绘制在补丁的顶部,而其他代理则绘制在补丁后面。我想知道是否有解决方案。

我的一个想法是,这与代理的日程安排有关。

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)))

Example of what I am trying to avoid

我看了看我是否能找到任何人们这样做的例子,但无法做到。最接近的事情是将其重写为补丁的模型步骤,但六边形网格的性质使它变得困难(除非我要重写我的整个模型)。

朱莉娅 特工.jl

评论

0赞 Dan Getz 11/11/2023
我的直觉是调度程序将确定此顺序。然后查看文档,可能会有所帮助。如果这没有帮助,则排序可能是代理字典中的内部顺序。希望这会有所帮助。Schedulers.ByID()Schedulers.ByProperty(property)
0赞 Dan Getz 11/11/2023
在查看了代码/文档后,我认为您可能希望在调用以创建模型时添加或。如果未删除任何代理,则后者更好。在这两种情况下,容器中代理的顺序可能是显示顺序,并且可以按此操作。container = OrderedDictcontainer = VectorStandardABM
1赞 cj_cool 11/14/2023
container = Vector有效,但导致了与以前相同的结果。绘图顺序由模型中的 ID 顺序决定,该顺序并不总是与 1 到 n 个代理相同。我不确定处理此代理最终被删除的最佳方法,但我确信有一种方法可以在初始化期间更改顺序。谢谢@DanGetzcontainer = OrderDict
0赞 Dan Getz 11/14/2023
对于 Vector 容器(也许还有 OrderedDict),可以选择手动置换代理。但这需要测试,因为有些可能依赖于顺序保持不变(尽管这听起来很牵强)

答: 暂无答案