/** * Class for storing a snapshot of the global state of the swarm. * Useful for passing data between simulation and rendering threads. * Also useful for serializing agent behavior for later analysis. * @author Michael Schuresko * @version %I%, %G% * @since 1.0 */ public class SwarmState { double [] m_arrLfPositions; StateBundle [] m_arrStates; IAgent m_agent; double m_lfTime; CommGraph m_commGraph; public double [] accessPositions() { return m_arrLfPositions; } public StateBundle [] accessStates() { return m_arrStates; } public IAgent accessAgent() { return m_agent; } public double getTime() { return m_lfTime; } public CommGraph getGraph() { return m_commGraph; } protected SwarmState() { m_commGraph = null; m_arrLfPositions = null; m_arrStates = null; m_agent = null; m_lfTime = 0.0; } boolean checkPosValid() { boolean bResult = false; if(m_arrLfPositions == null) { return false; } int nNumAgents = m_arrLfPositions.length/2; for(int i = 0; i < nNumAgents -1; ++i) { bResult = bResult || (Math.abs(m_arrLfPositions[2*i] - m_arrLfPositions[2*i+2]) > MathUtils.lfEps); } if(bResult == false) { System.out.println("getting coincident pts"); } return bResult; } /** * Constructor */ public SwarmState(double [] arrLfPositions, StateBundle [] arrStates, IAgent agent, double lfTime, CommGraph graph) { populate(arrLfPositions, arrStates, agent, lfTime, graph); } /** * Copy constructor. */ public SwarmState(SwarmState src) { if(src != null) { populate(src.m_arrLfPositions, src.m_arrStates, src.m_agent, m_lfTime, src.m_commGraph); } } void populate(double [] arrLfPositions, StateBundle [] arrStates, IAgent agent, double lfTime, CommGraph graph) { if(arrStates != null) { m_arrStates = new StateBundle[arrStates.length]; for(int i = 0; i < m_arrStates.length; ++i) { if(arrStates[i] != null) { m_arrStates[i] = arrStates[i].makeCopy(); } } } else { m_arrStates = null; } if(agent != null) { m_agent = agent.makeCopy(); } else { m_agent = null; } if(arrLfPositions != null) { m_arrLfPositions = new double[arrLfPositions.length]; for(int i = 0; i < m_arrLfPositions.length; ++i) { m_arrLfPositions[i] = arrLfPositions[i]; } } else { m_arrLfPositions = null; } m_lfTime = lfTime; m_commGraph = graph; checkPosValid(); } }