Package rinde.sim.core.graph

Examples of rinde.sim.core.graph.Point


  }

  @Test
  public void followPathStepByStep() {
    final SpeedyRoadUser agent = new SpeedyRoadUser(speed);
    model.addObjectAt(agent, new Point(0, 0));
    assertEquals(new Point(0, 0), model.getPosition(agent));
    assertEquals(5, path.size());

    final MoveProgress progress = model.followPath(agent, path,
        AbstractRoadModelTest.hour());
    assertEquals(speed, progress.distance.getValue(), DELTA);
View Full Code Here


    String line;
    while ((line = reader.readLine()) != null) {
      if (line.contains(POS + "=")) {
        final String nodeName = line.substring(0, line.indexOf("[")).trim();
        final String[] position = line.split("\"")[1].split(",");
        final Point p = new Point(Double.parseDouble(position[0]),
            Double.parseDouble(position[1]));
        nodeMapping.put(nodeName, p);
      } else if (line.contains("->")) {
        // example:
        // node1004 -> node820[label="163.3"]
        final String[] names = line.split("->");
        final String fromStr = names[0].trim();
        final String toStr = names[1].substring(0, names[1].indexOf("["))
            .trim();
        final Point from = nodeMapping.get(fromStr);
        final Point to = nodeMapping.get(toStr);
        for (final SerializerFilter<?> f : filters) {
          if (f.filterOut(from, to)) {
            continue;
          }
        }
View Full Code Here

    // @Ignore
    @Test
    public void testReadWrite() {
        final List<Point> points = new ArrayList<Point>();
        for (int i = 0; i < 1000; i++) {
            points.add(new Point(Math.random(), Math.random()));
        }

        final Scenario original = randomScenario(new MersenneTwister(123), 10, points);

        assertEquals(10, original.size());
View Full Code Here

    }

    @Test
    public void testSorting() {
        final List<TimedEvent> events = new ArrayList<TimedEvent>(10);
        final AddObjectEvent A1 = new AddObjectEvent(0, new Point(1, 0));
        final AddObjectEvent A2 = new AddObjectEvent(0, new Point(2, 0));
        final AddObjectEvent B = new AddObjectEvent(1, new Point(1, 1));
        final AddObjectEvent C = new AddObjectEvent(2, new Point(1, 0));
        final AddObjectEvent D1 = new AddObjectEvent(3, new Point(1, 2));
        final AddObjectEvent D2 = new AddObjectEvent(3, new Point(1, 3));
        final AddObjectEvent E = new AddObjectEvent(4, new Point(2, 0));
        final AddObjectEvent F = new AddObjectEvent(5, new Point(4, 0));
        events.addAll(asList(A1, A2, B, C, D1, D2, E, F));
        Collections.reverse(events);

        final ScenarioBuilder builder = new ScenarioBuilder(A1.getEventType());
        builder.addEvents(events);
View Full Code Here

    @Test
    public void testCreateScenarioByCopying() {

        final Scenario s = new ScenarioBuilder(EVENT_A)
                .addEvent(new AddObjectEvent(100, new Point(0, 0)))
                .addEvent(new AddObjectEvent(200, new Point(0, 0)))
                .addEvent(new AddObjectEvent(300, new Point(0, 0))).build();

        assertEquals(3, s.asList().size());

        final Scenario s2 = new Scenario(s);
View Full Code Here

    }

    @Test
    public void timedEventEquals() {
        assertFalse(new AddObjectEvent(10, new Point(10, 0))
                .equals(new TimedEvent(EVENT_A, 10)));
        assertFalse(new TimedEvent(EVENT_A, 10).equals(null));
        assertFalse(new TimedEvent(EVENT_A, 10).equals(new TimedEvent(EVENT_B,
                10)));
        assertTrue(new TimedEvent(EVENT_B, 10).equals(new TimedEvent(EVENT_B,
View Full Code Here

        int offsetX = 0;
        int offsetY = 0;
        @Nullable
        final ParcelState ps = pdpModel.get().getParcelState(p);
        if (ps == ParcelState.AVAILABLE) {
          final Point pos = roadModel.get().getPosition(p);
          final int x = vp.toCoordX(pos.x);
          final int y = vp.toCoordY(pos.y);
          offsetX = (int) img.atSiteOffset.x + x - image.getBounds().width / 2;
          offsetY = (int) img.atSiteOffset.y + y - image.getBounds().height / 2;
        } else if (ps == ParcelState.PICKING_UP || ps == ParcelState.DELIVERING) {

          final Vehicle v = mapping.get(p);
          final PDPModel.VehicleParcelActionInfo vpai = pdpModel.get()
              .getVehicleActionInfo(v);
          final Point pos = roadModel.get().getPosition(v);
          final int x = vp.toCoordX(pos.x);
          final int y = vp.toCoordY(pos.y);
          final double percentage = 1d - vpai.timeNeeded()
              / (double) p.getPickupDuration();
          final String text = ((int) (percentage * 100d)) + "%";

          final float rotFac = (float) (ps == ParcelState.PICKING_UP ? percentage
              : 1d - percentage);
          rotation = IN_CARGO_ROTATION * rotFac;

          final int textWidth = gc.textExtent(text).x;
          gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_BLUE));
          gc.drawText(text, (int) LABEL_OFFSET.x + x - textWidth / 2,
              (int) LABEL_OFFSET.y + y, true);

          Point from = new Point(img.atSiteOffset.x + x
              - image.getBounds().width
              / 2d, img.atSiteOffset.y + y - image.getBounds().height / 2d);
          Point to = new Point(img.inCargoOffset.x + x
              - image.getBounds().width
              / 2d, img.inCargoOffset.y + y - image.getBounds().height / 2d);

          if (ps == ParcelState.DELIVERING) {
            final Point temp = from;
            from = to;
            to = temp;
          }

          final Point diff = Point.diff(to, from);
          offsetX = (int) (from.x + (percentage * diff.x));
          offsetY = (int) (from.y + (percentage * diff.y));

        } else if (ps == ParcelState.IN_CARGO) {
          rotation = IN_CARGO_ROTATION;
          final Point pos = roadModel.get().getPosition(mapping.get(p));
          final int x = vp.toCoordX(pos.x);
          final int y = vp.toCoordY(pos.y);
          offsetX = (int) img.inCargoOffset.x + x - image.getBounds().width / 2;
          offsetY = (int) img.inCargoOffset.y + y - image.getBounds().height
              / 2;
View Full Code Here

  static void addPath(Graph<?> graph, Point... points) {
    final List<Point> newPoints = newArrayList();
    for (int i = 0; i < points.length - 1; i++) {
      final double dist = Point.distance(points[i], points[i + 1]);
      final Point unit = Point.divide(Point.diff(points[i + 1], points[i]),
          dist);
      final int numPoints = DoubleMath.roundToInt(dist / POINT_DISTANCE,
          RoundingMode.FLOOR);
      for (int j = 0; j < numPoints; j++) {
        final double factor = j * POINT_DISTANCE;
        newPoints.add(new Point(points[i].x + factor * unit.x, points[i].y
            + factor * unit.y));
      }
    }
    newPoints.add(points[points.length - 1]);
    Graphs.addPath(graph, newPoints.toArray(new Point[newPoints.size()]));
View Full Code Here

    final Graph<LengthData> graph = new MultimapGraph<LengthData>();

    int v = 0;
    // draw vertical lines
    for (int i = 0; i < width + 1; i++) {
      Point prev = new Point(i * distance, 0);
      if (i % vLines == 0) {
        for (int j = 1; j < height; j++) {
          final Point cur = new Point(i * distance, j * distance);
          if (v % 2 == 0) {
            graph.addConnection(prev, cur);
          } else {
            graph.addConnection(cur, prev);
          }
          prev = cur;
        }
        v++;
      }
    }

    int y = 1;
    for (int i = 0; i < height; i++) {
      Point prev = new Point(0, i * distance);
      if (i % hLines == 0) {
        for (int j = 1; j < width + 1; j++) {
          final Point cur = new Point(j * distance, i * distance);
          if (y % 2 == 0) {
            graph.addConnection(prev, cur);
          } else {
            graph.addConnection(cur, prev);
          }
View Full Code Here

    return graph;
  }

  static Graph<LengthData> createGraph() {
    final Graph<LengthData> graph = new MultimapGraph<LengthData>();
    addPath(graph, new Point(10, 10), new Point(10, 50), new Point(10, 80),
        new Point(10, 100), new Point(50, 100), new Point(100, 100), new Point(
            100, 80), new Point(100, 10), new Point(50, 10), new Point(15, 10),
        new Point(10, 10));

    addPath(graph, new Point(100, 10), new Point(100, 5));

    addPath(graph, new Point(10, 50), new Point(15, 50), new Point(15, 15),
        new Point(50, 15), new Point(55, 15), new Point(55, 60), new Point(50,
            60));

    addPath(graph, new Point(15, 15), new Point(15, 10), new Point(15, 5),
        new Point(50, 5));

    addPath(graph, new Point(50, 100), new Point(50, 60), new Point(40, 60),
        new Point(40, 80), new Point(50, 80));

    addPath(graph, new Point(50, 60), new Point(50, 15), new Point(50, 10),
        new Point(50, 5), new Point(100, 5), new Point(120, 5), new Point(120,
            10), new Point(120, 20), new Point(115, 20), new Point(115, 40),
        new Point(120, 40), new Point(120, 80), new Point(100, 80), new Point(
            50, 80));

    addPath(graph, new Point(100, 10), new Point(120, 10));
    addPath(graph, new Point(120, 20), new Point(120, 40));
    addPath(graph, new Point(40, 80), new Point(10, 80));
    return graph;
  }
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.