cz.cuni.amis.pogamut.ut2004.agent.module.sensor
Class NavigationGraphBuilder

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.module.AgentModule<AGENT>
      extended by cz.cuni.amis.pogamut.base.agent.module.SensorModule<UT2004Bot>
          extended by cz.cuni.amis.pogamut.ut2004.agent.module.sensor.NavigationGraphBuilder
All Implemented Interfaces:
IComponent

public class NavigationGraphBuilder
extends SensorModule<UT2004Bot>

This class can be used to manually improve the navigation graph of the UT2004 by manually adding/removing edges from it.

Note that NavigationGraphBuilder is automatically prefixing all navpoint ids with "mapName.", which means, that you do not need to specify the id of navpoints as (e.g.) "DM-1on1-Albatross.PathNode2", "PathNode2" suffices. If you want to change this behavior call setAutoPrefix(boolean) with "false". Autoprefixing is good as it solves the problem with case-sensitivity of navpoint ids (i.e., you may run map dm-1on1-albatross as well as DM-1on1-Albatross!), it also makes the work faster as you do not have to repeat yourself.

Note that even if auto-prefixing enabled you may prefix ids of navpoints with map name, the auto-prefixing implemented by autoPrefix(String) will detects that and auto-correct upper/lower case of this existing prefix if needed. Also you may use it as a validation feature because the autoPrefix(String) will raise an exception if the prefix does not match the current map name.

As all SensorModule it should be initialized in IUT2004BotController.prepareBot(UT2004Bot). Note that UT2004BotModuleController has it auto-initialized inside UT2004BotModuleController.initializeModules(UT2004Bot).

Best utilized in IUT2004BotController.botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage) method.


Nested Class Summary
 class NavigationGraphBuilder.ExistingNavPointEdgeBuilder
           
 class NavigationGraphBuilder.ExistingNavPointModifier
          Builder that allows you to modify edges of existing navpoint using NavigationGraphBuilder.ExistingNavPointModifier.createEdge(), NavigationGraphBuilder.ExistingNavPointModifier.createEdgeTo(String), NavigationGraphBuilder.ExistingNavPointModifier.modifyEdgeTo(String) methods.
 class NavigationGraphBuilder.NewNavPointBuilder
          Builder encloses the creation of the new navpoint.
 class NavigationGraphBuilder.NewNavPointEdgeBuilder<OWNER>
          Represents the edge of the navpoint you're newly creating.
 
Field Summary
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.SensorModule
worldView
 
Fields inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
agent, controller, eventBus, log
 
Constructor Summary
NavigationGraphBuilder(UT2004Bot bot)
           
NavigationGraphBuilder(UT2004Bot bot, java.util.logging.Logger log)
           
NavigationGraphBuilder(UT2004Bot bot, java.util.logging.Logger log, ComponentDependencies dependencies)
           
 
Method Summary
 java.lang.String autoPrefix(java.lang.String navPointId)
          If isAutoPrefix() is on (== true), it returns 'navPointId' prefixed with "getMapName().".
protected  void cleanUp()
          Hook where to perform clean up of data structures of the module.
 void createSimpleEdge(java.lang.String fromNavPointId, java.lang.String toNavPointId)
          Creates simple (non-altered == no flags == no needed jump, etc.) leading 'fromNavPointId' to 'toNavPointId' (only one edge is created).
 void createSimpleEdgesBetween(java.lang.String firstNavPointId, java.lang.String secondNavPointId)
          Creates simple (non-altered == no flags == no needed jump, etc.) edges between specified navpoints (in both directions).
 java.lang.String getMapName()
          Returns name of the map the UT2004 is currently running.
 java.lang.String getPrefixed(java.lang.String navPointId)
          It returns 'navPointId' prefixed with "getMapName().".
 boolean isAutoPrefix()
          Whether NavigationGraphBuilder is auto prefixing all navpoint ids with current map name.
 boolean isMapName(java.lang.String name)
          Tells, whether the UT2004 is currently running map with name 'name'.
 boolean isUsed()
          Whether this instance has been used to alter navigation graph.
 NavigationGraphBuilder.ExistingNavPointModifier modifyNavPoint(java.lang.String navPointId)
          Creates a modifier for already existing NavPoint instance, if navpoint of specified id is not found, an exception is thrown.
 NavigationGraphBuilder.NewNavPointBuilder newNavPoint()
          Creates a builder for the specification of the new navpoint you want to create and insert into the worldview.
 NavigationGraphBuilder.NewNavPointBuilder newNavPoint(java.lang.String navPointId)
          Creates a builder for the specification of the new navpoint you want to create and insert into the worldview.
 void removeEdge(java.lang.String fromNavPointId, java.lang.String toNavPointId)
          Deletes edge that is leading from 'fromNavPointId' to 'toNavPointId'.
 void removeEdgesBetween(java.lang.String firstNavPointId, java.lang.String secondNavPointId)
          Removes both edges between two specified navpoints.
 void setAutoPrefix(boolean autoPrefix)
          Enables (== true), disables (== false) navpoint ids auto prefixing feature.
 void setUsed(boolean used)
          Raises / drops "used" flag, see isUsed().
 
Methods inherited from class cz.cuni.amis.pogamut.base.agent.module.AgentModule
getComponentId, getLog, getState, initComponentId, isRunning, kill, pause, reset, resume, start, stop, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NavigationGraphBuilder

public NavigationGraphBuilder(UT2004Bot bot)

NavigationGraphBuilder

public NavigationGraphBuilder(UT2004Bot bot,
                              java.util.logging.Logger log)

NavigationGraphBuilder

public NavigationGraphBuilder(UT2004Bot bot,
                              java.util.logging.Logger log,
                              ComponentDependencies dependencies)
Method Detail

cleanUp

protected void cleanUp()
Description copied from class: AgentModule
Hook where to perform clean up of data structures of the module.

Called from AgentModule.stop(), AgentModule.kill(), AgentModule.reset().

Overrides:
cleanUp in class AgentModule<UT2004Bot>

getMapName

public java.lang.String getMapName()
Returns name of the map the UT2004 is currently running.

The name is used as a prefix to all IDs in the game. IDs in the world view are case-sensitive!

Note that NavigationGraphBuilder is automatically prefixing all navpoint ids with "mapName.", which means, that you do not need to specify the id of navpoints as (e.g.) "DM-1on1-Albatross.PathNode2", "PathNode2" suffices. If you want to change this behavior call setAutoPrefix(boolean) with "false".

Returns:

isMapName

public boolean isMapName(java.lang.String name)
Tells, whether the UT2004 is currently running map with name 'name'.

Parameters:
name -
Returns:

isAutoPrefix

public boolean isAutoPrefix()
Whether NavigationGraphBuilder is auto prefixing all navpoint ids with current map name.

As default, auto-prefixing is enabled.

Note that even if auto-prefixing enabled you may prefix ids of navpoints with map name, the auto-prefixing implemented by autoPrefix(String) will detects that and auto-correct upper/lower case of this existing prefix if needed. Also you may use it as a validation feature because the autoPrefix(String) will raise an exception if the prefix does not match the current map name.

Returns:
whether auto-prefixing is enabled

setAutoPrefix

public void setAutoPrefix(boolean autoPrefix)
Enables (== true), disables (== false) navpoint ids auto prefixing feature.

As default, auto-prefixing is enabled.

Note that even if auto-prefixing enabled you may prefix ids of navpoints with map name, the auto-prefixing implemented by autoPrefix(String) will detects that and auto-correct upper/lower case of this existing prefix if needed. Also you may use it as a validation feature because the autoPrefix(String) will raise an exception if the prefix does not match the current map name.

Parameters:
autoPrefix -

getPrefixed

public java.lang.String getPrefixed(java.lang.String navPointId)
It returns 'navPointId' prefixed with "getMapName().".

Note that you may pass prefixed navPointId into this method, it will detect it that and auto-correct upper/lower case of this existing prefix if needed. Also you may use it as a validation feature because the autoPrefix(String) will raise an exception if the prefix does not match the current map name.

Parameters:
navPointId - will be auto-prefixed (if enabled, which is default)
Returns:

autoPrefix

public java.lang.String autoPrefix(java.lang.String navPointId)
If isAutoPrefix() is on (== true), it returns 'navPointId' prefixed with "getMapName().". Otherwise it just returns 'navPointId' as is.

Uses getPrefixed(String) for prefixing.

Parameters:
navPointId - will be auto-prefixed (if enabled, which is default)
Returns:

newNavPoint

public NavigationGraphBuilder.NewNavPointBuilder newNavPoint()
Creates a builder for the specification of the new navpoint you want to create and insert into the worldview.

Use NavigationGraphBuilder.NewNavPointBuilder.createNavPoint() when done specifying the navpoint.

Returns:
navpoint builder

newNavPoint

public NavigationGraphBuilder.NewNavPointBuilder newNavPoint(java.lang.String navPointId)
Creates a builder for the specification of the new navpoint you want to create and insert into the worldview. The builder will have the id of the navpoint filled (i.e., it calls NavigationGraphBuilder.NewNavPointBuilder.setId(String) for you.

Use NavigationGraphBuilder.NewNavPointBuilder.createNavPoint() when done specifying the navpoint.

Parameters:
navPointId - will be auto-prefixed (if enabled, which is default)
Returns:
navpoint builder

modifyNavPoint

public NavigationGraphBuilder.ExistingNavPointModifier modifyNavPoint(java.lang.String navPointId)
Creates a modifier for already existing NavPoint instance, if navpoint of specified id is not found, an exception is thrown.

The modifier allows you to change existing edges or add new ones.

Parameters:
navPointId - will be auto-prefixed (if enabled, which is default)
Returns:
navpoint modifier for the 'navPointId'

createSimpleEdge

public void createSimpleEdge(java.lang.String fromNavPointId,
                             java.lang.String toNavPointId)
Creates simple (non-altered == no flags == no needed jump, etc.) leading 'fromNavPointId' to 'toNavPointId' (only one edge is created).

If uses NavigationGraphBuilder.ExistingNavPointModifier.modifyEdgeTo(String) for creation of new edge, so it won't replace an existing edge if such exist.

Parameters:
fromNavPointId - will be auto-prefixed (if enabled, which is default)
toNavPointId - will be auto-prefixed (if enabled, which is default)

createSimpleEdgesBetween

public void createSimpleEdgesBetween(java.lang.String firstNavPointId,
                                     java.lang.String secondNavPointId)
Creates simple (non-altered == no flags == no needed jump, etc.) edges between specified navpoints (in both directions).

If uses NavigationGraphBuilder.ExistingNavPointModifier.modifyEdgeTo(String) for creation of new edge, so it won't replace an existing edge if such exist.

Parameters:
firstNavPointId - will be auto-prefixed (if enabled, which is default)
secondNavPointId - will be auto-prefixed (if enabled, which is default)

removeEdge

public void removeEdge(java.lang.String fromNavPointId,
                       java.lang.String toNavPointId)
Deletes edge that is leading from 'fromNavPointId' to 'toNavPointId'.

Parameters:
fromNavPointId - will be auto-prefixed (if enabled, which is default)
toNavPointId - will be auto-prefixed (if enabled, which is default)

removeEdgesBetween

public void removeEdgesBetween(java.lang.String firstNavPointId,
                               java.lang.String secondNavPointId)
Removes both edges between two specified navpoints.

Parameters:
firstNavPointId - will be auto-prefixed (if enabled, which is default)
secondNavPointId - will be auto-prefixed (if enabled, which is default)

isUsed

public boolean isUsed()
Whether this instance has been used to alter navigation graph. This might interest you in case you're using FloydWarshallMap as you will need to FloydWarshallMap.refreshPathMatrix() after all changes done to the navigation graph.

Returns:

setUsed

public void setUsed(boolean used)
Raises / drops "used" flag, see isUsed().

Parameters:
used -