/** *
* Control function implementing "move in a direction" *
* @author Michael Schuresko * @version %I%, %G% * @since 1.0 */ public class ControlFuncMoveDir implements IControlFunc { double [] m_arrDir; public ControlFuncMoveDir() { m_arrDir = null; } public ControlFuncMoveDir(ControlFuncMoveDir src) { setVel(src.m_arrDir); } public ControlFuncMoveDir(double lfX, double lfY) { m_arrDir = new double[2]; m_arrDir[0] = lfX; m_arrDir[1] = lfY; } public ControlFuncMoveDir(double [] arrPtTowards) { setVel(arrPtTowards); } public boolean directionConstantQ(double lfCurrTime, double arrLfStateSrc[], ISensor sensors, IEnvironment env, ILogicVarBundle logicVars, int nIdxOffsetState) { return true; } /** * sets a new point to move towards, possibly re-assigning * control function dimension (some care must be taken by programmer * here) */ public void setVel(double [] arrVel) { if(m_arrDir == null || m_arrDir.length != arrVel.length) { m_arrDir = new double[arrVel.length]; } for(int i = 0; i < arrVel.length; ++i) { m_arrDir[i] = arrVel[i]; } } public double [] getVel() { return m_arrDir; } public double [] getVelCopy() { if(m_arrDir == null) { return null; } double [] arrLfRes = new double[m_arrDir.length]; for(int i = 0; i < m_arrDir.length; ++i) { arrLfRes[i] = m_arrDir[i]; } return arrLfRes; } /** * clones this object (similar to "clone" supported by IClonable * interface). */ public IControlFunc makeCopy() { return new ControlFuncMoveDir(this); } /** ** Updates arrLfDerivDst with the instantaneous derivatives * of the continuous-time component of the agent's state * given its current state and sensor readings *
* @param lfCurrTime current time (for time-varying systems) * @param arrLfStateSrc vector of global state of the system * @param sensors sensors * @param env environment * @param logicVars discrete components of agent internal state * @param arrLfDerivDst Destination for storing derivative values. * @param nIdxOff Offset index into the global state vector * corresponding to the beginning of the parameters for this agent. * @since 1.0 */ public void getDerivs(double lfCurrTime, double arrLfStateSrc[], ISensor sensors, IEnvironment env, ILogicVarBundle logicVars, double arrLfDerivDst[], int nIdxOff) { for(int i = 0; i < m_arrDir.length; ++i) { arrLfDerivDst[nIdxOff+i] = m_arrDir[i]; } } /** * returns dimensionality of the state vector corresponding to one agent * @return dimensionality of the state vector corresponding to one agent */ public int getNumStateVars() { if(m_arrDir == null) { return 0; } return m_arrDir.length; } }