@Test public void testMotionEquations() throws Exception { CartPoleState state = environment.sampleInitialStateDistribution(random); double[] dy = new double[6]; environment.motionEquations(1.0, state.getFeatures(), dy); Assert.assertArrayEquals(new double[] { 0.0, 0.9229968444719383, 0.0, -0.35294478228867243, 0.0, -13.844952667079076 }, dy, 10e-9); }
public void motionEquations(double force, double[] variables, double[] derivatives) { double sumEffectiveMasses = 0; double sumEffectiveForces = 0; for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double effectiveMass = poleMasses[pole] * (1 - (0.75 * Math.pow(cosPoleAngle, 2))); double sinPoleAngle = Math.sin(polAngle); double ml = poleMasses[pole] * poleLengths[pole]; double velocity = variables[3 + (pole * 2)]; double temp = (POLE_FRICTION * velocity) / ml; double effectiveForce = (ml * Math.pow(velocity, 2) * sinPoleAngle) + (0.75 * poleMasses[pole] * cosPoleAngle * (temp + (gravity * sinPoleAngle))); sumEffectiveForces += effectiveForce; sumEffectiveMasses += effectiveMass; } derivatives[1] = (force + sumEffectiveForces) / (sumEffectiveMasses + cartMass); for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double sinPoleAngle = Math.sin(polAngle); double temp = (POLE_FRICTION * variables[3 + (pole * 2)]) / poleMasses[pole] * poleLengths[pole]; derivatives[(pole * 2) + 3] = -0.75 * ((derivatives[1] * cosPoleAngle) + (gravity * sinPoleAngle) + temp) / poleLengths[pole]; } }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void motionEquations(double force, double[] variables, double[] derivatives) { double sumEffectiveMasses = 0; double sumEffectiveForces = 0; for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double effectiveMass = poleMasses[pole] * (1 - (0.75 * Math.pow(cosPoleAngle, 2))); double sinPoleAngle = Math.sin(polAngle); double ml = poleMasses[pole] * poleLengths[pole]; double velocity = variables[3 + (pole * 2)]; double temp = (POLE_FRICTION * velocity) / ml; double effectiveForce = (ml * Math.pow(velocity, 2) * sinPoleAngle) + (0.75 * poleMasses[pole] * cosPoleAngle * (temp + (gravity * sinPoleAngle))); sumEffectiveForces += effectiveForce; sumEffectiveMasses += effectiveMass; } derivatives[1] = (force + sumEffectiveForces) / (sumEffectiveMasses + cartMass); for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double sinPoleAngle = Math.sin(polAngle); double temp = (POLE_FRICTION * variables[3 + (pole * 2)]) / poleMasses[pole] * poleLengths[pole]; derivatives[(pole * 2) + 3] = -0.75 * ((derivatives[1] * cosPoleAngle) + (gravity * sinPoleAngle) + temp) / poleLengths[pole]; } } }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void motionEquations(double force, double[] variables, double[] derivatives) { double sumEffectiveMasses = 0; double sumEffectiveForces = 0; for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double effectiveMass = poleMasses[pole] * (1 - (0.75 * Math.pow(cosPoleAngle, 2))); double sinPoleAngle = Math.sin(polAngle); double ml = poleMasses[pole] * poleLengths[pole]; double velocity = variables[3 + (pole * 2)]; double temp = (POLE_FRICTION * velocity) / ml; double effectiveForce = (ml * Math.pow(velocity, 2) * sinPoleAngle) + (0.75 * poleMasses[pole] * cosPoleAngle * (temp + (gravity * sinPoleAngle))); sumEffectiveForces += effectiveForce; sumEffectiveMasses += effectiveMass; } derivatives[1] = (force + sumEffectiveForces) / (sumEffectiveMasses + cartMass); for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double sinPoleAngle = Math.sin(polAngle); double temp = (POLE_FRICTION * variables[3 + (pole * 2)]) / poleMasses[pole] * poleLengths[pole]; derivatives[(pole * 2) + 3] = -0.75 * ((derivatives[1] * cosPoleAngle) + (gravity * sinPoleAngle) + temp) / poleLengths[pole]; } } CartPoleEnvironment(int numPoles);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass, double gravity); }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void motionEquations(double force, double[] variables, double[] derivatives) { double sumEffectiveMasses = 0; double sumEffectiveForces = 0; for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double effectiveMass = poleMasses[pole] * (1 - (0.75 * Math.pow(cosPoleAngle, 2))); double sinPoleAngle = Math.sin(polAngle); double ml = poleMasses[pole] * poleLengths[pole]; double velocity = variables[3 + (pole * 2)]; double temp = (POLE_FRICTION * velocity) / ml; double effectiveForce = (ml * Math.pow(velocity, 2) * sinPoleAngle) + (0.75 * poleMasses[pole] * cosPoleAngle * (temp + (gravity * sinPoleAngle))); sumEffectiveForces += effectiveForce; sumEffectiveMasses += effectiveMass; } derivatives[1] = (force + sumEffectiveForces) / (sumEffectiveMasses + cartMass); for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double sinPoleAngle = Math.sin(polAngle); double temp = (POLE_FRICTION * variables[3 + (pole * 2)]) / poleMasses[pole] * poleLengths[pole]; derivatives[(pole * 2) + 3] = -0.75 * ((derivatives[1] * cosPoleAngle) + (gravity * sinPoleAngle) + temp) / poleLengths[pole]; } } CartPoleEnvironment(int numPoles);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass, double gravity); double[] getPoleMasses(); double[] getPoleLengths(); double getCartMass(); double getGravity(); int getNumPoles(); @Override AgentTransition<CartPoleState, ContinuousAction> getAgentTransition(CartPoleState state,
			ContinuousAction action); void step(double force, double[] variables, double[] derivatives); void motionEquations(double force, double[] variables, double[] derivatives); void RungeKutta4(double force, double[] y, double[] dydx, double[] yout); @Override EnvTransition<CartPoleState> getEnvironmentTransition(CartPoleState afterState,
			RandomDataGenerator random); @Override List<ContinuousAction> getPossibleActions(CartPoleState state); @Override CartPoleState sampleInitialStateDistribution(RandomDataGenerator random); @Override boolean isTerminal(CartPoleState state); @Override double getAgentPerformance(double totalReward, int numSteps, CartPoleState finalState); @Override double[] encode(CartPoleState state); int getNumInputs(); @Override double[] encode(ContinuousAction action); double evaluate(RealFunction controller, int maxNumSteps, RandomDataGenerator random); @Override String toString(); }
