Beispiel #1
0
 public void run() {
   try {
     while (true) {
       pendulum.step();
       queue.put(pendulum.get());
     }
   } catch (InterruptedException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
  @Test
  public void testStepFunction() {
    Sample sample = simulator.step(1);

    assertEquals(.1571, sample.currState.get(0), .0001);
    assertEquals(.1397, sample.currState.get(1), .0001);

    assertEquals(1, sample.action);
    double roundedVal = (double) Math.round(sample.nextState.get(0) * 10000) / 10000;
    assertEquals(0.1813, roundedVal, .0001);
    roundedVal = (double) Math.round(sample.nextState.get(1) * 10000) / 10000;
    assertEquals(0.3502, roundedVal, .0001);
    assertEquals(0, (int) sample.reward);
  }
  @Test
  public void testSimEnd() {
    int iter = 0;
    final int maxIter = 1000;

    while (!simulator.isTerminal(simulator.getState())) {
      iter++;
      if (iter >= maxIter) {
        fail("Pendulum did not enter terminal state before max iterations");
      }
      simulator.step(1);
    }
    assertTrue(simulator.isNonGoalTerminal(simulator.getState()));
    assertFalse(simulator.isGoal(simulator.getState()));
  }
 /** Creates a new deterministic pendulum domain for testing. */
 @Before
 public void setup() {
   simulator = new Pendulum(20);
   double[] stateArray = {0.1571, 0.1397};
   simulator.setState(new DenseVector(stateArray));
 }
Beispiel #5
0
 @Override
 protected void doUpdate(long elapsed) {
   elapsed = 100;
   pendulum1.update(elapsed);
   pendulum2.update(elapsed);
 }
Beispiel #6
0
 @Override
 protected void doPaint(Graphics2D g2) {
   pendulum1.doPaint(g2);
   pendulum2.doPaint(g2);
 }
 public void mouseReleased() {
   p.stopDragging();
 }
 public void mousePressed() {
   p.clicked(mouseX, mouseY);
 }
  public void draw() {

    background(255);
    p.go();
  }