>xabsl   The Extensible Agent Behavior Specification Language

XabslEngine Class Library Reference

 

xabsl::Engine Class Reference

#include <XabslEngine.h>

Inheritance diagram for xabsl::Engine:

Inheritance graph
[legend]
Collaboration diagram for xabsl::Engine:

Collaboration graph
[legend]
List of all members.

Detailed Description

Executes a behavior that was specified in the Xabsl language.

Author:
Martin Loetzsch

Max Risler

Matthias JŸngel

Definition at line 29 of file XabslEngine.h.


Public Member Functions

 Engine (ErrorHandler &e, unsigned(*pTimeFunction)())
 Constructor.

 ~Engine ()
 Destructor.

void execute ()
 Executes the engine for the selected agent starting from the root option.

void createOptionGraph (InputSource &input)
 Reads the intermediate code from an input source and creates the option graph.

void registerBasicBehavior (BasicBehavior &basicBehavior)
 Registers a basic behavior at the engine.

bool setSelectedAgent (const char *name)
 Sets the selected Agent.

void reset ()
 Resets all active options.

Debugging Interface
const NamedArray< Agent * > & getAgents () const
 Returns the agents of the engine.

const NamedArray< Option * > & getOptions () const
 Return the options of the engine.

const NamedArray< BasicBehavior * > & getBasicBehaviors () const
 Returns the registered basic behaviors of the engine.

void clearRootActions ()
 Clears the list of actions executed starting the option graph.

bool addRootAction (const char *name, bool isOption=true)
 Adds a given option or basic behavior to the list of actions executed starting the option graph.

bool setRootAction (const char *name, bool isOption=true)
 Executes the option graph starting from a given option or basic behavior.

void setRootAction ()
 Sets the root option of the selected agent.

void addRootAction (Behavior *behavior)
 Adds the specified option or basic behavior to the list of root actions.

bool addRootActionDecimalOutputSymbol (const char *name, double value)
 Adds a decimal output symbol assignment to the list of root actions.

bool addRootActionBooleanOutputSymbol (const char *name, bool value)
 Adds a boolean output symbol assignment to the list of root actions.

bool addRootActionEnumeratedOutputSymbol (const char *name, const char *value)
 Adds an enumerated output symbol assignment to the list of root actions.

void setRootAction (Behavior *behavior)
 Sets the root option to the specified option or basic behavior.

const ActiongetRootAction (int i) const
 Returns the selected root actions.

ActiongetRootAction (int i)
 Returns the selected root actions.

const Array< Action * > & getRootActions () const
 Returns the selected root actions.

Array< Action * > & getRootActions ()
 Returns the selected root actions.

const char * getSelectedAgentName () const
 Returns the name of the selected agent.

void prepareIncomingMessages ()
 Prepare for processing incoming team messages.

void processIncomingMessage (const TeamMessage &message)
 Process an incoming team message from another agent.

void generateOutgoingMessage (TeamMessage &message)
 Generate the outgoing team message to be sent to other agents.

void setSynchronizationTicks (int ticks)
 Set the number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received.

void setAgentPriority (int priority)
 Sets the priority value of the agent, used for solving conflicts in cooperative state assignment.


Private Member Functions

bool checkForLoops (Option *currentOption, ActionBehavior *currentOptionTree[], int currentLength, int maxSize)
 A recursive function that is used to check for loops in the option graph.

void addActions (ActionBehavior *actionToAdd, ActionBehavior *currentOptionTree[], int &currentLength, int maxSize)
 A recursive function that generates a list of actions referenced from a starting option This is used by checkForLoops.

int countActions (Option *option)
 Rescursively count the number of actions referenced from an option.


Private Attributes

unsigned timeOfExecutionStart
 The time of the start of the current engine execution.

NamedArray< Agent * > agents
 The agents of the engine.

AgentselectedAgent
 The selected agent.

NamedArray< Option * > options
 The options of the engine.

Array< Action * > rootActions
 The actions for the execution of the start of the option graph.

NamedArray< BasicBehavior * > basicBehaviors
 The registered basic behaviors of the engine.

ErrorHandlererrorHandler
 Is invoked when there are problems during initialization.

bool initialized
 If true, the engine was successfully initialized.

unsigned(* pTimeFunction )()
 A pointer to a function that returns the system time in ms.

NamedArray< double > internalDecimalSymbols
 Arrays containing internal symbol values.

NamedArray< bool > internalBooleanSymbols
NamedArray< int > internalEnumeratedSymbols
Array< CoopState * > coopStates
 Array of states which are used for cooperating agents.

int agentPriority
 Priority value of the agent, used for solving conflicts in cooperative state assignment.

int synchronizationTicks
 Number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received.


Constructor & Destructor Documentation

xabsl::Engine::Engine ErrorHandler e,
unsigned(*  pTimeFunction)()
 

Constructor.

Parameters:
e Is invoked when there are problems during initialization
pTimeFunction a pointer to a function that returns the system time in ms.

Definition at line 16 of file XabslEngine.cpp.

xabsl::Engine::~Engine  ) 
 

Destructor.

Definition at line 25 of file XabslEngine.cpp.

References agents, xabsl::Array< Action * >::getSize(), xabsl::Array< NamedArrayElement< Agent * > * >::getSize(), xabsl::Array< NamedArrayElement< Option * > * >::getSize(), options, and rootActions.

Here is the call graph for this function:


Member Function Documentation

void xabsl::Engine::execute  ) 
 

Executes the engine for the selected agent starting from the root option.

(Including the selected basic behavior)

Definition at line 39 of file XabslEngine.cpp.

References basicBehaviors, xabsl::ErrorHandler::error(), xabsl::Array< NamedArrayElement< BasicBehavior * > * >::getSize(), xabsl::Array< NamedArrayElement< Option * > * >::getSize(), xabsl::Array< Action * >::getSize(), initialized, options, pTimeFunction, xabsl::Symbols::resetOutputSymbols(), rootActions, and timeOfExecutionStart.

Here is the call graph for this function:

void xabsl::Engine::createOptionGraph InputSource input  ) 
 

Reads the intermediate code from an input source and creates the option graph.

Note that the basic behaviors and symbols have to be registered before that function is called.

Definition at line 66 of file XabslEngine.cpp.

References agents, xabsl::Array< CoopState * >::append(), xabsl::NamedArray< Agent * >::append(), xabsl::NamedArray< Option * >::append(), xabsl::NamedArray< int >::append(), xabsl::NamedArray< bool >::append(), xabsl::NamedArray< double >::append(), basicBehaviors, checkForLoops(), xabsl::InputSource::close(), coopStates, countActions(), xabsl::Enumeration::enumElements, xabsl::ErrorHandler::error(), xabsl::ErrorHandler::errorsOccurred, xabsl::NamedArray< Enumeration * >::exists(), xabsl::NamedArray< int >::getElement(), xabsl::NamedArray< bool >::getElement(), xabsl::NamedArray< double >::getElement(), xabsl::Array< NamedArrayElement< Option * > * >::getSize(), xabsl::Array< NamedArrayElement< Agent * > * >::getSize(), xabsl::Array< NamedArrayElement< int > * >::getSize(), xabsl::Array< NamedArrayElement< EnumElement * > * >::getSize(), xabsl::Array< NamedArrayElement< bool > * >::getSize(), xabsl::Array< NamedArrayElement< double > * >::getSize(), initialized, internalBooleanSymbols, internalDecimalSymbols, internalEnumeratedSymbols, xabsl::ErrorHandler::message(), xabsl::NamedItem::n, xabsl::InputSource::open(), options, pTimeFunction, xabsl::InputSource::readString(), xabsl::InputSource::readValue(), xabsl::Symbols::registerBooleanOutputSymbol(), xabsl::Symbols::registerDecimalOutputSymbol(), xabsl::Symbols::registerEnumElement(), xabsl::Symbols::registerEnumeratedOutputSymbol(), selectedAgent, setRootAction(), timeOfExecutionStart, and XABSL_DEBUG_INIT.

Here is the call graph for this function:

void xabsl::Engine::registerBasicBehavior BasicBehavior basicBehavior  ) 
 

Registers a basic behavior at the engine.

This must be done before the intermediate code is read.

Parameters:
basicBehavior A reference to the basic behavior

Definition at line 340 of file XabslEngine.cpp.

References xabsl::NamedArray< BasicBehavior * >::append(), basicBehaviors, xabsl::ErrorHandler::error(), xabsl::NamedArray< BasicBehavior * >::exists(), xabsl::Array< NamedArrayElement< BasicBehavior * > * >::getSize(), xabsl::BasicBehavior::index, xabsl::ErrorHandler::message(), xabsl::NamedItem::n, xabsl::Behavior::parameters, xabsl::Parameters::registerEnumerations(), xabsl::BasicBehavior::registerParameters(), and XABSL_DEBUG_INIT.

Here is the call graph for this function:

bool xabsl::Engine::setSelectedAgent const char *  name  ) 
 

Sets the selected Agent.

If the last selected agent was different from the new one, the root option is changed depending on the new agent.

