/** *

Just a series of simple checks to prevent stupid mismatches. * A truly well-engineered solution would make it impossible * to generate a mismatch. For version 1.0, we'll just make * simple sanity checking available instead. *

* @author Michael Schuresko * @version %I%, %G% * @since 1.0 */ public class SanityChecks { /** * Checks that the dimensionality of a continuous state vector, * vector of discrete state descriptions, and agent internal * state all match up. * @param agent description * @param arrLfContState continuous state state-vector * @param arrStates array of discrete states (one for each agent) * @return true if everything checks out, false otherwise */ public static boolean dimensionCheck(IAgent agent, double [] arrLfContState, StateBundle [] arrStates) { int nCnt = arrLfContState.length; for(int i = 0; i < arrStates.length; ++i) { if(arrStates[i] == null) { return false; } nCnt -= arrStates[i].getControlFunc().getNumStateVars(); } return (nCnt == 0); } /** * checks that the agent knows how to handle each state in * the state array (and that the states are not null) * @param agent description * @param arrStates array of discrete states (one for each agent) * @return true if everything checks out, false otherwise */ public static boolean stateCheck(IAgent agent, StateBundle [] arrStates) { for(int i = 0; i < arrStates.length; ++i) { if(arrStates[i] == null || agent.checkStateValidity(arrStates[i]) == false) { return false; } } return true; } }