Beispiel #1
0
	protected void recalcQ(Sign tl, int pos, Node destination, boolean light, Sign tl_new, int pos_new, PosMov[] posMovs, int Ktl)
	{
		/* The calculation of the Q values in TC-3 */
		float newQvalue = qa_table[tl.getId()][pos][destination.getId()][light?green_index:red_index];
		float V=0;

// Waarom splitst TC2 wel op rood/groen, en TC3 niet??
		CountEntry currentsituation = new CountEntry (tl, pos, destination, light, tl_new, pos_new, Ktl);		
		Enumeration e = pKtl_table[tl.getId()][pos][destination.getId()].elements();
		
		while(e.hasMoreElements()) {
			PKtlEntry P = (PKtlEntry) e.nextElement();
			if(P.sameSourceKtl(currentsituation) != -1.0f) {
				try {
					V = v_table[P.tl_new.getId()][P.pos_new][destination.getId()];
				}
				catch (Exception excep) {
					System.out.println("ERROR in q");
				}
// Moet er hier geen reward functie??				
				newQvalue += P.getValue() *gamma * V;
			}
		}
		
		q_table[tl.getId()][pos][destination.getId()][light?green_index:red_index] = newQvalue; //sign, pos, des, color (red=0, green=1)
	}
Beispiel #2
0
	protected void recalcV(Sign tl, int pos, Node destination, boolean light, int Ktl)
	{
		/* The calculation of the V values in TC-3 */
		float newVvalue;
		float tempSumGreen=0, tempSumRed=0;
		float V;
		int[] amount = count(tl, pos, destination);
		int tlId = tl.getId();
		int desId = destination.getId();
		float total = (float) amount[green_index] + (float) amount[red_index];

		newVvalue = va_table[tl.getId()][pos][destination.getId()];
		
		CountEntry currentsituation_green = new CountEntry (tl, pos, destination, green, tl, pos, Ktl);
		CountEntry currentsituation_red = new CountEntry (tl, pos, destination, red, tl, pos, Ktl);
		
		Enumeration e = pKtl_table[tlId][pos][desId].elements();
		
		while(e.hasMoreElements()) {
			//Green part
			PKtlEntry P = (PKtlEntry) e.nextElement();
			
			if(P.sameSourceKtl(currentsituation_green) != -1) {
				try {				
					V = v_table[P.tl_new.getId()][P.pos_new][destination.getId()];
					tempSumGreen += P.getValue() *gamma * V;
				}
				catch (Exception excep) {
					System.out.println(excep+"");
					excep.printStackTrace();
				}
			}
			//Red Part
			if(P.sameSourceKtl(currentsituation_red) != -1) {
				try {				
					V = v_table[P.tl_new.getId()][P.pos_new][destination.getId()];
					tempSumRed += P.getValue() *gamma * V;
				}
				catch (Exception excep) {
					System.out.println("ERROR in recalc V2");
					System.out.println(excep+"");
					excep.printStackTrace();
				}
			}
		}
		
		newVvalue += ((float)amount[green_index]/ (float)total) * tempSumGreen + ((float)amount[red_index]/ (float)total) * tempSumRed;
		try {
			v_table[tl.getId()][pos][destination.getId()] = newVvalue;
		}
		catch (Exception excep) {
			System.out.println("Error in v");
		}
	}
Beispiel #3
0
 public void loadSecondStage(Dictionary dictionaries)
     throws XMLInvalidInputException, XMLTreeException {
   super.loadSecondStage(dictionaries);
   // Load roads
   Dictionary roadDictionary = (Dictionary) (dictionaries.get("road"));
   allRoads = new Road[loadData.roads.length];
   for (int t = 0; t < loadData.roads.length; t++) {
     allRoads[t] = (Road) (roadDictionary.get(new Integer(loadData.roads[t])));
     if (allRoads[t] == null && loadData.roads[t] != -1)
       System.out.println("Warning : " + getName() + " could not find road " + loadData.roads[t]);
   }
   // Load normal signs
   Dictionary laneDictionary = (Dictionary) (dictionaries.get("lane"));
   signs = new Sign[loadData.signs.length];
   for (int t = 0; t < loadData.signs.length; t++)
     signs[t] = getSign(laneDictionary, loadData.signs[t]);
   // Load Signconfigurations
   signconfigs = new Sign[loadData.signconfigs.length][2];
   for (int t = 0; t < signconfigs.length; t++) {
     signconfigs[t] = new Sign[loadData.signconfigs[t].length];
     for (int u = 0; u < signconfigs[t].length; u++) {
       signconfigs[t][u] = getSign(laneDictionary, loadData.signconfigs[t][u]);
     }
   }
   // Tell *all* roads to load themselves
   // It's possible that this Node has a BetaLane that has not been SecondStageLoaded
   // And so we cant do an UpdateLanes() as that one needs secondStageData to proceed.
   // Hence, we need to 2ndStage all Roads.
   Enumeration e = new ArrayEnumeration(allRoads);
   Road tmpRoad;
   while (e.hasMoreElements()) {
     tmpRoad = (Road) e.nextElement();
     if (tmpRoad != null) tmpRoad.loadSecondStage(dictionaries);
   }
   try { // System.out.println("Trying to updateLanes()");
     updateLanes();
   } catch (InfraException x) {
     throw new XMLInvalidInputException("Cannot initialize lanes of node " + nodeId);
   }
 }
Beispiel #4
0
  protected Target[] ownedTargets(Sign tl, int pos, Node des, boolean light) {
    // This method will determine to which destinations you can go starting at this source
    // represented in this QEntry

    CountEntry dummy = new CountEntry(tl, pos, des, light, tl, pos);
    Target[] ownedtargets;
    Vector candidate_targets;
    candidate_targets = new Vector();

    // Use the count table to sort this out, we need all Targets from
    // Only the elements in the count table are used, other  just give a P

    Enumeration _enum = count.elements();
    while (_enum.hasMoreElements()) {
      CountEntry current_entry = (CountEntry) _enum.nextElement();
      if (current_entry.sameSource(dummy) != 0) {
        candidate_targets.addElement(new Target(current_entry.tl_new, current_entry.pos_new));
      }
    }
    ownedtargets = new Target[candidate_targets.size()];
    candidate_targets.copyInto(ownedtargets);
    return ownedtargets;
  }