cz.cuni.amis.pogamut.sposh.usar2004
Class SposhLogicController<BOT extends cz.cuni.amis.pogamut.usar2004.agent.USAR2004Bot,WORK_EXECUTOR extends IWorkExecutor>

Package class diagram package SposhLogicController
java.lang.Object
  extended by cz.cuni.amis.pogamut.usar2004.agent.USAR2004BotController<BOT>
      extended by cz.cuni.amis.pogamut.usar2004.agent.module.logic.USAR2004BotLogicController<BOT>
          extended by cz.cuni.amis.pogamut.sposh.usar2004.SposhLogicController<BOT,WORK_EXECUTOR>
All Implemented Interfaces:
cz.cuni.amis.pogamut.base.agent.module.IAgentLogic<cz.cuni.amis.pogamut.base.agent.module.LogicModule>, cz.cuni.amis.pogamut.usar2004.agent.IUSAR2004BotController<BOT>, cz.cuni.amis.pogamut.usar2004.agent.module.logic.IUSAR2004BotLogicController<BOT,cz.cuni.amis.pogamut.base.agent.module.LogicModule>
Direct Known Subclasses:
StateSposhLogicController

public abstract class SposhLogicController<BOT extends cz.cuni.amis.pogamut.usar2004.agent.USAR2004Bot,WORK_EXECUTOR extends IWorkExecutor>
extends cz.cuni.amis.pogamut.usar2004.agent.module.logic.USAR2004BotLogicController<BOT>

Logic controller that utilizes sposh engine for decision making of bot in UT2004 environment.

Sposh requires two things: plan and primitives. The plan is provided by getPlan() method and are supplied by IWorkExecutor. IWorkExecutor is instantiated during first call of logic, so if the varioud modules are already initialized.

If needed, override createTimer(), but it shouldn't be needed.

Author:
Honza H.

Field Summary
static String SPOSH_LOG_CATEGORY
           
 
Fields inherited from class cz.cuni.amis.pogamut.usar2004.agent.module.logic.USAR2004BotLogicController
logicModule
 
Fields inherited from class cz.cuni.amis.pogamut.usar2004.agent.USAR2004BotController
bot, log, user, USER_LOG_CATEGORY_ID
 
Constructor Summary
SposhLogicController()
           
 
Method Summary
protected  ITimer createTimer()
          Create timer for posh engine.
protected abstract  WORK_EXECUTOR createWorkExecutor()
          Create IWorkExecutor that will execute primitives contained in the plan.
protected  PoshEngine getEngine()
          Get sposh engine for this logic
protected abstract  String getPlan()
          Get the POSH plan for the bot.
protected  String getPlanFromFile(String filename)
          Read POSH plan from the file and return it.
protected  String getPlanFromResource(String resourcePath)
          Get POSh plan from resource int the same jar as the class.
protected  String getPlanFromStream(InputStream in)
          Read POSH plan from the stream and return it.
protected  ITimer getTimer()
          Get timer that is used by posh engine to make sure timeouts and other stuff that requires time are working properly.
protected  WORK_EXECUTOR getWorkExecutor()
          Get work executor.
 void initializeController(BOT bot)
           
 void logic()
          Logic method evaluates the posh plan every time it is called.
protected  void logicAfterPlan()
          Method that is triggered every time the plan for executor is evaluated.
protected  void logicBeforePlan()
          Method that is triggered every time the plan for executor is evaluated.
 
Methods inherited from class cz.cuni.amis.pogamut.usar2004.agent.module.logic.USAR2004BotLogicController
beforeFirstLogic, getLogicInitializeTime, getLogicShutdownTime, logicInitialize, logicShutdown
 
Methods inherited from class cz.cuni.amis.pogamut.usar2004.agent.USAR2004BotController
getAct, getLog, getWorldView, prepareBot, robotInitialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.pogamut.usar2004.agent.IUSAR2004BotController
prepareBot, robotInitialized
 

Field Detail

SPOSH_LOG_CATEGORY

