Showing 2 of 6 files from the diff.

@@ -30,6 +30,8 @@
Loading
30 30
@deprecate node_neighbors nearby_positions
31 31
@deprecate get_node_contents agents_in_pos
32 32
@deprecate pick_empty random_empty
33 +
@deprecate find_empty_nodes empty_positions
34 +
@deprecate has_empty_nodes has_empty_positions
33 35
34 36
# Predefined models
35 37
include("models/Models.jl")

@@ -7,7 +7,7 @@
Loading
7 7
- agents_in_pos(position, model)
8 8
=#
9 9
10 -
export nodes, agents_in_pos, find_empty_nodes, random_empty, has_empty_nodes
10 +
export nodes, agents_in_pos, empty_positions, random_empty, has_empty_positions
11 11
12 12
"""
13 13
    nodes(model::ABM{A, <:DiscreteSpace}) → ns
@@ -34,7 +34,7 @@
Loading
34 34
end
35 35
36 36
# TODO: Does this really have to be collecting...?
37 -
function find_empty_nodes(model::ABM{<:AbstractAgent,<:DiscreteSpace})
37 +
function empty_positions(model::ABM{<:AbstractAgent,<:DiscreteSpace})
38 38
    collect(Iterators.filter(i -> length(agents_in_pos(i, model)) == 0, nodes(model)))
39 39
end
40 40
@@ -46,12 +46,11 @@
Loading
46 46
47 47
48 48
"""
49 -
    has_empty_nodes(model::ABM{A, <:DiscreteSpace})
49 +
    has_empty_positions(model::ABM{A, <:DiscreteSpace})
50 50
Return `true` if there are any positions in the model without agents.
51 51
"""
52 -
function has_empty_nodes(model::ABM{<:AbstractAgent,<:DiscreteSpace})
53 -
    s = model.space.s
54 -
    return any(i -> length(i) == 0, s)
52 +
function has_empty_positions(model::ABM{<:AbstractAgent,<:DiscreteSpace})
53 +
    return any(i -> length(i) == 0, model.space.s)
55 54
end
56 55
57 56
"""
@@ -59,9 +58,9 @@
Loading
59 58
Return a random position without any agents, or `nothing` if no such positions exist.
60 59
"""
61 60
function random_empty(model::ABM{<:AbstractAgent,<:DiscreteSpace})
62 -
    empty_nodes = find_empty_nodes(model)
63 -
    isempty(empty_nodes) && return nothing
64 -
    rand(empty_nodes)
61 +
    empty = empty_positions(model)
62 +
    isempty(empty) && return nothing
63 +
    rand(empty)
65 64
end
66 65
67 66
#######################################################################################
@@ -93,9 +92,9 @@
Loading
93 92
    properties...;
94 93
    kwargs...,
95 94
) where {A<:AbstractAgent}
96 -
    empty_positions = find_empty_nodes(model)
97 -
    if length(empty_positions) > 0
98 -
        add_agent!(rand(empty_positions), model, properties...; kwargs...)
95 +
    empty = empty_positions(model)
96 +
    if length(empty) > 0
97 +
        add_agent!(rand(empty), model, properties...; kwargs...)
99 98
    end
100 99
end
101 100
@@ -163,17 +162,16 @@
Loading
163 162
"""
164 163
    move_agent_single!(agent::A, model::ABM{A, <:DiscreteSpace}) → agentt
165 164
166 -
Move agent to a random node while respecting a maximum of one agent
167 -
per node. If there are no empty nodes, the agent won't move.
165 +
Move agent to a random position while respecting a maximum of one agent
166 +
per position. If there are no empty positions, the agent won't move.
168 167
"""
169 168
function move_agent_single!(
170 169
        agent::A,
171 170
        model::ABM{A,<:DiscreteSpace},
172 171
    ) where {A<:AbstractAgent}
173 -
    empty_positions = find_empty_nodes(model)
174 -
    if length(empty_positions) > 0
175 -
        random_node = rand(empty_positions)
176 -
        move_agent!(agent, random_node, model)
172 +
    empty = empty_positions(model)
173 +
    if length(empty) > 0
174 +
        move_agent!(agent, rand(empty), model)
177 175
    end
178 176
    return agent
179 177
end
Files Coverage
src 89.27%
Project Totals (13 files) 89.27%
Notifications are pending CI completion. Waiting for GitHub's status webhook to queue notifications. Push notifications now.
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading