예제 #1
0
 private void cpdSpd(Measure m) {
   double fr = m.time - 2;
   double to = m.time + 2;
   double spd = 0;
   double cnt = 0;
   double dsSpd = 0;
   double dsCnt = 0;
   double usSpd = 0;
   double usCnt = 0;
   for (Id id : m.in) {
     AgentInfo ai = this.ais.get(id);
     Entry<Double, Integer> frEntr = ai.timePos.floorEntry(fr);
     Entry<Double, Integer> toEntr = ai.timePos.ceilingEntry(to);
     if (frEntr == null) {
       frEntr = ai.timePos.ceilingEntry(fr);
     }
     if (toEntr == null) {
       toEntr = ai.timePos.floorEntry(to);
     }
     double tt = toEntr.getKey() - frEntr.getKey();
     int cells = toEntr.getValue() - frEntr.getValue();
     double dist = Math.abs(cells) * this.cellsize;
     double s = dist / tt;
     spd += s;
     cnt++;
     if (ai.dir == 1) {
       dsSpd += s;
       dsCnt++;
     } else {
       usSpd += s;
       usCnt++;
     }
   }
   m.spd = spd / cnt;
   if (dsCnt > 0) {
     m.dsSpd = dsSpd / dsCnt;
   }
   if (usCnt > 0) {
     m.usSpd = usSpd / usCnt;
   }
 }
예제 #2
0
  @Override
  public void report(BufferedWriter bw) throws IOException {
    int in = this.dsIn + this.usIn - this.dsOut - this.usOut;
    System.out.println(
        in
            + " "
            + " dsIn:"
            + this.dsIn
            + " dsOut:"
            + this.dsOut
            + " usIn:"
            + this.usIn
            + " usOut:"
            + this.usOut);

    List<Tuple<Integer, Integer>> ranges = new ArrayList<>();
    Variance vd = new Variance();
    Variance vs = new Variance();
    Variance vf = new Variance();
    int cnt = 0;
    double tm = 15;
    int from = 0;
    int to = 0;
    for (Measure m : this.ms) {
      cpdSpd(m);
      bw.append(
          m.time + " " + m.dsRho + " " + m.dsSpd + " " + m.usRho + " " + m.usSpd + " " + m.rho + " "
              + " " + m.spd + "\n");

      if (true) continue;
      if (m.time < 15 || m.time > 100) {
        to++;
        from++;
        continue;
      }
      cpdSpd(m);
      vd.addVar(m.rho);
      vs.addVar(m.spd);
      vf.addVar(m.rho * m.spd);
      cnt++;
      if (cnt < 5) {
        to++;
        continue;
      }
      double md = vd.getMean();
      double std = Math.sqrt(vd.getVar());

      double ms = vs.getMean();
      double sts = Math.sqrt(vs.getVar());

      double mf = vf.getMean();
      double stf = Math.sqrt(vf.getVar());

      double bal = m.dsRho / m.usRho;
      bal = bal > 1 ? 1 / bal : bal;
      // bal = 1;
      double timespan = m.time - tm;
      if (md > 1 && std > 0.1 * md || sts > 0.1 * ms || bal < 0.5 || timespan > 20) {
        if (timespan > 5) {
          Tuple<Integer, Integer> t = new Tuple<>(from, to);
          ranges.add(t);
        }
        tm = m.time;
        from = to;
        cnt = 0;
        vd = new Variance();
        vs = new Variance();
      }
      to++;
    }

    int rng = ranges.size();
    int cntt = 0;
    for (Tuple<Integer, Integer> r : ranges) {
      cntt++;
      // if (cntt < rng / 2 + rng / 4 || cntt > rng / 2 + rng / 4 + rng /
      // 8) {
      // continue;
      // }
      from = r.getFirst();
      to = r.getSecond();
      Measure m = new Measure();

      double range = to - from;
      double ccnt = 0;
      double lastTime = 0;
      for (int idx = from; idx < to; idx++) {
        Measure mm = this.ms.get(idx);
        if (lastTime + 1 > mm.time) {
          continue;
        }
        ccnt++;
        m.rho += mm.rho;
        m.spd += mm.spd;
        m.time += mm.time;
        m.dsRho += mm.dsRho;
        m.usRho += mm.usRho;
        m.dsSpd += mm.dsSpd;
        m.usSpd += mm.usSpd;
        bw.append(
            mm.time + " " + mm.dsRho + " " + mm.dsSpd + " " + mm.usRho + " " + mm.usSpd + " "
                + mm.rho + " " + " " + mm.spd + "\n");
        lastTime = mm.time;
      }
      m.rho /= ccnt;
      m.spd /= ccnt;
      m.dsRho /= ccnt;
      m.dsSpd /= ccnt;
      m.usRho /= ccnt;
      m.usSpd /= ccnt;
      m.time /= ccnt;
      // bw.append(m.time + " " + m.dsRho + " " + m.dsSpd + " " + m.usRho
      // + " " + m.usSpd + " " + m.rho + " " + " " + m.spd + "\n");

    }
    // bw.append(m.time + " " + m.rho + " " + m.spd + "\n");

  }