Package rinde.sim.core.graph

Examples of rinde.sim.core.graph.Point


  }

  @Test(expected = IllegalArgumentException.class)
  public void followPathUnconnected() {
    final MovingRoadUser agent = new SpeedyRoadUser(100);
    model.addObjectAt(agent, new Point(0, 0));
    assertEquals(new Point(0, 0), model.getPosition(agent));

    // illegal trajectory, the two points are not connected
    final Queue<Point> traject = new LinkedList<Point>(Arrays.asList(new Point(
        0, 0), new Point(10, 10)));

    assertEquals(2, traject.size());
    model.followPath(agent, traject, timeLength(20));
  }
View Full Code Here


  }

  @Test(expected = IllegalArgumentException.class)
  public void followPathNotAvertex() {
    final MovingRoadUser agent = new SpeedyRoadUser(EPSILON);
    model.addObjectAt(agent, new Point(0, 0));
    assertEquals(new Point(0, 0), model.getPosition(agent));

    // illegal trajectory, the second point is not a vertex
    final Queue<Point> traject = new LinkedList<Point>(Arrays.asList(new Point(
        0, 0), new Point(10, 1)));

    assertEquals(2, traject.size());
    model.followPath(agent, traject, timeLength(20));
  }
View Full Code Here

  }

  @Test
  public void followPathNotTillEnd() {
    final MovingRoadUser agent = new SpeedyRoadUser(1);
    model.addObjectAt(agent, new Point(0, 0));
    assertEquals(new Point(0, 0), model.getPosition(agent));

    final Queue<Point> path = asPath(SW, SE, NE);
    MoveProgress travelled = model.followPath(agent, path, hour(10));
    assertEquals(10d, travelled.distance.getValue(), EPSILON);
    assertEquals(1, path.size());

    travelled = model.followPath(agent, path, hour(1));
    assertEquals(1d, travelled.distance.getValue(), EPSILON);
    assertEquals(1, path.size());
    assertEquals(new Point(10, 1), model.getPosition(agent));
  }
View Full Code Here

  public void followPathTime() {
    final Queue<Point> path = asPath(SW, SE, NE);
    assertEquals(3, path.size());

    final MovingRoadUser agent = new SpeedyRoadUser(5);
    model.addObjectAt(agent, new Point(0, 0));
    assertTrue(model.getPosition(agent).equals(new Point(0, 0)));
    assertEquals(3, path.size());

    MoveProgress progress = model.followPath(agent, path, hour(1));
    assertEquals(5d, progress.distance.getValue(), EPSILON);
    assertEquals(2, path.size());
    assertEquals(new Point(5, 0), model.getPosition(agent));

    progress = model.followPath(agent, path, hour(2)); // follow path
                                                       // for 2 x
                                                       // time
    assertEquals(10, progress.distance.getValue(), EPSILON);
    assertEquals(1, path.size());
    assertEquals(new Point(10, 5), model.getPosition(agent));

    progress = model.followPath(agent, path, hour(3)); // follow path
                                                       // for 3 x
                                                       // time
    // == 15
    assertEquals(5, progress.distance.getValue(), EPSILON);
    assertEquals(Measure.valueOf(1L, NonSI.HOUR).to(SI.MILLI(SI.SECOND)),
        progress.time);
    assertEquals(0, path.size());
    assertEquals(new Point(10, 10), model.getPosition(agent));
  }