Parameters:
name The name of the agent
Returns:
if the requested agent exists

Definition at line 471 of file XabslEngine.cpp.

References agents, xabsl::NamedArray< Agent * >::exists(), selectedAgent, and setRootAction().

Here is the call graph for this function:

void xabsl::Engine::reset  ) 
 

Resets all active options.

Next cycle will execute initial state of currently set root option.

Definition at line 489 of file XabslEngine.cpp.

References basicBehaviors, xabsl::ErrorHandler::errorsOccurred, xabsl::Array< NamedArrayElement< BasicBehavior * > * >::getSize(), xabsl::Array< NamedArrayElement< Option * > * >::getSize(), and options.

Here is the call graph for this function:

bool xabsl::Engine::checkForLoops Option currentOption,
ActionBehavior currentOptionTree[],
int  currentLength,
int  maxSize
[private]
 

A recursive function that is used to check for loops in the option graph.

Parameters:
currentOption The option to be checked
currentOptionTree An array of the currently traced option tree
currentLength The length of the current option tree array
maxSize maximum allowed size of the array
Returns:
If true, then a loop was detected.

Definition at line 228 of file XabslEngine.cpp.

References addActions(), xabsl::ErrorHandler::error(), xabsl::ActionBehavior::getBehavior(), xabsl::Array< NamedArrayElement< State * > * >::getSize(), xabsl::NamedItem::n, xabsl::ActionOption::option, and xabsl::Option::states.

Referenced by createOptionGraph().

Here is the call graph for this function:

void xabsl::Engine::addActions ActionBehavior actionToAdd,
ActionBehavior currentOptionTree[],
int &  currentLength,
int  maxSize
[private]
 

A recursive function that generates a list of actions referenced from a starting option This is used by checkForLoops.

Parameters:
actionToAdd The option whose referenced actions are to be added to the current array
currentOptionTree An array to which the referenced options are to be added
currentLength The current length of the array. Actions will be appended at the end of the array. currentLength will increase accordingly.
maxSize maximum allowed size of the array

Definition at line 292 of file XabslEngine.cpp.

References xabsl::ErrorHandler::error(), xabsl::Array< NamedArrayElement< State * > * >::getSize(), xabsl::NamedItem::n, xabsl::ActionOption::option, and xabsl::Option::states.

Referenced by checkForLoops().

Here is the call graph for this function:

int xabsl::Engine::countActions Option option  )  [private]
 

Rescursively count the number of actions referenced from an option.

Parameters:
option A pointer to the option for which the referenced options are counted.
Returns:
Number of actions

Definition at line 319 of file XabslEngine.cpp.

References xabsl::Array< NamedArrayElement< State * > * >::getSize(), xabsl::ActionOption::option, and xabsl::Option::states.

Referenced by createOptionGraph().

Here is the call graph for this function:

const NamedArray<Agent*>& xabsl::Engine::getAgents  )  const [inline]
 

Returns the agents of the engine.

Definition at line 152 of file XabslEngine.h.

References agents.

const NamedArray<Option*>& xabsl::Engine::getOptions  )  const [inline]
 

Return the options of the engine.

Definition at line 155 of file XabslEngine.h.

References options.

const NamedArray<BasicBehavior*>& xabsl::Engine::getBasicBehaviors  )  const [inline]
 

Returns the registered basic behaviors of the engine.

Definition at line 158 of file XabslEngine.h.

References basicBehaviors.

void xabsl::Engine::clearRootActions  ) 
 

Clears the list of actions executed starting the option graph.

Definition at line 357 of file XabslEngine.cpp.

References xabsl::Array< Action * >::clear(), xabsl::Array< Action * >::getSize(), and rootActions.

Referenced by setRootAction().

Here is the call graph for this function:

bool xabsl::Engine::addRootAction const char *  name,
bool  isOption = true
 

Adds a given option or basic behavior to the list of actions executed starting the option graph.

Can be called to test a single option or basic behavior.

Parameters:
name The name of the option or basic behavior
isOption True for an option, false for a basic behavior
Returns:
When false, the option is not known to the engine

Definition at line 365 of file XabslEngine.cpp.

References basicBehaviors, xabsl::NamedArray< BasicBehavior * >::exists(), xabsl::NamedArray< Option * >::exists(), and options.

Referenced by setRootAction().

Here is the call graph for this function:

bool xabsl::Engine::setRootAction const char *  name,
bool  isOption = true
 

Executes the option graph starting from a given option or basic behavior.

Can be called to test a single option or basic behavior.

