1- export AbstractStructuredSpecies, BaseStructuredSpecies
2- export @structured
3- export add_structured_species !
1+ export AbstractStructuredToken, BaseStructuredToken
2+ export @structured_token
3+ export add_structured_token !
44
55# Abstract supertype of all structured species.
6- abstract type AbstractStructuredSpecies <: AbstractAlgebraicAgent end
6+ abstract type AbstractStructuredToken <: AbstractAlgebraicAgent end
77
88# It comes handy to keep track of the transition the entity is assigned to (if).
99# In general, we will probably assume that each "structured agent" type implements this field.
1010# Otherwise, it would be possible to implement getter and setter interface and use it from within ReaDyn.
11- @aagent FreeAgent struct BaseStructuredSpecies
11+ @aagent FreeAgent struct BaseStructuredToken
12+ species:: Union{Nothing,Symbol}
1213 bound_transition:: Union{Nothing,ReactiveDynamics.Transition}
14+ past_bonds:: Vector{Tuple{Symbol,Float64,Transition}}
1315end
1416
1517# We use this to let the network know that the type is structured.
@@ -25,33 +27,45 @@ function register_structured_species!(reaction_network, type)
2527end
2628
2729# Convenience macro to define structured species.
28- macro structured (network, type)
29- name = Docs. namify (type. args[2 ])
30-
30+ macro structured_token (network, type)
3131 quote
3232 $ (AlgebraicAgents. aagent (
33- BaseStructuredSpecies ,
34- AbstractStructuredSpecies ,
33+ BaseStructuredToken ,
34+ AbstractStructuredToken ,
3535 type,
3636 ReactiveDynamics,
3737 ))
38- register_structured_species! ($ (esc (network)), $ (QuoteNode (name)))
3938 end
4039end
4140
4241# Add a structured agent instance to an instance of a reaction network.
43- function add_structured_species ! (problem:: ReactionNetworkProblem , agent)
44- return entangle! (getagent (problem, " structured/ $( nameof ( typeof (agent))) " ), agent)
42+ function add_structured_token ! (problem:: ReactionNetworkProblem , agent)
43+ return entangle! (getagent (problem, " structured" ), agent)
4544end
4645
4746import AlgebraicAgents
4847
4948# By default, structured agents have no evolutionary rule.
50- AlgebraicAgents. _projected_to (:: AbstractStructuredSpecies ) = nothing
51- AlgebraicAgents. _step! (:: AbstractStructuredSpecies ) = nothing
49+ AlgebraicAgents. _projected_to (:: AbstractStructuredToken ) = nothing
50+ AlgebraicAgents. _step! (:: AbstractStructuredToken ) = nothing
5251
5352# Tell if an agent is assigned to a transition, as a resource.
54- isblocked (a) = ! isnothing (a. bound_transition)
53+ isblocked (a:: AbstractStructuredToken ) = ! isnothing (get_bound_transition (a))
54+
55+ # Add a record that an agent was used as "species" in a "transition".
56+ function add_to_log! (a:: AbstractStructuredToken , species:: Symbol , t, transition:: Transition )
57+ return push! (a. past_bonds, (species, Float64 (t), transition))
58+ end
59+
60+ # Set the transition a token is bound to.
61+ get_bound_transition (a:: AbstractStructuredToken ) = a. bound_transition
62+ function set_bound_transition! (a:: AbstractStructuredToken , t:: Union{Nothing,Transition} )
63+ return a. bound_transition = t
64+ end
5565
5666# Priority with which an unbound agent will be assigned to a transition.
57- priority (a, transition) = 0.0
67+ priority (a:: AbstractStructuredToken , transition) = 0.0
68+
69+ # What species (place) is an agent currently assigned to.
70+ get_species (a:: AbstractStructuredToken ) = a. species
71+ set_species! (a:: AbstractStructuredToken , species:: Symbol ) = a. species = species
0 commit comments