View Full Code Here

    graph.addConnection(NE, SE);

    final MovingRoadUser agent1 = new TestRoadUser();
    model.addObjectAt(agent1, SW);
    model.followPath(agent1, new LinkedList<Point>(asList(SW, SE)), hour(5));
    assertEquals(new Point(5, 0), model.getPosition(agent1));

    final MovingRoadUser agent2 = new TestRoadUser();
    model.addObjectAt(agent2, SW);
    assertEquals(new Point(0, 0), model.getPosition(agent2));

    final Queue<Point> path1 = new LinkedList<Point>(model.getShortestPathTo(
        agent2, agent1));
    assertEquals(asList(SW, new Point(5, 0)), path1);

    model.followPath(agent2, path1, hour(10));
    assertEquals(new Point(5, 0), model.getPosition(agent2));

    final Queue<Point> path2 = new LinkedList<Point>(model.getShortestPathTo(
        agent2, NE));
    assertEquals(asList(new Point(5, 0), SE, NE), path2);
    model.followPath(agent2, path2, hour(10));
    assertEquals(new Point(10, 5), model.getPosition(agent2));
    assertTrue(connectionEquals(model.getConnection(agent2), SE, NE));

    // coming from the front side, we have to turn around at p1
    final Queue<Point> path3 = new LinkedList<Point>(model.getShortestPathTo(
        agent2, agent1));
    assertEquals(asList(new Point(10, 5), NE, SE, SW, new Point(5, 0)), path3);
    model.followPath(agent2, path3, hour(100));

    assertEquals(new Point(5, 0), model.getPosition(agent1));
    assertEquals(new Point(5, 0), model.getPosition(agent2));

    graph.addConnection(SW, NW);
    graph.addConnection(NW, SW);
    model.followPath(agent2, new LinkedList<Point>(asList(SE, SW, NW)),
        hour(25));
    assertEquals(new Point(0, 10), model.getPosition(agent2));

    // coming from the back side, no turning around is required
    final Queue<Point> path4 = new LinkedList<Point>(model.getShortestPathTo(
        agent2, agent1));
    assertEquals(asList(NW, SW, new Point(5, 0)), path4);
    assertEquals(10,
        model.followPath(agent2, path4, hour(10)).distance.getValue(), EPSILON);
    assertEquals(new Point(0, 0), model.getPosition(agent2));
    assertEquals(5,
        model.followPath(agent2, path4, hour(20)).distance.getValue(), EPSILON);
    assertEquals(new Point(5, 0), model.getPosition(agent2));
  }
View Full Code Here

  }

  @Test(expected = IllegalArgumentException.class)
  public void followPathWrongFirstPoint() {
    final MovingRoadUser agent = new SpeedyRoadUser(3);
    model.addObjectAt(agent, new Point(10, 10));

    final Queue<Point> path = asPath(SW, SE, NE);
    assertEquals(new Point(10, 10), model.getPosition(agent));
    assertEquals(3, path.size());
    // the path does not directly connect to the current position
    model.followPath(agent, path, timeLength(1));
  }
View Full Code Here

    model.addObjectAt(tru2, SW);
    final MoveProgress pp = model.followPath(tru2,
        asPath(SW, SE, model.getPosition(tru1)), hour(11));
    assertEquals(11, pp.distance.getValue(), EPSILON);

    final Point p1 = model.getPosition(tru1);
    final Point p2 = model.getPosition(tru2);

    final Point diff = Point.diff(p1, p2);
    assertTrue(diff.x == 0 && diff.y > 0);
  }
View Full Code Here

    final TestRoadUser tru2 = new TestRoadUser();
    model.addObjectAt(tru2, SW);
    model.followPath(tru2, asPath(SW, SE), hour(2));

    // now the road users are in the above described positions
    final Point difference = Point.diff(model.getPosition(tru1),
        model.getPosition(tru2));
    assertTrue(difference.x < 0 && difference.y == 0);

    model.followPath(tru2, asPath(model.getPosition(tru1)), hour(2));
  }
View Full Code Here

  @Test
  public void moveTo() {
    final MovingRoadUser agent = new SpeedyRoadUser(1);

    model.addObjectAt(agent, SW);
    assertEquals(new Point(0, 0), model.getPosition(agent));

    model.moveTo(agent, NW, hour(9));
    assertTrue(Point.distance(model.getPosition(agent), new Point(9, 0)) < EPSILON);

    model.followPath(agent, newLinkedList(asList(SE, NE)), hour(2));
    assertTrue(Point.distance(model.getPosition(agent), new Point(10, 1)) < EPSILON);

    model.moveTo(agent, NW, hour(2));
    assertTrue(Point.distance(model.getPosition(agent), new Point(10, 3)) < EPSILON);

    model.moveTo(agent, NW, hour(1));
    model.moveTo(agent, NE, hour(1));
    assertTrue(Point.distance(model.getPosition(agent), new Point(10, 5)) < EPSILON);

    model.followPath(agent, newLinkedList(asList(NE)), hour(2));
    assertTrue(Point.distance(model.getPosition(agent), new Point(10, 7)) < EPSILON);

    model.moveTo(agent, NW, hour(13));
    assertTrue(Point.distance(model.getPosition(agent), new Point(0, 10)) < EPSILON);

    final MovingRoadUser agent2 = new SpeedyRoadUser(1);
    model.addObjectAt(agent2, SW);
    assertEquals(new Point(0, 0), model.getPosition(agent2));

    model.moveTo(agent2, agent, hour(30));
    assertEquals(model.getPosition(agent), model.getPosition(agent2));
  }
View Full Code Here

  }

  @Test(expected = IllegalArgumentException.class)
  public void getShortestPathToFail() {
    model.getShortestPathTo(new TestRoadUser(), new Point(0, 0));
  }
View Full Code Here

TOP

Related Classes of rinde.sim.core.graph.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.