public static void toCRAWDAD(LinkTrace links, OutputStream out, double timeMul)
      throws IOException {

    StatefulReader<LinkEvent, Link> linkReader = links.getReader();
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
    Map<Link, Long> activeContacts = new AdjacencyMap.Links<Long>();

    linkReader.seek(links.minTime());
    for (Link l : linkReader.referenceState()) activeContacts.put(l, links.minTime());
    while (linkReader.hasNext()) {
      for (LinkEvent lev : linkReader.next()) {
        Link l = lev.link();
        if (lev.isUp()) {
          activeContacts.put(l, linkReader.time());
        } else {
          double b = activeContacts.get(l) * timeMul;
          double e = linkReader.time() * timeMul;
          activeContacts.remove(l);
          bw.write(l.id1() + "\t" + l.id2() + "\t" + b + "\t" + e + "\n");
        }
      }
    }
    linkReader.close();
    bw.close();
  }
Ejemplo n.º 2
0
  @Override
  public void convert() throws IOException {
    final AdjacencyMap.Arcs<ArcEvent> to_bring_down = new AdjacencyMap.Arcs<ArcEvent>();

    final StatefulWriter<ArcEvent, Arc> upper_writer = _upper.getWriter();
    final StatefulReader<ArcEvent, Arc> lower_reader = _lower.getReader();

    lower_reader.seek(_lower.minTime());
    upper_writer.setInitState(_lower.minTime(), lower_reader.referenceState());
    long last_time = _lower.minTime();
    long time = last_time;
    final long eta = _lower.eta();

    while (lower_reader.hasNext()) {
      time = lower_reader.nextTime();
      if (time > last_time + eta) {
        for (final ArcEvent aev : to_bring_down.values()) upper_writer.queue(last_time, aev);
        to_bring_down.clear();
      }
      boolean first_down = true;
      for (final ArcEvent aev : lower_reader.next()) { // assumes that all
        // UP event come
        // before all DOWN
        // events
        final Arc a = aev.arc();
        if (aev.isUp()) {
          if (to_bring_down.containsKey(a)) to_bring_down.remove(a);
          else upper_writer.queue(time, aev);
        } else { // down event. Just queue for next time step
          if (first_down) { // first flush previous time's down events
            for (final ArcEvent dev : to_bring_down.values()) upper_writer.queue(last_time, dev);
            to_bring_down.clear();
            first_down = false;
          }
          to_bring_down.put(a, aev);
        }
      }
      upper_writer.flush(last_time);
      last_time = time;
    }

    // flush final events
    for (final ArcEvent dev : to_bring_down.values()) upper_writer.queue(last_time, dev);
    upper_writer.flush();

    upper_writer.setPropertiesFromTrace(_lower);
    _lower.copyOverTraceInfo(upper_writer);
    upper_writer.close();
    lower_reader.close();
  }