Parameters:
name The name of the option or basic behavior
isOption True for an option, false for a basic behavior
Returns:
When false, the option is not known to the engine

Definition at line 387 of file XabslEngine.cpp.

References addRootAction(), and clearRootActions().

Here is the call graph for this function:

void xabsl::Engine::setRootAction  ) 
 

Sets the root option of the selected agent.

Definition at line 393 of file XabslEngine.cpp.

References xabsl::Agent::getRootOption(), and selectedAgent.

Referenced by createOptionGraph(), and setSelectedAgent().

Here is the call graph for this function:

void xabsl::Engine::addRootAction Behavior behavior  ) 
 

Adds the specified option or basic behavior to the list of root actions.

Definition at line 398 of file XabslEngine.cpp.

References xabsl::Array< Action * >::append(), rootActions, and timeOfExecutionStart.

Here is the call graph for this function:

bool xabsl::Engine::addRootActionDecimalOutputSymbol const char *  name,
double  value
 

Adds a decimal output symbol assignment to the list of root actions.

Definition at line 409 of file XabslEngine.cpp.

References xabsl::Array< Action * >::append(), xabsl::ActionDecimalOutputSymbol::decimalOutputSymbol, xabsl::ActionDecimalOutputSymbol::decimalOutputSymbolExpression, xabsl::NamedArray< DecimalOutputSymbol * >::exists(), rootActions, and timeOfExecutionStart.

Here is the call graph for this function:

bool xabsl::Engine::addRootActionBooleanOutputSymbol const char *  name,
bool  value
 

Adds a boolean output symbol assignment to the list of root actions.

Definition at line 420 of file XabslEngine.cpp.

References xabsl::Array< Action * >::append(), xabsl::ActionBooleanOutputSymbol::booleanOutputSymbol, xabsl::ActionBooleanOutputSymbol::booleanOutputSymbolExpression, xabsl::NamedArray< BooleanOutputSymbol * >::exists(), rootActions, and timeOfExecutionStart.

Here is the call graph for this function:

bool xabsl::Engine::addRootActionEnumeratedOutputSymbol const char *  name,
const char *  value
 

Adds an enumerated output symbol assignment to the list of root actions.

Definition at line 431 of file XabslEngine.cpp.

References xabsl::Array< Action * >::append(), xabsl::ActionEnumeratedOutputSymbol::enumeratedOutputSymbol, xabsl::ActionEnumeratedOutputSymbol::enumeratedOutputSymbolExpression, xabsl::NamedArray< EnumeratedOutputSymbol * >::exists(), rootActions, and timeOfExecutionStart.

Here is the call graph for this function:

void xabsl::Engine::setRootAction Behavior behavior  ) 
 

Sets the root option to the specified option or basic behavior.

Definition at line 403 of file XabslEngine.cpp.

References addRootAction(), and clearRootActions().

Here is the call graph for this function:

const Action * xabsl::Engine::getRootAction int  i  )  const
 

Returns the selected root actions.

Definition at line 443 of file XabslEngine.cpp.

References rootActions.

Action * xabsl::Engine::getRootAction int  i  ) 
 

Returns the selected root actions.

Definition at line 448 of file XabslEngine.cpp.

References rootActions.

const Array< Action * > & xabsl::Engine::getRootActions  )  const
 

Returns the selected root actions.

Definition at line 453 of file XabslEngine.cpp.

References rootActions.

Array< Action * > & xabsl::Engine::getRootActions  ) 
 

Returns the selected root actions.

Definition at line 458 of file XabslEngine.cpp.

References rootActions.

const char * xabsl::Engine::getSelectedAgentName  )  const
 

Returns the name of the selected agent.

Definition at line 463 of file XabslEngine.cpp.

References xabsl::NamedItem::n, and selectedAgent.

void xabsl::Engine::prepareIncomingMessages  ) 
 

Prepare for processing incoming team messages.

This resets previously processed messages.

Definition at line 503 of file XabslEngine.cpp.

References coopStates, and xabsl::Array< CoopState * >::getSize().

Here is the call graph for this function:

void xabsl::Engine::processIncomingMessage const TeamMessage message  ) 
 

Process an incoming team message from another agent.

Definition at line 511 of file XabslEngine.cpp.

References xabsl::TeamMessage::agentPriority, coopStates, xabsl::TeamMessage::coopStatesEntering, xabsl::TeamMessage::coopStatesExecuted, xabsl::TeamMessage::coopStatesOptionExecuted, and xabsl::Array< int >::getSize().

Here is the call graph for this function:

void xabsl::Engine::generateOutgoingMessage TeamMessage message  ) 
 

Generate the outgoing team message to be sent to other agents.

Definition at line 528 of file XabslEngine.cpp.

References xabsl::TeamMessage::agentPriority, xabsl::Array< int >::append(), coopStates, xabsl::TeamMessage::coopStatesEntering, xabsl::TeamMessage::coopStatesExecuted, xabsl::TeamMessage::coopStatesOptionExecuted, xabsl::Array< CoopState * >::getSize(), options, and xabsl::TeamMessage::reset().

Here is the call graph for this function:

void xabsl::Engine::setSynchronizationTicks int  ticks  )  [inline]
 

Set the number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received.

Definition at line 238 of file XabslEngine.h.

void xabsl::Engine::setAgentPriority int  priority  )  [inline]
 

Sets the priority value of the agent, used for solving conflicts in cooperative state assignment.

Definition at line 241 of file XabslEngine.h.


Member Data Documentation

unsigned xabsl::Engine::timeOfExecutionStart [private]
 

The time of the start of the current engine execution.

Definition at line 82 of file XabslEngine.h.

Referenced by addRootAction(), addRootActionBooleanOutputSymbol(), addRootActionDecimalOutputSymbol(), addRootActionEnumeratedOutputSymbol(), createOptionGraph(), and execute().

NamedArray<Agent*> xabsl::Engine::agents [private]
 

The agents of the engine.

Definition at line 85 of file XabslEngine.h.

Referenced by createOptionGraph(), getAgents(), setSelectedAgent(), and ~Engine().

Agent* xabsl::Engine::selectedAgent [private]
 

The selected agent.

Definition at line 88 of file XabslEngine.h.

Referenced by createOptionGraph(), getSelectedAgentName(), setRootAction(), and setSelectedAgent().

NamedArray<Option*> xabsl::Engine::options [private]
 

The options of the engine.

Definition at line 91 of file XabslEngine.h.

Referenced by addRootAction(), createOptionGraph(), execute(), generateOutgoingMessage(), getOptions(), reset(), and ~Engine().

Array<Action*> xabsl::Engine::rootActions [private]
 

The actions for the execution of the start of the option graph.

Definition at line 94 of file XabslEngine.h.

Referenced by addRootAction(), addRootActionBooleanOutputSymbol(), addRootActionDecimalOutputSymbol(), addRootActionEnumeratedOutputSymbol(), clearRootActions(), execute(), getRootAction(), getRootActions(), and ~Engine().

NamedArray<BasicBehavior*> xabsl::Engine::basicBehaviors [private]
 

The registered basic behaviors of the engine.

Definition at line 97 of file XabslEngine.h.

Referenced by addRootAction(), createOptionGraph(), execute(), getBasicBehaviors(), registerBasicBehavior(), and reset().

ErrorHandler& xabsl::Engine::errorHandler [private]
 

Is invoked when there are problems during initialization.

Reimplemented from xabsl::Symbols.

Definition at line 100 of file XabslEngine.h.

bool xabsl::Engine::initialized [private]
 

If true, the engine was successfully initialized.

Definition at line 128 of file XabslEngine.h.

Referenced by createOptionGraph(), and execute().

unsigned(* xabsl::Engine::pTimeFunction)() [private]
 

A pointer to a function that returns the system time in ms.

Referenced by createOptionGraph(), and execute().

NamedArray<double> xabsl::Engine::internalDecimalSymbols [private]
 

Arrays containing internal symbol values.

Definition at line 134 of file XabslEngine.h.

Referenced by createOptionGraph().

NamedArray<bool> xabsl::Engine::internalBooleanSymbols [private]
 

Definition at line 135 of file XabslEngine.h.

Referenced by createOptionGraph().

NamedArray<int> xabsl::Engine::internalEnumeratedSymbols [private]
 

Definition at line 136 of file XabslEngine.h.

Referenced by createOptionGraph().

Array<CoopState*> xabsl::Engine::coopStates [private]
 

Array of states which are used for cooperating agents.

Definition at line 139 of file XabslEngine.h.

Referenced by createOptionGraph(), generateOutgoingMessage(), prepareIncomingMessages(), and processIncomingMessage().

int xabsl::Engine::agentPriority [private]
 

Priority value of the agent, used for solving conflicts in cooperative state assignment.

Definition at line 142 of file XabslEngine.h.

int xabsl::Engine::synchronizationTicks [private]
 

Number of execution cycles that is required for synchonization with other agents, i.e time from sending a message until answer is received.

Definition at line 145 of file XabslEngine.h.


The documentation for this class was generated from the following files:

Up | Main Page | Generated at Wed Aug 19 17:32:30 2009.