|
1 | 1 | using Symbolics: StateMachineOperator |
| 2 | + |
| 3 | +""" |
| 4 | + $(TYPEDEF) |
| 5 | +
|
| 6 | +Struct used to represent a connection equation. A connection equation is an `Equation` |
| 7 | +where the LHS is an empty `Connection(nothing)` and the RHS is a `Connection` containing |
| 8 | +the connected connectors. |
| 9 | +
|
| 10 | +For special types of connections, the LHS `Connection` can contain relevant metadata. |
| 11 | +""" |
| 12 | +struct Connection |
| 13 | + systems::Any |
| 14 | +end |
| 15 | + |
| 16 | +Base.broadcastable(x::Connection) = Ref(x) |
| 17 | +Connection() = Connection(nothing) |
| 18 | +Base.hash(c::Connection, seed::UInt) = hash(c.systems, (0xc80093537bdc1311 % UInt) ⊻ seed) |
| 19 | +Symbolics.hide_lhs(_::Connection) = true |
| 20 | + |
| 21 | +""" |
| 22 | + $(TYPEDSIGNATURES) |
| 23 | +
|
| 24 | +Connect multiple connectors created via `@connector`. All connected connectors |
| 25 | +must be unique. |
| 26 | +""" |
| 27 | +function connect(sys1::AbstractSystem, sys2::AbstractSystem, syss::AbstractSystem...) |
| 28 | + syss = (sys1, sys2, syss...) |
| 29 | + length(unique(nameof, syss)) == length(syss) || error("connect takes distinct systems!") |
| 30 | + Equation(Connection(), Connection(syss)) # the RHS are connected systems |
| 31 | +end |
| 32 | + |
| 33 | +function Base.show(io::IO, c::Connection) |
| 34 | + print(io, "connect(") |
| 35 | + if c.systems isa AbstractArray || c.systems isa Tuple |
| 36 | + n = length(c.systems) |
| 37 | + for (i, s) in enumerate(c.systems) |
| 38 | + str = join(split(string(nameof(s)), NAMESPACE_SEPARATOR), '.') |
| 39 | + print(io, str) |
| 40 | + i != n && print(io, ", ") |
| 41 | + end |
| 42 | + end |
| 43 | + print(io, ")") |
| 44 | +end |
| 45 | + |
2 | 46 | isconnection(_) = false |
3 | 47 | isconnection(_::Connection) = true |
4 | 48 | """ |
@@ -188,7 +232,7 @@ var1 ~ var3 |
188 | 232 | # ... |
189 | 233 | ``` |
190 | 234 | """ |
191 | | -function Symbolics.connect(var1::ConnectableSymbolicT, var2::ConnectableSymbolicT, |
| 235 | +function connect(var1::ConnectableSymbolicT, var2::ConnectableSymbolicT, |
192 | 236 | vars::ConnectableSymbolicT...) |
193 | 237 | allvars = (var1, var2, vars...) |
194 | 238 | validate_causal_variables_connection(allvars) |
|
0 commit comments