CartPoleEnvironment implements Environment<CartPoleState, ContinuousAction>,
		EnvironmentEncoder<CartPoleState, ContinuousAction>, Serializable { public void motionEquations(double force, double[] variables, double[] derivatives) { double sumEffectiveMasses = 0; double sumEffectiveForces = 0; for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double effectiveMass = poleMasses[pole] * (1 - (0.75 * Math.pow(cosPoleAngle, 2))); double sinPoleAngle = Math.sin(polAngle); double ml = poleMasses[pole] * poleLengths[pole]; double velocity = variables[3 + (pole * 2)]; double temp = (POLE_FRICTION * velocity) / ml; double effectiveForce = (ml * Math.pow(velocity, 2) * sinPoleAngle) + (0.75 * poleMasses[pole] * cosPoleAngle * (temp + (gravity * sinPoleAngle))); sumEffectiveForces += effectiveForce; sumEffectiveMasses += effectiveMass; } derivatives[1] = (force + sumEffectiveForces) / (sumEffectiveMasses + cartMass); for (int pole = 0; pole < numPoles; pole++) { double polAngle = variables[2 + (pole * 2)]; double cosPoleAngle = Math.cos(polAngle); double sinPoleAngle = Math.sin(polAngle); double temp = (POLE_FRICTION * variables[3 + (pole * 2)]) / poleMasses[pole] * poleLengths[pole]; derivatives[(pole * 2) + 3] = -0.75 * ((derivatives[1] * cosPoleAngle) + (gravity * sinPoleAngle) + temp) / poleLengths[pole]; } } CartPoleEnvironment(int numPoles);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass);  CartPoleEnvironment(int numPoles, double[] poleLengths, double[] poleMasses, double cartMass, double gravity); double[] getPoleMasses(); double[] getPoleLengths(); double getCartMass(); double getGravity(); int getNumPoles(); @Override AgentTransition<CartPoleState, ContinuousAction> getAgentTransition(CartPoleState state,
			ContinuousAction action); void step(double force, double[] variables, double[] derivatives); void motionEquations(double force, double[] variables, double[] derivatives); void RungeKutta4(double force, double[] y, double[] dydx, double[] yout); @Override EnvTransition<CartPoleState> getEnvironmentTransition(CartPoleState afterState,
			RandomDataGenerator random); @Override List<ContinuousAction> getPossibleActions(CartPoleState state); @Override CartPoleState sampleInitialStateDistribution(RandomDataGenerator random); @Override boolean isTerminal(CartPoleState state); @Override double getAgentPerformance(double totalReward, int numSteps, CartPoleState finalState); @Override double[] encode(CartPoleState state); int getNumInputs(); @Override double[] encode(ContinuousAction action); double evaluate(RealFunction controller, int maxNumSteps, RandomDataGenerator random); @Override String toString(); static final int NUM_INPUTS_ONE_POLE; static final int NUM_INPUTS_TWO_POLES; }