Skip to content

Commit 277275e

Browse files
committed
introduce single argument EIndex/VIndex to acces models
1 parent d9c2368 commit 277275e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/show.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ end
147147
function Base.show(io::IO, idx::EIndex)
148148
print(io, "EIndex(", repr(idx.compidx), ", ", repr(idx.subidx), ")")
149149
end
150+
function Base.show(io::IO, idx::VIndex{<:Any,Nothing})
151+
print(io, "VIndex(", repr(idx.compidx), ")")
152+
end
153+
function Base.show(io::IO, idx::EIndex{<:Any,Nothing})
154+
print(io, "EIndex(", repr(idx.compidx), ")")
155+
end
150156
function Base.show(io::IO, idx::VPIndex)
151157
print(io, "VPIndex(", repr(idx.compidx), ", ", repr(idx.subidx), ")")
152158
end

src/symbolicindexing.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ A symbolic index for a vertex state variable.
1010
VIndex(1, :P) # vertex 1, variable :P
1111
VIndex(1:5, 1) # first state of vertices 1 to 5
1212
VIndex(7, (:x,:y)) # states :x and :y of vertex 7
13+
VIndex(2) # references the second vertex model
1314
```
1415
1516
Can be used to index into objects supporting the `SymbolicIndexingInterface`,
@@ -21,6 +22,7 @@ struct VIndex{C,S} <: SymbolicStateIndex{C,S}
2122
compidx::C
2223
subidx::S
2324
end
25+
VIndex(ci::Union{Symbol,Int}) = VIndex(ci, nothing)
2426
"""
2527
EIndex{C,S} <: SymbolicStateIndex{C,S}
2628
idx = EIndex(comp, sub)
@@ -33,6 +35,7 @@ A symbolic index for an edge state variable.
3335
EIndex(1, :P) # edge 1, variable :P
3436
EIndex(1:5, 1) # first state of edges 1 to 5
3537
EIndex(7, (:x,:y)) # states :x and :y of edge 7
38+
EIndex(2) # references the second edge model
3639
```
3740
3841
Can be used to index into objects supporting the `SymbolicIndexingInterface`,
@@ -44,6 +47,7 @@ struct EIndex{C,S} <: SymbolicStateIndex{C,S}
4447
compidx::C
4548
subidx::S
4649
end
50+
EIndex(ci::Union{Symbol,Int}) = EIndex(ci, nothing)
4751
"""
4852
VPIndex{C,S} <: SymbolicStateIndex{C,S}
4953
idx = VPIndex(comp, sub)
@@ -1168,3 +1172,11 @@ end
11681172

11691173
Base.getindex(s::NWState, idx::ObservableExpression) = SII.getu(s, idx)(s)
11701174
Base.getindex(s::NWParameter, idx::ObservableExpression) = SII.getp(s, idx)(s)
1175+
1176+
# using getindex to access component models
1177+
function Base.getindex(nw::Network, i::EIndex{<:Union{Symbol,Int}, Nothing})
1178+
return nw.im.edgem[resolvecompidx(nw,i)]
1179+
end
1180+
function Base.getindex(nw::Network, i::VIndex{<:Union{Symbol,Int}, Nothing})
1181+
return nw.im.vertexm[resolvecompidx(nw,i)]
1182+
end

0 commit comments

Comments
 (0)