Browse Source

BUG: Use `__init__` function with Requires.jl.

pull/48/head
Evan Patterson 4 weeks ago
parent
commit
d92cf6fa3d
  1. 38
      src/interoperability.jl
  2. 1
      test/Project.toml

38
src/interoperability.jl

@ -1,26 +1,28 @@
using Requires
@require Petri="4259d249-1051-49fa-8328-3f8ab9391c33" begin
import .Petri
function __init__()
@require Petri="4259d249-1051-49fa-8328-3f8ab9391c33" begin
import .Petri
# Interoperability with Petri.jl
Petri.Model(p::AbstractPetriNet) = begin
ts = TransitionMatrices(p)
t_in = map(i->Dict(k=>v for (k,v) in enumerate(ts.input[i,:]) if v != 0), 1:nt(p))
t_out = map(i->Dict(k=>v for (k,v) in enumerate(ts.output[i,:]) if v != 0), 1:nt(p))
# Interoperability with Petri.jl
Petri.Model(p::AbstractPetriNet) = begin
ts = TransitionMatrices(p)
t_in = map(i->Dict(k=>v for (k,v) in enumerate(ts.input[i,:]) if v != 0), 1:nt(p))
t_out = map(i->Dict(k=>v for (k,v) in enumerate(ts.output[i,:]) if v != 0), 1:nt(p))
Δ = Dict(i=>t for (i,t) in enumerate(zip(t_in, t_out)))
return Model(ns(p), Δ)
end
Δ = Dict(i=>t for (i,t) in enumerate(zip(t_in, t_out)))
return Petri.Model(ns(p), Δ)
end
Petri.Model(p::Union{AbstractLabelledPetriNet, AbstractLabelledReactionNet}) = begin
snames = [sname(p, s) for s in 1:ns(p)]
tnames = [tname(p, t) for t in 1:nt(p)]
ts = TransitionMatrices(p)
t_in = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.input[i,:]) if v != 0]...), 1:nt(p))
t_out = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.output[i,:]) if v != 0]...), 1:nt(p))
Petri.Model(p::Union{AbstractLabelledPetriNet, AbstractLabelledReactionNet}) = begin
snames = [sname(p, s) for s in 1:ns(p)]
tnames = [tname(p, t) for t in 1:nt(p)]
ts = TransitionMatrices(p)
t_in = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.input[i,:]) if v != 0]...), 1:nt(p))
t_out = map(i->LVector(;[(snames[k]=>v) for (k,v) in enumerate(ts.output[i,:]) if v != 0]...), 1:nt(p))
Δ = LVector(;[(tnames[i]=>t) for (i,t) in enumerate(zip(t_in, t_out))]...)
return Model(collect(values(snames)), Δ)
Δ = LVector(;[(tnames[i]=>t) for (i,t) in enumerate(zip(t_in, t_out))]...)
return Petri.Model(collect(values(snames)), Δ)
end
end
end

1
test/Project.toml

@ -1,5 +1,6 @@
[deps]
AlgebraicPetri = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
Petri = "4259d249-1051-49fa-8328-3f8ab9391c33"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Loading…
Cancel
Save