Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar committed Jul 30, 2024
1 parent 499d40f commit 248edec
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 103 deletions.
42 changes: 1 addition & 41 deletions docs/src/tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -771,46 +771,6 @@ model = StandardABM(
agent_step!
)

# ## Adding agents of different types to the model

# Regardless of whether you went down the `Union` or `@multiagent` route,
# the API of Agents.jl has been designed such that there is no difference in subsequent
# usage.

# For example, in the union case we provide the `Union` type when we create the model,

model = StandardABM(Union{Schelling, Politician}, space)

# we add them by specifying the type

add_agent_single!(Schelling, model; group = 1, mood = true)

# or

add_agent_single!(Politician, model; preferred_demographic = 1)

# and we see

collect(allagents(model))

# For the `@multiagent` case instead

model = StandardABM(MultiSchelling, space)

# and we can add agents like so

agent = MultiSchelling'.Schelling(model; pos = random_position(model), group = 1, mood = true)
add_agent_single!(agent, model)

# or

agent = MultiSchelling'.Politician(model; pos = random_position(model), preferred_demographic = 1)
add_agent_single!(agent, model)

# and we see

collect(allagents(model))

# And that's the end of the tutorial!!!
# You can visit other examples to see other types of usage of Agents.jl,
# or go into the [API](@ref) to find the functions you need to make your own ABM!
# usage.
59 changes: 1 addition & 58 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,63 +816,6 @@ model = StandardABM(
)
````

## Adding agents of different types to the model

Regardless of whether you went down the `Union` or `@multiagent` route,
the API of Agents.jl has been designed such that there is no difference in subsequent
usage.

For example, in the union case we provide the `Union` type when we create the model,

````@example tutorial
model = StandardABM(Union{Schelling, Politician}, space)
````

we add them by specifying the type

````@example tutorial
add_agent_single!(Schelling, model; group = 1, mood = true)
````

or

````@example tutorial
add_agent_single!(Politician, model; preferred_demographic = 1)
````

and we see

````@example tutorial
collect(allagents(model))
````

For the `@multiagent` case instead

````@example tutorial
model = StandardABM(MultiSchelling, space)
````

and we can add agents like so

````@example tutorial
agent = MultiSchelling'.Schelling(model; pos = random_position(model), group = 1, mood = true)
add_agent_single!(agent, model)
````

or

````@example tutorial
agent = MultiSchelling'.Politician(model; pos = random_position(model), preferred_demographic = 1)
add_agent_single!(agent, model)
````

and we see

````@example tutorial
collect(allagents(model))
````

And that's the end of the tutorial!!!
You can visit other examples to see other types of usage of Agents.jl,
or go into the [API](@ref) to find the functions you need to make your own ABM!

usage.
4 changes: 2 additions & 2 deletions src/core/space_interaction_API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function add_agent!(model::ABM, args::Vararg{Any, N}; kwargs...) where {N}
add_agent!(A, model, args...; kwargs...)
end

function add_agent!(A::Type, model::ABM,
function add_agent!(A::Union{Function, Type}, model::ABM,
args::Vararg{Any, N}; kwargs...) where {N}
add_agent!(random_position(model), A, model, args...; kwargs...)
end
Expand All @@ -280,7 +280,7 @@ end
# lowest level - actually constructs the agent
function add_agent!(
pos::ValidPos,
A::Type,
A::Union{Function, Type},
model::ABM,
args::Vararg{Any, N};
kwargs...,
Expand Down
4 changes: 2 additions & 2 deletions src/spaces/discrete.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ end
Same as `add_agent!(A, model, properties...; kwargs...)` but ensures that it adds an agent
into a position with no other agents (does nothing if no such position exists).
"""
function add_agent_single!(A::Type, model::ABM, properties::Vararg{Any, N}; kwargs...) where {N}
function add_agent_single!(A::Union{Function, Type}, model::ABM, properties::Vararg{Any, N}; kwargs...) where {N}
position = random_empty(model)
isnothing(position) && return nothing
agent = add_agent!(position, A, model, properties...; kwargs...)
Expand Down Expand Up @@ -248,7 +248,7 @@ function fill_space!(model::ABM, args::Vararg{Any, N}; kwargs...) where {N}
end

function fill_space!(
A::Type,
A::Union{Function, Type},
model::ABM{<:DiscreteSpace},
args::Vararg{Any, N};
kwargs...,
Expand Down

0 comments on commit 248edec

Please sign in to comment.