Package rinde.sim.core.graph

Examples of rinde.sim.core.graph.MultiAttributeData


  protected double getMaxSpeed(MovingRoadUser object, Point from, Point to) {
    final double objSpeed = toInternalSpeedConv.convert(object.getSpeed());
    if (!from.equals(to)) {
      final Connection<?> conn = getConnection(from, to);
      if (conn.getData() instanceof MultiAttributeData) {
        final MultiAttributeData maed = (MultiAttributeData) conn.getData();
        @SuppressWarnings("null")
        final double connSpeedLimit = maed.getMaxSpeed();
        return Double.isNaN(connSpeedLimit) ? objSpeed : Math.min(
            toInternalSpeedConv.convert(connSpeedLimit), objSpeed);
      }
    }
    return objSpeed;
View Full Code Here


    // length 10 no speed limit
    graph.addConnection(A, B);

    // length 10 speed 2.5
    graph.addConnection(B, C, new MultiAttributeData(10d, 2.5));
    graph.addConnection(C, B); // length Math.sqr(10^2 + 10^2)

    // length 10 speed 10
    graph.addConnection(B, D, new MultiAttributeData(10d, 10));

    graph.addConnection(C, D); // length 10

    // length 12 speed 1
    graph.addConnection(D, C, new MultiAttributeData(12, 1));
    graph.addConnection(D, E, new MultiAttributeData(5, 7));

    final Set<Point> points = graph.getNodes();
    assertEquals(5, points.size());
    assertTrue(points.contains(A));
    assertTrue(points.contains(B));
View Full Code Here

    @Override
    public MultiAttributeData deserialize(String connection) {
      final double distance = Double.parseDouble(connection.split("\"")[1]);
      try {
        final double maxSpeed = Double.parseDouble(connection.split("\"")[3]);
        return new MultiAttributeData(distance, maxSpeed);
      } catch (final Exception e) {
        return new MultiAttributeData(distance);
      }
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void locationIsOnSameEdge() {
    ((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);
View Full Code Here

  public void getConnectionLength() {
    assertEquals(10,
        GraphRoadModel.getConnectionLength(new Connection<ConnectionData>(NE,
            NW, null)), EPSILON);
    final Connection<MultiAttributeData> conn = new Connection<MultiAttributeData>(
        NE, NW, new MultiAttributeData(12, 0d));
    assertEquals(12, GraphRoadModel.getConnectionLength(conn), EPSILON);
    conn.getData().put(MultiAttributeData.KEY_LENGTH, "this is not a number");
    assertEquals(10, GraphRoadModel.getConnectionLength(conn), EPSILON);
  }
View Full Code Here

    assertEquals(conv.convert(10),
        rm.getMaxSpeed(new SpeedyRoadUser(10), A, B), EPSILON);

    ((Graph<MultiAttributeData>) graph).addConnection(SE, SW,
        new MultiAttributeData(3, 5d));
    assertEquals(conv.convert(5),
        model.getMaxSpeed(new SpeedyRoadUser(10), SE, SW), EPSILON);

    ((Graph<MultiAttributeData>) graph).addConnection(NE, SE,
        new MultiAttributeData(3, Double.NaN));
    assertEquals(conv.convert(10),
        model.getMaxSpeed(new SpeedyRoadUser(10), NE, SE), EPSILON);
  }
View Full Code Here

  public void computeConnectionLength() {
    assertEquals(0,
        model.computeConnectionLength(new Point(1, 2), new Point(1, 2)),
        EPSILON);
    ((Graph<MultiAttributeData>) graph).addConnection(SE, SW,
        new MultiAttributeData(5, 5d));

    final TestRoadUser agent1 = new TestRoadUser();
    model.addObjectAt(agent1, SE);
    final MoveProgress pp1 = model.followPath(agent1, asPath(SW), hour());
    pp1.toString();
View Full Code Here

  static <E extends ConnectionData> E mergeEdgeData(E empty, E e1, double l1,
      E e2, double l2) {
    if (empty instanceof LengthData) {
      return (E) new LengthData(l1 + l2);
    } else if (empty instanceof MultiAttributeData) {
      return (E) new MultiAttributeData(l1 + l2);
    }
    throw new IllegalArgumentException("EdgeData objects are of unknown type");
  }
View Full Code Here

          final Point to = nodeMapping.get(nodes.get(i));
          if (from != null && to != null && !from.equals(to)) {

            final double length = Point.distance(from, to);
            if (!graph.hasConnection(from, to)) {
              graph.addConnection(from, to, new MultiAttributeData(length,
                  maxSpeed));
            }
            if (!oneWay && !graph.hasConnection(to, from)) {
              graph.addConnection(to, from, new MultiAttributeData(length,
                  maxSpeed));
            }
          }
        }
      }
View Full Code Here

TOP

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

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.