Class SituationRecognizer

java.lang.Object
  |
  +--SituationRecognizer
All Implemented Interfaces:
java.lang.Runnable

public class SituationRecognizer
extends java.lang.Object
implements java.lang.Runnable

This is the main class of the application. The user interface is provided by a SituationWindow can be shown from this class. This class implements runnable and is started from the SituationWindow when the user starts the recognizer. In the run() method a loop is started that runs the recognition process at specified intervals. Furthermore this class creates and controls all other classes and windows of the application.


Field Summary
protected  java.lang.String currentSituationName
          The name of the situation that has been in the previous recognition process.
protected  double endThreshhold
          The endThreshhold is the value above which the probability for the end of a situation must be before the situation is considered to be finished.
protected  JESSCommunicator jessCommunicator
          The JESSCommunicator is a shell around the JESS engine.
protected  JessViewer jessViewer
          The JessViewer is a window that can show the contents of the JESS engine.
protected  boolean running
          This boolean is set to false when the user stops the recognition process.
protected  int sampleInterval
          This is the interval at which the recognition process is run.
protected  java.util.HashMap situations
          This is the HashMap of the situations that the XMLParser has parsed from the XML file.
protected  java.util.Comparator situationsComparator
          This comparator compares the start probabilities of two situations.
protected  java.util.HashMap situationStates
          This is a HashMap of the situations with a Vector with the start and end probability for every situation.
protected  SituationWindow situationWindow
          The SituationWindow provides the user interface and is used to show the results of the recognition process to the user.
protected  double startThreshhold
          The startThreshhold is the value above which the probability for the start of a situation must be before the situation can be detected.
protected  VariableReader variableReader
          The VariableReader reads the values of all variables from the flight simulator, displays them in the VariableWindow and puts them in the JESS engine.
protected  VariableWindow variableWindow
          The VariableWindow shows the values of all variables from the flight simulator.
protected  XMLParser xmlParser
          The XMLParser parses the xml file and creates a hashmap of Situation objects.
 
Constructor Summary
SituationRecognizer()
          The constructor.
 
Method Summary
 void addPerformedAction(java.lang.String situationName)
          This method is called from the JESSCommunicator when one of the action rules in the JESS engine has fires.
protected  void addSituationProbs(java.lang.String situationName, double startProb, double endProb)
          The start and end probabilities for the situation with the given name are stored in a Vector, which is then stored in a HashMap which is passed to the SituationWindow later on.
 boolean isRunning()
          Returns true if the recognizer is running, false otherwise.
 boolean loadXMLFile(java.io.File xmlFile)
          Load and parse the knowledge base in the xml file.
static void main(java.lang.String[] args)
          The main function of the application.
 void pauseRecognizer()
          Pause the recognition process by setting the boolean running to false.
 void recognizerWillStart()
          This method is called just before the recognizer is started.
 void run()
          Starts the recognition process.
 void setSituationState(java.lang.String situationName, java.lang.String state)
          This method is called from the JESSCommunicator when the state of the situation is changed in the JESS engine.
 void showWindow()
          Displays the SituationWindow.
 void stopRecognizer()
          Stops the recognizer, clears the situation states and resets the JESS engine and the situations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jessCommunicator

protected JESSCommunicator jessCommunicator
The JESSCommunicator is a shell around the JESS engine.


jessViewer

protected JessViewer jessViewer
The JessViewer is a window that can show the contents of the JESS engine.


xmlParser

protected XMLParser xmlParser
The XMLParser parses the xml file and creates a hashmap of Situation objects.


variableWindow

protected VariableWindow variableWindow
The VariableWindow shows the values of all variables from the flight simulator.


variableReader

protected VariableReader variableReader
The VariableReader reads the values of all variables from the flight simulator, displays them in the VariableWindow and puts them in the JESS engine.


situationWindow

protected SituationWindow situationWindow
The SituationWindow provides the user interface and is used to show the results of the recognition process to the user.


situations

protected java.util.HashMap situations
This is the HashMap of the situations that the XMLParser has parsed from the XML file.


situationStates

protected java.util.HashMap situationStates
This is a HashMap of the situations with a Vector with the start and end probability for every situation.


sampleInterval

