Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Xabsl2/Xabsl2Engine/Xabsl2Option.h

Go to the documentation of this file.
00001 /**
00002 * @file Xabsl2Option.h
00003 * 
00004 * Definition of class Xabsl2Option and Helper classes
00005 *
00006 * @author Martin Lötzsch
00007 */
00008 
00009 #ifndef __Xabsl2Option_h_
00010 #define __Xabsl2Option_h_
00011 
00012 #include "Xabsl2BasicBehavior.h"
00013 #include "Xabsl2BooleanExpression.h"
00014 
00015 
00016 // class prototype needed for the declaration of Xabsl2Statement
00017 class Xabsl2State;
00018 
00019 /** 
00020 * @class Xabsl2Statement 
00021 * 
00022 * An element of a decision that that determines a transition to a state.
00023 * It can be either a transition to a state or a if/else-if/else block containing other statements.
00024 * 
00025 * @author Martin Lötzsch
00026 */
00027 class Xabsl2Statement
00028 {
00029 public:
00030   /** Executes the statement and determines the next active state (can be the same). */
00031   virtual Xabsl2State* getNextState() = 0;
00032   
00033   /** 
00034   * Creates a statement depending on the input.
00035   * @param input An input source for the intermediate code. It must be opened and read until 
00036   *              A position where a statement starts.
00037   * @param subsequentOption The subsequent option of the state. 0 if the subsequent behavior is a basic behavior
00038   * @param errorHandler A reference to a Xabsl2ErrorHandler instance
00039   * @param states All states of the option
00040   * @param parameters The parameters of the option
00041   * @param symbols All available symbols
00042   * @param timeOfOptionExecution The time how long the option is already active
00043   * @param timeOfStateExecution The time how long the state is already active
00044   */
00045   static Xabsl2Statement* createStatement(Xabsl2InputSource& input,    
00046     Xabsl2Option* subsequentOption,
00047     Xabsl2ErrorHandler& errorHandler,
00048     Xabsl2Array<Xabsl2State*>& states,
00049     Xabsl2Array<double>& parameters,
00050     Xabsl2Symbols& symbols,    
00051     unsigned long& timeOfOptionExecution,
00052     unsigned long& timeOfStateExecution);
00053   
00054   /** Destructor */
00055   virtual ~Xabsl2Statement() = 0;
00056 };
00057 
00058 /**
00059 * @class Xabsl2IfElseBlock
00060 *
00061 * An element of a decision tree that that contains of an if - (else-if) - else block
00062 * 
00063 * @author Martin Lötzsch.
00064 l*/
00065 class Xabsl2IfElseBlock : public Xabsl2Statement
00066 {
00067 public:
00068 /** 
00069 * Constructor. Creates the if / else statement
00070 * @param input An input source for the intermediate code. It must be opened and read until 
00071 *              A position where a transition starts.
00072 * @param subsequentOption The subsequent option of the state. 0 if the subsequent behavior is a basic behavior
00073 * @param errorHandler A reference to a Xabsl2ErrorHandler instance
00074 * @param states All states of the option
00075 * @param parameters The parameters of the option
00076 * @param symbols All available symbols
00077 * @param timeOfOptionExecution The time how long the option is already active
00078 * @param timeOfStateExecution The time how long the state is already active
00079   */
00080   Xabsl2IfElseBlock(Xabsl2InputSource& input, 
00081     Xabsl2Option* subsequentOption,
00082     Xabsl2ErrorHandler& errorHandler,
00083     Xabsl2Array<Xabsl2State*>& states,
00084     Xabsl2Array<double>& parameters,
00085     Xabsl2Symbols& symbols,
00086     unsigned long& timeOfOptionExecution,
00087     unsigned long& timeOfStateExecution
00088     );
00089   
00090   /** Destructor. Deletes all statements and conditions */
00091   ~Xabsl2IfElseBlock();
00092   
00093   /** Executes the statement and determines the next active state (can be the same). */
00094   virtual Xabsl2State* getNextState();
00095   
00096 private:
00097   /** The boolean expression that is evaluated for the if case */
00098   Xabsl2BooleanExpression* ifCondition;
00099   
00100   /** The statement that is executed if the if condition is true */
00101   Xabsl2Statement* ifStatement;
00102   
00103   /** The boolean expressions for the else-if cases */
00104   Xabsl2Array<Xabsl2BooleanExpression*> elseIfConditions;
00105   
00106   /** The statements that are executed if the else-if condition are true */
00107   Xabsl2Array<Xabsl2Statement*> elseIfStatements;
00108   
00109   /** The statement that is executed if all if and else-if conditions fail */
00110   Xabsl2Statement* elseStatement;
00111 };
00112 
00113 
00114 /**
00115 * Represents a transition to a state inside a decision tree
00116 */
00117 class Xabsl2TransitionToState : public Xabsl2Statement
00118 {
00119 public:
00120 /** 
00121 * Constructor. Creates the transition object
00122 * @param input An input source for the intermediate code. It must be opened and read until 
00123 *              A position where a transition starts.
00124 * @param errorHandler A reference to a Xabsl2ErrorHandler instance
00125 * @param states All states of the option
00126   */
00127   Xabsl2TransitionToState(Xabsl2InputSource& input, 
00128     Xabsl2ErrorHandler& errorHandler,
00129     Xabsl2Array<Xabsl2State*>& states);
00130   
00131   /** Executes the statement and determines the next active state (can be the same). */
00132   virtual Xabsl2State* getNextState();
00133   
00134 private:
00135   /** The state where that transition points to */
00136   Xabsl2State* nextState;
00137 };
00138 
00139 // class prototype needed for declaration of Xabsl2State
00140 class Xabsl2Option;
00141 
00142 /**
00143 * @class Xabsl2State
00144 *
00145 * Represents a single state written in Xabsl2
00146 *
00147 * @author Martin Lötzsch
00148 */
00149 class Xabsl2State : public Xabsl2NamedItem
00150 {
00151 public:
00152 /** 
00153 * Constructor. Does not create the state.
00154 * @param name The name of the state. For debugging purposes.
00155 * @param errorHandler A reference to a Xabsl2ErrorHandler instance
00156 * @param pTimeFunction a pointer to a function that returns the system time in ms.
00157   */
00158   Xabsl2State(const char* name, 
00159     Xabsl2ErrorHandler& errorHandler,
00160     unsigned long (*pTimeFunction)());
00161   
00162   /** Destructor */
00163   ~Xabsl2State();
00164   
00165   /** 
00166   * Creates the state and it's subelements from the intermediate code.
00167   * @param input An input source for the intermediate code. It must be opened and read until 
00168   *              A position where a state starts.
00169   * @param options All available options
00170   * @param basicBehaviors All available basicBehaviors
00171   * @param states All states of the option
00172   * @param parameters The parameters of the option
00173   * @param symbols All available symbols
00174   * @param timeOfOptionExecution The time how long the option is already active
00175   */
00176   void create(Xabsl2InputSource& input,    
00177     Xabsl2Array<Xabsl2Option*>& options,
00178     Xabsl2Array<Xabsl2BasicBehavior&>& basicBehaviors,
00179     Xabsl2Array<Xabsl2State*>& states,
00180     Xabsl2Array<double>& parameters,
00181     Xabsl2Symbols& symbols,
00182     unsigned long& timeOfOptionExecution);
00183   
00184   /** 
00185   * Executes the decision tree and determines the next active state (can be the same). 
00186   */
00187   Xabsl2State* getNextState();
00188   
00189   /** Sets the output symbols of the state */
00190   void setOutputSymbols();
00191 
00192   /** 
00193   * The option that is executed after that option if the state is active. 
00194   * If 0, a basic behavior is executed after that option. 
00195   */
00196   Xabsl2Option* subsequentOption;  
00197   
00198   /** 
00199   * The basic behavior that is executed after that option if the state is active. 
00200   * If 0, an option is executed after that option. 
00201   */
00202   Xabsl2BasicBehavior* subsequentBasicBehavior;  
00203   
00204   /** the time how long the state is already active */
00205   unsigned long timeOfStateExecution;
00206   
00207   /** Sets the time when the state was activated to 0 */
00208   void reset();
00209 
00210   /** Pointers to the parameters of a subsequent basic behavior or a subsequent option */
00211   Xabsl2Array<double*> parametersOfSubsequentBehavior;
00212 
00213   /** Decimal expressions for the parameters of a subsequent basic behavior or a subsequent option */
00214   Xabsl2Array<Xabsl2DecimalExpression*> parameterValues;
00215 
00216   /** Returns wheter the state is a target state */
00217   bool isTargetState() const;
00218 
00219 private:
00220 
00221   /** The time, when the state was activated */
00222   unsigned long timeWhenStateWasActivated;
00223 
00224   /** If true, the state is a target state */
00225   bool targetState;
00226 
00227   /** Used for error handling */
00228   Xabsl2ErrorHandler& errorHandler;
00229   
00230   /** The root element of the decision tree */
00231   Xabsl2Statement* decisionTree;
00232 
00233   /** The output symbols that are set if the state is active */
00234   Xabsl2Array<Xabsl2EnumeratedOutputSymbol*> outputSymbols;
00235 
00236   /** The for the output symbols that are set if the state is active */
00237   Xabsl2Array<int> outputSymbolValues;
00238 
00239   /** A pointer to a function that returns the system time in ms. */
00240   unsigned long (*pTimeFunction)();
00241 };
00242 
00243 /** 
00244 * @class Xabsl2Option
00245 * 
00246 * Represents a single option written in Xabsl2
00247 * 
00248 * @author Martin Lötzsch
00249 */
00250 class Xabsl2Option : public Xabsl2NamedItem
00251 {
00252 public:
00253 /** 
00254 * Constructor. Does not create the option.
00255 * @param name The name of the option. For debugging purposes.
00256 * @param input An input source for the intermediate code. It must be opened and read until 
00257 *              A position where an option starts.
00258 * @param errorHandler A reference to a Xabsl2ErrorHandler instance
00259 * @param pTimeFunction a pointer to a function that returns the system time in ms.
00260   */
00261   Xabsl2Option(const char* name, Xabsl2InputSource& input,
00262     Xabsl2ErrorHandler& errorHandler,
00263     unsigned long (*pTimeFunction)());
00264   
00265   /** Destructor. Deletes the states */
00266   ~Xabsl2Option();
00267   
00268   /** 
00269   * Creates the option and it's states from the intermediate code.
00270   * @param input An input source for the intermediate code. It must be opened and read until 
00271   *              A position where an option starts.
00272   * @param options All other options
00273   * @param basicBehaviors All basic behaviors
00274   * @param symbols All available symbols
00275   */
00276   void create(Xabsl2InputSource& input,    
00277     Xabsl2Array<Xabsl2Option*>& options,
00278     Xabsl2Array<Xabsl2BasicBehavior&>& basicBehaviors,
00279     Xabsl2Symbols& symbols);
00280   
00281     /**
00282     * Executes the option. The state machine is carried out to determine the subsequent 
00283     * option or the subsequent basic behavior. Output symbols are set.
00284   */
00285   void execute();
00286   
00287   /** The parameters of the option */
00288   Xabsl2Array<double> parameters;
00289   
00290   /** The states of the option */
00291   Xabsl2Array<Xabsl2State*> states;
00292   
00293   /** A pointer to the active state. If 0, then no state is active */
00294   Xabsl2State* activeState;
00295   
00296   /** the option is activated in the current path through the option graph */
00297   bool optionIsActive;
00298   
00299   /** the option was activated in the last path trough the option graph */
00300   bool optionWasActive;
00301 
00302   /** the time how long the option is already active */
00303   unsigned long timeOfOptionExecution;
00304 
00305   /** Returns wheter the option reached a target state */
00306   bool getOptionReachedATargetState() const;
00307 
00308 private:
00309   /** The time, when the option was activated */
00310   unsigned long timeWhenOptionWasActivated;
00311 
00312   /** A pointer to the initial state */
00313   Xabsl2State* initialState;
00314   
00315   /** Used for error handling */
00316   Xabsl2ErrorHandler& errorHandler;
00317 
00318   /** A pointer to a function that returns the system time in ms. */
00319   unsigned long (*pTimeFunction)();
00320 };
00321 
00322 
00323 #endif //__Xabsl2Option_h_
00324 
00325 /*
00326 * Change Log:
00327 * 
00328 * $Log: Xabsl2Option.h,v $
00329 * Revision 1.1.1.1  2004/05/22 17:37:57  cvsadm
00330 * created new repository GT2004_WM
00331 *
00332 * Revision 1.2  2003/10/08 11:50:09  loetzsch
00333 * made the Xabsl2Engine really platform independent
00334 * (removed inclusion of Platform/SystemCall.h)
00335 * A time function is given to the engine by parameter.
00336 *
00337 * Revision 1.1  2003/10/07 10:13:25  cvsadm
00338 * Created GT2004 (M.J.)
00339 *
00340 * Revision 1.4  2003/09/30 10:51:11  dueffert
00341 * typos fixed
00342 *
00343 * Revision 1.3  2003/09/20 16:34:16  loetzsch
00344 * renamed "following-option-..." to "subsequent-option-.." and
00345 * "following-basic-behavior-.." to "subsequent-basic-behavior-.."
00346 * for consistency with publications
00347 *
00348 * Revision 1.2  2003/09/16 13:27:21  loetzsch
00349 * changed all occurrences of "option tree" to "option graph"
00350 *
00351 * Revision 1.1.1.1  2003/07/02 09:40:29  cvsadm
00352 * created new repository for the competitions in Padova from the 
00353 * tamara CVS (Tuesday 2:00 pm)
00354 *
00355 * removed unused solutions
00356 *
00357 * Revision 1.11  2003/05/05 17:47:55  loetzsch
00358 * added in Xabsl2:
00359 * - marking of states as target-states with attribute is-target-state="true"
00360 * - boolean expression "subsequent-option-reached-target-state"
00361 * - common-decision-tree
00362 *
00363 * Revision 1.10  2003/02/22 18:09:40  loetzsch
00364 * changed comments
00365 *
00366 * Revision 1.9  2003/01/15 01:19:45  timrie
00367 * corrected doxygen comments
00368 *
00369 * Revision 1.8  2003/01/14 16:28:32  loetzsch
00370 * creation of references to output symbols added
00371 * setting of output symbols added
00372 *
00373 * Revision 1.7  2003/01/13 22:39:38  loetzsch
00374 * implemented the execution of the engine.
00375 *
00376 * Revision 1.6  2003/01/13 13:18:18  loetzsch
00377 * Creation of boolean and decimal expressions finished.
00378 *
00379 * Revision 1.5  2003/01/12 14:54:04  loetzsch
00380 * continued creation of option tree: Xabsl2Statement and derivates added
00381 *
00382 * Revision 1.4  2003/01/11 14:41:42  loetzsch
00383 * continued creation of the option tree
00384 *
00385 * Revision 1.3  2003/01/09 17:28:33  loetzsch
00386 * introduced Xabsl2Agent, continued Xabsl2Option
00387 *
00388 * Revision 1.2  2003/01/08 18:47:17  loetzsch
00389 * first version of state implementation
00390 *
00391 * Revision 1.1  2003/01/08 15:22:33  loetzsch
00392 * - started implementation of the option tree
00393 * - started the reading of the intermediate code
00394 *
00395 */

Generated on Thu Sep 23 19:57:42 2004 for GT2004 by doxygen 1.3.6