Package rinde.sim.core.model.road.GraphRoadModel

Examples of rinde.sim.core.model.road.GraphRoadModel.Loc


  // TODO add unit tests for timelapse inputs
  @Override
  protected MoveProgress doFollowPath(MovingRoadUser object, Queue<Point> path,
      TimeLapse time) {
    final long startTimeConsumed = time.getTimeConsumed();
    final Loc objLoc = objLocs.get(object);
    checkLocation(objLoc);
    double traveled = 0;

    final UnitConverter toInternalTimeConv = time.getTimeUnit().getConverterTo(
        INTERNAL_TIME_UNIT);
    final UnitConverter toExternalTimeConv = INTERNAL_TIME_UNIT
        .getConverterTo(time.getTimeUnit());

    Loc tempLoc = objLoc;
    Point tempPos = objLoc;

    double newDis = Double.NaN;

    final List<Point> travelledNodes = new ArrayList<Point>();
View Full Code Here


      // check if next destination is a MidPoint
      checkArgument(
          nextHop instanceof Loc,
          "Illegal path for this object, from a position on an edge we can not jump to another edge or go back. From %s, to %s.",
          objLoc, nextHop);
      final Loc dest = (Loc) nextHop;
      // check for same edge
      checkArgument(
          objLoc.isOnSameConnection(dest),
          "Illegal path for this object, first point is not on the same edge as the object.");
      // check for relative position
      checkArgument(objLoc.relativePos <= dest.relativePos,
          "Illegal path for this object, can not move backward over an edge.");
    }
    // in case we start from a node and we are not going to another node
    else if (!objLoc.isOnConnection() && !nextHop.equals(objLoc)
        && !graph.hasConnection(objLoc, nextHop)) {
      checkArgument(nextHop instanceof Loc,
          "Illegal path, first point should be directly connected to object location.");
      final Loc dest = (Loc) nextHop;
      checkArgument(graph.hasConnection(objLoc, dest.conn.to),
          "Illegal path, first point is on an edge not connected to object location. ");
      checkArgument(objLoc.equals(dest.conn.from),
          "Illegal path, first point is on a different edge.");
    }
View Full Code Here

  protected double computeConnectionLength(Point from, Point to) {
    if (from.equals(to)) {
      return 0;
    }
    if (isOnConnection(from) && isOnConnection(to)) {
      final Loc start = (Loc) from;
      final Loc end = (Loc) to;
      checkArgument(start.isOnSameConnection(end),
          "the points are not on the same connection");
      return Math.abs(start.relativePos - end.relativePos);
    } else if (isOnConnection(from)) {
      final Loc start = (Loc) from;
      checkArgument(start.conn.to.equals(to),
          "from is not on a connection leading to 'to'");
      return start.connLength - start.relativePos;
    } else if (isOnConnection(to)) {
      final Loc end = (Loc) to;
      checkArgument(end.conn.from.equals(from), "to is not connected to from");
      return end.relativePos;
    } else {
      checkArgument(graph.hasConnection(from, to), "connection does not exist");
      return getConnectionLength(graph.getConnection(from, to));
View Full Code Here

  protected Connection<?> getConnection(Point from, Point to) {
    final boolean fromIsOnConn = isOnConnection(from);
    final boolean toIsOnConn = isOnConnection(to);
    Connection<?> conn = null;
    if (fromIsOnConn) {
      final Loc start = (Loc) from;
      if (toIsOnConn) {
        checkArgument(start.isOnSameConnection((Loc) to),
            "the specified points must be part of the same connection");
      } else {
        checkArgument(start.conn.to.equals(to),
            "the specified points must be part of the same connection");
      }
      conn = start.conn;

    } else if (toIsOnConn) {
      final Loc end = (Loc) to;
      checkArgument(end.conn.from.equals(from),
          "the specified points must be part of the same connection");
      conn = end.conn;
    } else {
      checkArgument(graph.hasConnection(from, to),
View Full Code Here

   * @return A {@link Connection} if <code>obj</code> is on one,
   *         <code>null</code> otherwise.
   */
  @Nullable
  public Connection<? extends ConnectionData> getConnection(RoadUser obj) {
    final Loc point = objLocs.get(obj);
    if (isOnConnection(point)) {
      return graph.getConnection(point.conn.from, point.conn.to);
    }
    return null;
  }
View Full Code Here

   * @param p The point used as input.
   * @return A {@link Loc} with identical position as the specified
   *         {@link Point}.
   */
  protected static Loc newLoc(Point p) {
    return new Loc(p.x, p.y, null, -1, 0);
  }
View Full Code Here

    final Point diff = Point.diff(conn.to, conn.from);
    final double roadLength = getConnectionLength(conn);

    final double perc = relativePos / roadLength;
    if (perc + DELTA >= 1) {
      return new Loc(conn.to.x, conn.to.y, null, -1, 0);
    }
    return new Loc(conn.from.x + perc * diff.x, conn.from.y + perc * diff.y,
        conn, roadLength, relativePos);
  }
View Full Code Here

    ((Graph<MultiAttributeData>) graph).addConnection(SE, SW,
        new MultiAttributeData(300));
    ((Graph<MultiAttributeData>) graph).addConnection(NE, SW,
        new MultiAttributeData(Double.NaN));

    final Loc loc1 = GraphRoadModel.newLoc(new Connection<ConnectionData>(SW,
        SE, null), 3);
    final Loc loc2 = GraphRoadModel.newLoc(new Connection<ConnectionData>(SW,
        SE, null), 1);
    final Loc loc3 = GraphRoadModel.newLoc(new Connection<ConnectionData>(SE,
        NE, null), 9.999999);
    final Loc loc4 = GraphRoadModel.newLoc(SW);
    final Loc loc5 = GraphRoadModel.newLoc(new Connection<ConnectionData>(SE,
        SW, null), 1);
    final Loc loc6 = GraphRoadModel.newLoc(new Connection<ConnectionData>(NE,
        SW, null), 1);

    assertEquals(NE, loc3);
    assertTrue(loc1.isOnSameConnection(loc2));
    assertTrue(loc2.isOnSameConnection(loc1));
View Full Code Here

    assertFalse(loc3.isOnSameConnection(loc6));
  }

  @Test(expected = NullPointerException.class)
  public void newLocationFail1() {
    @SuppressWarnings({ "null", "unused" })
    final Loc l = GraphRoadModel.newLoc(null);
  }
View Full Code Here

    final Loc l = GraphRoadModel.newLoc(null);
  }

  @Test(expected = IllegalArgumentException.class)
  public void checkLocationFail1() {
    final Loc l = GraphRoadModel.newLoc(new Point(-10, -10));
    model.checkLocation(l);
  }
View Full Code Here

TOP

Related Classes of rinde.sim.core.model.road.GraphRoadModel.Loc

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.