Пример #1
0
  @Override
  public void trigger(double time) {
    Measure m = new Measure();
    m.time = time;
    int cnt = 0;
    double dsCnt = 0;
    double usCnt = 0;
    double dsRho = 0;
    double usRho = 0;
    for (int lane = 0; lane < this.lanes; lane++) {
      CAMoveableEntity[] p = this.l.getParticles(lane);
      for (int i = this.from; i <= this.to; i++) {
        if (p[i] != null) {
          cnt++;
          m.in.add(p[i].getId());
          AgentInfo ai = this.ais.get(p[i].getId());
          // updateTimeRho(i, ai.dir, ai, time, p);
          if (p[i].getDir() == 1) {

            dsCnt++;
            // dsRho += ai.timeRho.get(time);
          } else {
            usCnt++;
            // usRho += ai.timeRho.get(time);
          }
        }
      }
    }
    double rho = cnt / this.a;

    m.rho = rho;
    m.dsRho = dsCnt / this.a;
    m.usRho = usCnt / this.a;
    // m.dsRho = dsRho / dsCnt;
    // m.usRho = usRho / usCnt;

    for (int lane = 0; lane < this.lanes; lane++) {
      CAMoveableEntity[] p = this.l.getParticles(lane);
      for (int i = 0; i < this.l.getNumOfCells(); i++) {
        CAMoveableEntity part = p[i];
        if (part != null) {
          Id id = part.getId();
          AgentInfo ai = this.ais.get(id);
          if (ai == null && (i == 0 || i == this.l.getNumOfCells() - 1)) {
            ai = new AgentInfo(part.getDir());
            // ai.lastPos = i;
            this.ais.put(id, ai);
          }
          if (ai.lastPos != i) {
            ai.timePos.put(time, i);
            ai.lastPos = i;
            if (i == 0) {
              if (part.getDir() == 1) {
                this.dsIn++;
              } else {
                this.usOut++;
              }
            } else if (i == this.l.getNumOfCells() - 1) {
              if (part.getDir() == 1) {
                this.dsOut++;
              } else {
                this.usIn++;
              }
            }
          }
        }
      }
    }
    if (m.rho > 0) {
      this.ms.add(m);
    }
  }