Skip to content

Indexing over tuples of symbols #182

@SamuelBrand1

Description

@SamuelBrand1

In the vectorfield function

""" vectorfield(pn::AbstractPetriNet)
Generates a Julia function which calculates the vectorfield of the Petri net
being simulated under the law of mass action.
The resulting function has a signature of the form `f!(du, u, p, t)` and can be
passed to the DifferentialEquations.jl solver package.
"""
vectorfield(pn::AbstractPetriNet) = begin
tm = TransitionMatrices(pn)
dt = tm.output - tm.input
(du, u, p, t) -> begin
rates = zeros(valtype(du), nt(pn))
u_m = [u[sname(pn, i)] for i in 1:ns(pn)]
p_m = [p[tname(pn, i)] for i in 1:nt(pn)]
for i in 1:nt(pn)
rates[i] = valueat(p_m[i], u, t) * prod(u_m[j]^tm.input[i, j] for j in 1:ns(pn))
end
for j in 1:ns(pn)
du[sname(pn, j)] = sum(rates[i] * dt[i, j] for i in 1:nt(pn); init=0.0)
end
du
end
end

it is assumed that the state and parameter arrays u, p etc can be indexed by the species name. This is fine when the species name is a symbol, but its also possible to have species names that are tuples of symbols e.g. from using typed_product.

Is there a recommended way to define arrays that can be indexed by Tuples of symbols?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions