Package ca.uqac.lif.cep.fsm
Class MooreMachine
- java.lang.Object
-
- ca.uqac.lif.cep.Processor
-
- ca.uqac.lif.cep.SynchronousProcessor
-
- ca.uqac.lif.cep.fsm.MooreMachine
-
- All Implemented Interfaces:
ca.uqac.lif.azrael.Printable
,ca.uqac.lif.azrael.Readable
,ca.uqac.lif.cep.Contextualizable
,ca.uqac.lif.cep.Duplicable
,ca.uqac.lif.cep.DuplicableProcessor
,ca.uqac.lif.cep.Stateful
public class MooreMachine extends ca.uqac.lif.cep.SynchronousProcessor implements ca.uqac.lif.cep.Stateful
A finite-state automaton with output symbols associated to its states. Its input arity is not fixed to 1, i.e. it can read events from multiple traces at once. (Although, theoretically, this can be reduced to the unary case, so this is not a genuine generalization.)A "classical" finite-state automaton is a particular case of Moore machine where one simply ignores any output symbols. In that context, accepting and rejecting states can simply be associated to two different, arbitrary symbols (e.g.
true
andfalse
).- Author:
- Sylvain Hallé
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MooreMachine.Transition
Represents a transition in the Moore machine
-
Field Summary
Fields Modifier and Type Field Description protected int
m_currentState
The current state the machine is inprotected java.util.Set<ca.uqac.lif.cep.functions.ContextAssignment>
m_initialAssignments
The initial assignments given to each variableprotected int
m_initialState
The initial state of the machineprotected java.util.Map<java.lang.Integer,java.lang.Integer>
m_lastOccurrences
A map storing the last event position for each stateprotected java.util.List<java.lang.Integer>
m_looplessPath
A map storing the last loopless pathprotected java.util.Map<java.lang.Integer,ca.uqac.lif.cep.functions.Function[]>
m_outputSymbols
Associates output symbols to the states of the machineprotected java.util.Map<java.lang.Integer,java.util.List<MooreMachine.Transition>>
m_relation
A map from a state to the list of transitions from that state-
Fields inherited from class ca.uqac.lif.cep.SynchronousProcessor
m_inputPushables, m_outputPullables, m_tempQueue
-
Fields inherited from class ca.uqac.lif.cep.Processor
m_context, m_eventTracker, m_hasBeenNotifiedOfEndOfTrace, m_inputArity, m_inputCount, m_inputPullables, m_inputQueues, m_notifiedEndOfTraceDownstream, m_outputArity, m_outputCount, m_outputPushables, m_outputQueues, MAX_PULL_RETRIES, s_versionString
-
-
Constructor Summary
Constructors Constructor Description MooreMachine(int in_arity, int out_arity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addInitialAssignment(ca.uqac.lif.cep.functions.ContextAssignment asg)
MooreMachine
addSymbol(int state, ca.uqac.lif.cep.functions.Function symbol)
Associates an output symbol (i.e.MooreMachine
addSymbols(int state, ca.uqac.lif.cep.functions.Function... symbols)
Associates output symbols (i.e.MooreMachine
addTransition(int source, MooreMachine.Transition t)
Adds a transition to the machineprotected void
assignToContext(ca.uqac.lif.cep.functions.ContextAssignment asg)
protected boolean
compute(java.lang.Object[] inputs, java.util.Queue<java.lang.Object[]> outputs)
MooreMachine
duplicate(boolean with_state)
protected boolean
fire(MooreMachine.Transition t, java.lang.Object[] inputs, java.lang.Object[] outputs)
Fires a transition and updates the machine's statejava.lang.Object
getState()
void
reset()
protected void
updatePathHistory()
protected void
updateProvenance()
-
Methods inherited from class ca.uqac.lif.cep.SynchronousProcessor
getPullableOutput, getPushableInput, setEventTracker
-
Methods inherited from class ca.uqac.lif.cep.Processor
allNotifiedEndOfTrace, allNull, associateTo, associateToInput, associateToOutput, copyInputQueue, copyOutputQueue, duplicate, duplicateInto, equals, getAt, getContext, getContext, getEmptyQueue, getEventTracker, getId, getInputArity, getInputCount, getInputQueue, getInputType, getInputTypesFor, getLeaves, getLeaves, getOutputArity, getOutputCount, getOutputQueue, getOutputType, getPullableInput, getPullableOutput, getPushableInput, getPushableOutput, hashCode, leftShift, newContext, onEndOfTrace, or, or, print, printState, read, readState, rightShift, setContext, setContext, setPullableInput, setPushableOutput, start, startAll, stop, stopAll
-
-
-
-
Field Detail
-
m_relation
protected java.util.Map<java.lang.Integer,java.util.List<MooreMachine.Transition>> m_relation
A map from a state to the list of transitions from that state
-
m_outputSymbols
protected java.util.Map<java.lang.Integer,ca.uqac.lif.cep.functions.Function[]> m_outputSymbols
Associates output symbols to the states of the machine
-
m_currentState
protected int m_currentState
The current state the machine is in
-
m_initialState
protected int m_initialState
The initial state of the machine
-
m_lastOccurrences
protected java.util.Map<java.lang.Integer,java.lang.Integer> m_lastOccurrences
A map storing the last event position for each state
-
m_looplessPath
protected java.util.List<java.lang.Integer> m_looplessPath
A map storing the last loopless path
-
m_initialAssignments
protected java.util.Set<ca.uqac.lif.cep.functions.ContextAssignment> m_initialAssignments
The initial assignments given to each variable
-
-
Method Detail
-
addInitialAssignment
public void addInitialAssignment(ca.uqac.lif.cep.functions.ContextAssignment asg)
-
assignToContext
protected void assignToContext(ca.uqac.lif.cep.functions.ContextAssignment asg)
-
reset
public void reset()
- Overrides:
reset
in classca.uqac.lif.cep.Processor
-
addSymbols
public MooreMachine addSymbols(int state, ca.uqac.lif.cep.functions.Function... symbols)
Associates output symbols (i.e. event) to a state of the Moore machine- Parameters:
state
- The statesymbols
- The symbols to associate. This will be the output event produced whenever the machine takes a transition ending in that state. There should be as many symbols as the output arity of the machine- Returns:
- A reference to the current Moore machine
-
addSymbol
public MooreMachine addSymbol(int state, ca.uqac.lif.cep.functions.Function symbol)
Associates an output symbol (i.e. event) to a state of the Moore machine- Parameters:
state
- The statesymbol
- The symbol to associate. This will be the output event produced whenever the machine takes a transition ending in that state. There should be as many symbols as the output arity of the machine. Therefore this method should only be called on a Moore machine of output arity 1.- Returns:
- A reference to the current Moore machine
-
addTransition
public MooreMachine addTransition(int source, MooreMachine.Transition t)
Adds a transition to the machine- Parameters:
source
- The source statet
- The transition to add- Returns:
- A reference to the current Moore machine
-
compute
protected boolean compute(java.lang.Object[] inputs, java.util.Queue<java.lang.Object[]> outputs) throws ca.uqac.lif.cep.ProcessorException
- Specified by:
compute
in classca.uqac.lif.cep.SynchronousProcessor
- Throws:
ca.uqac.lif.cep.ProcessorException
-
updatePathHistory
protected void updatePathHistory()
-
updateProvenance
protected void updateProvenance()
-
fire
protected boolean fire(MooreMachine.Transition t, java.lang.Object[] inputs, java.lang.Object[] outputs)
Fires a transition and updates the machine's state- Parameters:
t
- The transition to fireinputs
- The inputs that caused the transition to fireoutputs
- Any output symbol associated with the destination state,null
otherwise- Returns:
true
if an output symbol is produced,false
otherwise
-
duplicate
public MooreMachine duplicate(boolean with_state)
- Specified by:
duplicate
in interfaceca.uqac.lif.cep.Duplicable
- Specified by:
duplicate
in classca.uqac.lif.cep.Processor
-
getState
public java.lang.Object getState()
- Specified by:
getState
in interfaceca.uqac.lif.cep.Stateful
-
-