public static final String SPOSH_LOG_CATEGORY
See Also:
Constant Field Values
Constructor Detail

SposhLogicController

public SposhLogicController()
Method Detail

initializeController

public void initializeController(BOT bot)
Specified by:
initializeController in interface cz.cuni.amis.pogamut.usar2004.agent.IUSAR2004BotController<BOT extends cz.cuni.amis.pogamut.usar2004.agent.USAR2004Bot>
Overrides:
initializeController in class cz.cuni.amis.pogamut.usar2004.agent.module.logic.USAR2004BotLogicController<BOT extends cz.cuni.amis.pogamut.usar2004.agent.USAR2004Bot>

createWorkExecutor

protected abstract WORK_EXECUTOR createWorkExecutor()
Create IWorkExecutor that will execute primitives contained in the plan. This method will be called only once.

Returns:
executor to execute primitives.

getWorkExecutor

protected final WORK_EXECUTOR getWorkExecutor()
Get work executor. If work executor is not yet created, create one using createWorkExecutor().

Returns:
work executor for this bot controller.

logic

public final void logic()
Logic method evaluates the posh plan every time it is called.

Specified by:
logic in interface cz.cuni.amis.pogamut.base.agent.module.IAgentLogic<cz.cuni.amis.pogamut.base.agent.module.LogicModule>
Overrides:
logic in class cz.cuni.amis.pogamut.usar2004.agent.module.logic.USAR2004BotLogicController<BOT extends cz.cuni.amis.pogamut.usar2004.agent.USAR2004Bot>

logicBeforePlan

protected void logicBeforePlan()
Method that is triggered every time the plan for executor is evaluated. It is triggered right before the plan evaluation. Currently, it checks if workExecutor is a ILogicWorkExecutor and if it is, it executes ILogicWorkExecutor.logicBeforePlan().


logicAfterPlan

protected void logicAfterPlan()
Method that is triggered every time the plan for executor is evaluated. It is triggered right after the plan evaluation. Currently, it checks if workExecutor is a ILogicWorkExecutor and if it is, it executes ILogicWorkExecutor.logicBeforePlan().


createTimer

protected ITimer createTimer()
Create timer for posh engine. By default, use SystemClockTimer.

Returns:
See Also:
getTimer()

getTimer

protected final ITimer getTimer()
Get timer that is used by posh engine to make sure timeouts and other stuff that requires time are working properly.

Returns:

getEngine

protected final PoshEngine getEngine()
Get sposh engine for this logic

Returns:
null if engine wasn't yet created(is created in SposhLogicController#initializeController(UT2004Bot) ) or the engine.

getPlan

protected abstract String getPlan()
                           throws IOException
Get the POSH plan for the bot. Easiest way is to use getPlanFromResource, getPlanFromFile or getPlanFromStream.

Returns:
Text of the whole plan
Throws:
IOException

getPlanFromStream

protected final String getPlanFromStream(InputStream in)
                                  throws IOException
Read POSH plan from the stream and return it. Close the stream.

Parameters:
in - Input stream from which the plan is going to be read
Returns:
Text of the plan, basically content of the stream
Throws:
IOException - If there is some error while reading the stream

getPlanFromFile

protected final String getPlanFromFile(String filename)
                                throws IOException
Read POSH plan from the file and return it.

Parameters:
filename - Path to the file that contains the POSH plan.
Returns:
Text of the plan, basically content of the file
Throws:
IOException - If there is some error while reading the stream

getPlanFromResource

protected final String getPlanFromResource(String resourcePath)
                                    throws IOException
Get POSh plan from resource int the same jar as the class.

  // Plan is stored in package cz.cuni.amis.pogamut.testbot under name poshPlan.lap
  // This can get the file from .jar or package structure
  getPlanFromResource("cz/cuni/amis/pogamut/testbot/poshPlan.lap");
 

Parameters:
resourcePath - Path to the plan in some package
Returns:
Content of the plan.
Throws:
IOException - if something goes wrong, like file is missing, hardisk has blown up ect.


Copyright © 2014 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.