Ejemplo n.º 1
0
  /**
   * Calculates how every traffic light should be switched Per node, per sign the waiting roadusers
   * are passed and per each roaduser the gain is calculated.
   *
   * @param The TLDecision is a tuple consisting of a traffic light and a reward (Q) value, for it
   *     to be green
   * @see gld.algo.tlc.TLDecision
   */
  public TLDecision[][] decideTLs() {
    int num_dec;
    int num_tld = tld.length;

    // Determine wheter it should be random or not
    boolean do_this_random = false;
    if (random_number.nextFloat() < random_chance) do_this_random = true;

    for (int i = 0; i < num_tld; i++) {
      num_dec = tld[i].length;
      for (int j = 0; j < num_dec; j++) {
        Sign currenttl = tld[i][j].getTL();
        float gain = 0;

        Drivelane currentlane = currenttl.getLane();
        int waitingsize = currentlane.getNumRoadusersWaiting();
        ListIterator queue = currentlane.getQueue().listIterator();

        if (!do_this_random) {
          for (; waitingsize > 0; waitingsize--) {
            Roaduser ru = (Roaduser) queue.next();
            int pos = ru.getPosition();
            Node destination = ru.getDestNode();
            gain +=
                q_table[currenttl.getId()][pos][destination.getId()][1]
                    - q_table[currenttl.getId()][pos][destination.getId()][0]; // red - green
          }
          float q = gain;
        } else gain = random_number.nextFloat();

        tld[i][j].setGain(gain);
      }
    }
    return tld;
  }