protected int sampleInterval
This is the interval at which the recognition process is run.


running

protected boolean running
This boolean is set to false when the user stops the recognition process.


currentSituationName

protected java.lang.String currentSituationName
The name of the situation that has been in the previous recognition process.


startThreshhold

protected double startThreshhold
The startThreshhold is the value above which the probability for the start of a situation must be before the situation can be detected.


endThreshhold

protected double endThreshhold
The endThreshhold is the value above which the probability for the end of a situation must be before the situation is considered to be finished.


situationsComparator

protected java.util.Comparator situationsComparator
This comparator compares the start probabilities of two situations. It returns 1 if the start probability of the first is lower than that of the second, it return -1 if it is bigger and it returns 0 if they are equal. This comparator is used to sort situation from ones with a high start probability to ones with a low start probability.

Constructor Detail

SituationRecognizer

public SituationRecognizer()
The constructor. Nothing has to be done here, because everything has already been intitialized upon declaration.

Method Detail

showWindow

public void showWindow()
Displays the SituationWindow.


run

public void run()
Starts the recognition process. This is just a loop in which the following is done: 1 - the variables are updated from the flight simulator and put in the JESS engine. 2 - the JESS engine is run. During this run the situation states are set from the JESS engine and the number of performed actions of the situation is updated. 3 - the end probabilities of the situations are calculated. This must be done first, because the end probabilities must be known to be able to calculate the start probabilities. 4 - the start probabilities are calculated and the start and end probabilities are set in the situationStates HashMap. 5 - the situations are ordered from ones with a high start probability to those with a low start probability. 6 - the first situation that is not equals to the current situation and with an end probability below the threshhold is taken as the candidate to become the next situation. 7 - if the candidate has a start probability that is above the threshhold and the current situation either has a start probability that is lower than that of the candidate's or the current situation has an end probability that is above the threshold, then the candidate is set as the current situation. 8 - the situations with their probabilities are given to the SituationWindow to be shown. 9 - the thread is put to sleep for the remaining time of the sampleinterval.

Specified by:
run in interface java.lang.Runnable

pauseRecognizer

public void pauseRecognizer()
Pause the recognition process by setting the boolean running to false. This will make sure no new recognition loop is started. The currently running one is still completed though, so some output might be generated after this method has been called. This is handled by the SituationWindow.


stopRecognizer

public void stopRecognizer()
Stops the recognizer, clears the situation states and resets the JESS engine and the situations.


recognizerWillStart

public void recognizerWillStart()
This method is called just before the recognizer is started. This allows the recognizer to set the first situation to the current one.


isRunning

public boolean isRunning()
Returns true if the recognizer is running, false otherwise. This method is called by the SituationWindow to see if output has to be generated.

Returns:
Whether or not the recognizer is running.

loadXMLFile

public boolean loadXMLFile(java.io.File xmlFile)
Load and parse the knowledge base in the xml file. After parsing, all the situations are retreived from the XML parser and the knowledge about those situations is put intor the JESS engine.

Parameters:
xmlFile - The file where all the knowledge is stored.
Returns:
false if the parsing failed, true otherwise.

setSituationState

public void setSituationState(java.lang.String situationName,
                              java.lang.String state)
This method is called from the JESSCommunicator when the state of the situation is changed in the JESS engine. The situation is retrieved from the HashMap, its state is set and it is put back into the HashMap.

Parameters:
situationName - The name of the situation.
state - The new state of the situation.

addPerformedAction

public void addPerformedAction(java.lang.String situationName)
This method is called from the JESSCommunicator when one of the action rules in the JESS engine has fires. The situation is retrieved from the HashMap, the action is added and it is put back into the HashMap.

Parameters:
situationName - The name of the situation.

main

public static void main(java.lang.String[] args)
The main function of the application.

Parameters:
args - Some arguments

addSituationProbs

protected void addSituationProbs(java.lang.String situationName,
                                 double startProb,
                                 double endProb)
The start and end probabilities for the situation with the given name are stored in a Vector, which is then stored in a HashMap which is passed to the SituationWindow later on. The SituationWindow can then show these probabilities to the user.

Parameters:
situationName - The name of the situation.
startProb - The start probability of the situation.
endProb - The end probability of the situation.