Skip to content

Commit

Permalink
Introduced after
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilding-Elmqvist committed May 30, 2021
1 parent 0852325 commit 758383a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Symbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,21 @@ end


nCrossingFunctions = 0
nAfter = 0
nClocks = 0
nSamples = 0
previousVars = []
preVars = []

function resetEventCounters()
global nCrossingFunctions
global nAfter
global nClocks
global nSamples
global previousVars
global preVars
nCrossingFunctions = 0
nAfter = 0
nClocks = 0
nSamples = 0
previousVars = []
Expand All @@ -121,17 +124,19 @@ end

function getEventCounters()
global nCrossingFunctions
global nAfter
global nClocks
global nSamples
global previousVars
global preVars
return (nCrossingFunctions, nClocks, nSamples, previousVars, preVars)
return (nCrossingFunctions, nAfter, nClocks, nSamples, previousVars, preVars)
end

substituteForEvents(ex) = ex

function substituteForEvents(ex::Expr)
global nCrossingFunctions
global nAfter
global nClocks
global nSamples
global previousVar
Expand All @@ -143,26 +148,32 @@ function substituteForEvents(ex::Expr)
elseif ex.head == :call && ex.args[1] == :Clock
@assert 2<=length(ex.args)<=3 "The Clock function takes one or two arguments: $ex"
nClocks += 1
:(Clock(ustrip($(substituteForEvents(ex.args[2:end])...)), instantiatedModel, $nClocks))
if length(ex.args) == 2
:(Clock(ustrip($(substituteForEvents(ex.args[2]))), instantiatedModel, $nClocks))
else
:(Clock(ustrip($(substituteForEvents(ex.args[2]))), ustrip($(substituteForEvents(ex.args[3]))), instantiatedModel, $nClocks))
end
elseif ex.head == :call && ex.args[1] == :sample
nSamples += 1
:(sample($(substituteForEvents(ex.args[2])), $(substituteForEvents(ex.args[3])), instantiatedModel, $nSamples))
elseif ex.head == :call && ex.args[1] == :previous
if length(ex.args) == 2
push!(preVars, ex.args[2])
nPre = length(preVars)
:(pre($(ex.args[2]), instantiatedModel, $nPre))
:(pre(instantiatedModel, $nPre))
elseif length(ex.args) == 3
push!(previousVars, ex.args[2])
nPrevious = length(previousVars)
:(previous($(ex.args[2]), $(substituteForEvents(ex.args[3])), instantiatedModel, $nPrevious))
:(previous($(substituteForEvents(ex.args[3])), instantiatedModel, $nPrevious))
else
error("The previous function takes one or two arguments: $ex")
end
elseif ex.head == :call && ex.args[1] == :after
# Temporarily: Convert time event to state event
nCrossingFunctions += 1
:(positive(instantiatedModel, $nCrossingFunctions, ustrip(time - $(substituteForEvents(ex.args[2]))), $(string(substituteForEvents(ex.args[2]))), _leq_mode))
:(positive(instantiatedModel, $nCrossingFunctions, ustrip(time-$(substituteForEvents(ex.args[2]))), $(string(substituteForEvents(ex.args[2]))), _leq_mode))
# after(instantiatedModel, nr, t, tAsString, leq_mode)
# nAfter += 1
# :(after(instantiatedModel, $nAfter, ustrip($(substituteForEvents(ex.args[2]))), $(string(substituteForEvents(ex.args[2]))), _leq_mode))
else
Expr(ex.head, ex.args[1], [substituteForEvents(arg) for arg in ex.args[2:end]]...)
end
Expand Down

0 comments on commit 758383a

Please sign in to comment.