--- "Peter" example 

in dynamics.maude

--- in dynamics.maude

omod EDWARD-LEE-EXAMPLE-PETER is

 including RUNTIME-APG .


 op x : -> IVarId [ctor] .
 ops reactor1 reactor2 reactor3 : -> ReactorId [ctor] .
 ops in in1 in2  out : -> IPortId [ctor] .
 --- op startup : -> ActionId .
 op init : -> Configuration .

 eq init = 

    < reactor1 : Reactor | 
      inports : < in1 : Port | value : [0] > 
                 < in2 : Port | value : [0] >,
      outports : < out : Port | value : [0] >, 
      state : x |-> [3],
      timers : none,
      actions : none,
      reactions : 
        (reaction when in2 --> out do { (x := x * x) ; (out <- x) })
        reaction when in1  do { x := x + [8] }
    > 


    < reactor2 : Reactor | 
      inports : < in : Port | value : [0] >,
      outports : < out : Port | value : [0] >, 
      state : empty,
      timers : none,
      actions : none,
      reactions : 
        reaction when in --> out do { out <- in }
    > 

  < reactor3 : Reactor | 
      inports : < in : Port | value : [0] >,
      outports : none, 
      state : empty,
      timers : none,
      actions : none,
      reactions : 
        reaction when in do { skip }
    >

   (reactor1 : out --> reactor2 : in)
   (reactor2 : out --> reactor1 : in1)
   (reactor1 : out --> reactor3 : in) .

endom

red generateAPG(event(reactor1, in2, [2]), addReactionIndices(init)) .





omod TEST-APG is
  including EDWARD-LEE-EXAMPLE-PETER .
  including SIMULATION-DYNAMICS .

  ops env queue rxns : -> Oid [ctor] .

  op initSystem : -> GlobalSystem .
  eq initSystem =
      { < env : Environment | physicalActions : none >
        addReactionIndices(init)
	< queue : EventQueue | queue : event(reactor1, in2, [2]) at tag(0,0) >
	< rxns : Invoked | reactions : none >} .
endom





--- red initializeAPG(event(y, startup, [0]), init) .

--- red executeStep(event(reactor1, in2, [2]), init, empty) .

rew initSystem .

search initSystem =>! CS:ClockedSystem .

--- works perfectly in new complex setting ...