Пример #1
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;
  }
Пример #2
0
	protected void recalcP(Sign tl, int pos, Node destination, boolean light, Sign tl_new, int pos_new, int Ktl)
	{
		int tlId = tl.getId();
		int desId = destination.getId();
		//Update the count table
		CountEntry currentsituation = new  CountEntry(tl, pos, destination, light, tl_new, pos_new, Ktl);
		int count_index = count[tlId][pos][desId].indexOf(currentsituation);
		if (count_index>=0) {
			currentsituation = (CountEntry) count[tlId][pos][desId].elementAt(count_index);
			currentsituation.incrementValue();
		}
		else {
			count[tlId][pos][desId].add(currentsituation);
		}
		//Update the p_table
		PEntry currentchance = new PEntry(tl, pos, destination, light, tl_new, pos_new);		
		
		int dest=0, source=0;
		
		Enumeration enum = count[tlId][pos][desId].elements();
		while(enum.hasMoreElements()) {
			CountEntry current = (CountEntry) enum.nextElement();
			dest += current.sameSourceDifferentKtl(currentsituation);
			source += current.sameSource(currentsituation);
		}
		
		if(source == 0) currentchance.setValue(0);
		else currentchance.setValue((float)dest/(float)source);
		
		int p_index = p_table[tlId][pos][desId].indexOf(currentchance);
		if(p_index>=0) p_table[tlId][pos][desId].setElementAt(currentchance, p_index);
		else { 
			p_table[tlId][pos][desId].add(currentchance);
			p_index = p_table[tlId][pos][desId].indexOf(currentchance);
		}
		
		// Change the rest of the p_table, Also check the other chances for updates
		int size = p_table[tlId][pos][desId].size()-1;
		for(; size>=0; size--) {
			PEntry P = (PEntry) p_table[tlId][pos][desId].elementAt(size);
			float pvalue = P.sameSource(currentsituation);
			if(pvalue > -1.0f) {
				if(size != p_index)
					P.setValue(pvalue * (float)(source-1) / (float)source);
			}
		}

		//update the p'_table ......		
		PKtlEntry currentchance2 = new PKtlEntry(tl, pos, destination, light, tl_new, pos_new, Ktl);
		source=0;

		enum = count[tlId][pos][desId].elements();
		while(enum.hasMoreElements()) {
			source += ((CountEntry) enum.nextElement()).sameSourceWithKtl(currentsituation);
		}
		
		dest = currentsituation.getValue();
		if(source == 0) currentchance2.setValue(0);
		else currentchance2.setValue((float)dest/(float)source);
	
		p_index = pKtl_table[tlId][pos][desId].indexOf(currentchance2);
		if(p_index>=0) pKtl_table[tlId][pos][desId].setElementAt(currentchance2, p_index);
		else {
			pKtl_table[tlId][pos][desId].add(currentchance2);
			p_index = pKtl_table[tlId][pos][desId].indexOf(currentchance2);
		}
		
		// Change the rest of the pKtl_table, Also check the other chances for updates
		size = pKtl_table[tlId][pos][desId].size()-1;
		for(; size>=0; size--) {
			PKtlEntry P = (PKtlEntry) pKtl_table[tlId][pos][desId].elementAt(size);
			float pvalue = P.sameSource(currentsituation);
			if(pvalue > -1) {
				if(size != p_index) {
					P.setValue(pvalue * (float)(source-1) / (float)source);
				}
			}
		}

		if(currentchance.getValue() >1  ||currentchance2.getValue() >1 || currentchance.getValue() <0  ||currentchance2.getValue() <0 )	System.out.println("Serious error !!!!!!!!!1");
	}