-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add structured agents and related examples
- Loading branch information
1 parent
033f202
commit 8652f3d
Showing
13 changed files
with
697 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export AbstractStructuredSpecies, BaseStructuredSpecies | ||
export @structured | ||
export add_structured_species! | ||
|
||
# Abstract supertype of all structured species. | ||
abstract type AbstractStructuredSpecies <: AbstractAlgebraicAgent end | ||
|
||
# It comes handy to keep track of the transition the entity is assigned to (if). | ||
# In general, we will probably assume that each "structured agent" type implements this field. | ||
# Otherwise, it would be possible to implement getter and setter interface and use it from within ReaDyn. | ||
@aagent FreeAgent struct BaseStructuredSpecies | ||
bound_transition::Union{Nothing, ReactiveDynamics.Transition} | ||
end | ||
|
||
# We use this to let the network know that the type is structured. | ||
function register_structured_species!(reaction_network, type) | ||
if !(type ∈ reaction_network[:, :specName]) | ||
add_part!(reaction_network, :S; specName = type) | ||
end | ||
|
||
i = first(incident(reaction_network, type, :specName)) | ||
reaction_network[i, :specStructured] = true | ||
|
||
return nothing | ||
end | ||
|
||
# Convenience macro to define structured species. | ||
macro structured(network, type) | ||
name = Docs.namify(type.args[2]) | ||
|
||
quote | ||
$(AlgebraicAgents.aagent(BaseStructuredSpecies, AbstractStructuredSpecies, type, ReactiveDynamics)) | ||
register_structured_species!($(esc(network)), $(QuoteNode(name))) | ||
end | ||
end | ||
|
||
# Add a structured agent instance to an instance of a reaction network. | ||
function add_structured_species!(problem::ReactionNetworkProblem, agent) | ||
entangle!(getagent(problem, "structured/$(nameof(typeof(agent)))"), agent) | ||
end | ||
|
||
import AlgebraicAgents | ||
|
||
# By default, structured agents have no evolutionary rule. | ||
AlgebraicAgents._projected_to(::AbstractStructuredSpecies) = nothing | ||
AlgebraicAgents._step!(::AbstractStructuredSpecies) = nothing | ||
|
||
# Tell if an agent is assigned to a transition, as a resource. | ||
isblocked(a) = !isnothing(a.bound_transition) | ||
|
||
# Priority with which an unbound agent will be assigned to a transition. | ||
priority(a, transition) = 0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.