Example #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)
	}
Example #2
0
	protected void recalcQa(Sign tl, int pos, Node destination, boolean light, Sign tl_new, int pos_new, PosMov[] posMovs)
	{
		float newQvalue=0;
		int size = tl.getLane().getCompleteLength()-1;
		int R;
		int tlId = tl.getId();
		int desId = destination.getId();
		float Va;

		for(; size>=0; size--) {
			PEntry P = new PEntry(tl, pos, destination, light, tl, size);

			int p_index = p_table[tlId][pos][desId].indexOf(P);
			if(p_index>=0) {
				try {
					P = (PEntry) p_table[tlId][pos][desId].elementAt(p_index);
					Va = va_table[tlId][size][desId];	
					R = rewardFunction(tl_new, pos_new, posMovs);
					newQvalue += P.getValue() *(((float)R) + gamma * Va);
				}
				catch (Exception e) {
					System.out.println("Error in recalc Q'");
				}
			}
		}

		try {
			qa_table[tl.getId()][pos][destination.getId()][light?green_index:red_index] = newQvalue;
		}
		catch (Exception e) {
			System.out.println("ERROR, Zwaluw is not found");
		}
	}
Example #3
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;
  }
Example #4
0
  protected void recalcQ(
      Sign tl,
      int pos,
      Node destination,
      boolean light,
      Sign tl_new,
      int pos_new,
      boolean light_new,
      PosMov[] posMovs) {
    /*  Recalculate the Q values, only one PEntry has changed, meaning also only 1 QEntry has to change
     */

    int R;

    float oldQvalue = 0;
    float Qmark = 0;
    float newQvalue = 0;

    R = rewardFunction(tl_new, pos_new, posMovs);

    try {
      oldQvalue = q_table[tl.getId()][pos][destination.getId()][light ? green_index : red_index];
      Qmark =
          q_table[tl_new.getId()][pos_new][destination.getId()][
              light_new ? green_index : red_index]; // Q( [ tl' , p' ] , L')
    } catch (Exception e) {
      System.out.println("ERROR");
      System.out.println("tl: " + tl.getId());
      System.out.println("pos:" + pos);
      System.out.println("des:" + destination.getId());
    }

    newQvalue = oldQvalue + alpha * (R + gamma * Qmark - oldQvalue);
    q_table[tl.getId()][pos][destination.getId()][light ? green_index : red_index] = newQvalue;
  }
  @Override
  protected void initFlow(HierarchicalConfiguration flowCfg) {
    // int node = flowCfg.getInt("[@node]");

    int inLink = flowCfg.getInt("[@inLink]", -1);
    int outLink = flowCfg.getInt("[@outLink]", -1);

    // int next = flowCfg.getInt("[@next]");
    int no = flowCfg.getInt("[@no]", 0);

    Node node;
    Node next;

    if (inLink != -1) {
      Link link = idToLinkMap.get(Id.create(inLink, Link.class));

      node = link.getFromNode();
      next = link.getToNode();
    } else {
      Link link = idToLinkMap.get(Id.create(outLink, Link.class));

      node = link.getToNode();
      next = link.getFromNode();
    }

    int nodeId = Integer.parseInt(node.getId().toString());
    int nextId = Integer.parseInt(next.getId().toString());

    flows[nodeId] = new MATSimFlow(nodeId, inLink, outLink, nextId, no);
  }
Example #6
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");
		}
	}
Example #7
0
	public float getColearnValue(Sign sign_new, Sign sign, Node destination, int pos)
	{
		int Ktl = sign.getLane().getNumRoadusersWaiting();
		int tlId = sign.getId();
		int desId = destination.getId();
	
		// Calculate the colearning value
		float newCovalue=0;
		int size = sign.getLane().getCompleteLength()-1;

		for(; size>=0; size--) {
			float V;
			PKtlEntry P = new PKtlEntry(sign, 0, destination, green, sign_new, size, Ktl);
			int p_index = pKtl_table[tlId][pos][desId].indexOf(P);
			
			if(p_index>=0) {
				try {
					P = (PKtlEntry) pKtl_table[tlId][pos][desId].elementAt(p_index);
					V = v_table[tlId][size][desId];
					newCovalue += P.getValue() * V;
				}
				catch (Exception e) {
					System.out.println("Error");
				}
			}
		}
		return newCovalue;
	}
Example #8
0
	protected int[] count(Sign tl, int pos, Node destination)
	{
		int tlId = tl.getId();
		int desId = destination.getId();
		int[] counters;
		counters = new int[2];
		
		//See the green_index definitions above !!!!
		counters[green_index] = 0;
		counters[red_index] = 0;
		
		//Calcs the number of entries in the table matching the given characteristics, and returns the count
		int psize = p_table[tlId][pos][desId].size()-1;
		for(; psize>=0; psize--)
		{
			PEntry candidate = (PEntry) p_table[tlId][pos][desId].elementAt(psize);
			if(candidate.tl.getId() == tlId && candidate.pos == pos && candidate.destination.getId() == desId) {
					if(candidate.light == green) {
						counters[green_index]++;
					}
					else {
						counters[red_index]++;
					}
			}
		}
		return counters;
	}
Example #9
0
	protected void recalcVa(Sign tl, int pos, Node destination)
	{
		float newWvalue;
		float qa_red = qa_table[tl.getId()][pos][destination.getId()][red_index];
		float qa_green = qa_table[tl.getId()][pos][destination.getId()][green_index];
		int[] amount = count(tl, pos, destination);
		float total = (float) amount[green_index] + (float) amount[red_index];
		
		newWvalue = ((float)amount[green_index]/(float)total)*qa_green + ((float)amount[red_index]/(float)total)*qa_red;
		
		try {
			va_table[tl.getId()][pos][destination.getId()] = newWvalue;
		}
		catch (Exception e) {
			System.out.println("Error in recalc W");
		}

	}
Example #10
0
	public float getVValue(Sign sign, Node des, int pos)
	{
		try {
			return v_table[sign.getId()][pos][des.getId()];
		}
		catch (Exception e) {
			System.out.print("Error in v_table");
			return 0;
		}
	}
Example #11
0
  @Listen("onClick = #addBtn")
  public void add() throws InterruptedException {
    Node node = nodeList.getSelectedItem().getValue();
    node = nodeDao.loadById(node.getId());
    AbstractQuestionRelation p = (AbstractQuestionRelation) getParent();
    node.getGroups().addAll((p.getQuestion().getAvailableGroups()));
    nodeDao.save(node);

    // update interface
    p.refreshWholePage();
  }
    public NodeData(
        Controller parent,
        Link profileLink,
        String demandStr,
        Double knob,
        Double dpdt,
        Scenario scenario) {

      this.knob = knob;
      this.myNode = profileLink.getBegin_node();
      meas = profileLink;
      feeds = new ArrayList<Link>();
      not_feeds = new ArrayList<Link>();

      //  incoming link sets
      for (int i = 0; i < myNode.getnIn(); i++) {
        Link link = myNode.getInput_link()[i];
        if (link.isFreeway() || link.isHov()) feeds.add(link);
        else not_feeds.add(link);
      }

      // outgoing link sets
      not_meas = new ArrayList<Link>();
      for (int j = 0; j < myNode.getnOut(); j++) {
        Link link = myNode.getOutput_link()[j];
        if (meas != link) not_meas.add(link);
      }

      if (meas == null) return;

      // find the demand profile for the offramp
      measured_flow_profile_veh =
          new BeatsTimeProfileDouble(demandStr, ",", dpdt, 0d, scenario.get.simdtinseconds());
      measured_flow_profile_veh.multiplyscalar(scenario.get.simdtinseconds());

      //            alpha_tilde = new Double[myNode.nIn];

      // create the actuator
      edu.berkeley.path.beats.jaxb.Actuator jaxbA = new edu.berkeley.path.beats.jaxb.Actuator();
      edu.berkeley.path.beats.jaxb.ScenarioElement se =
          new edu.berkeley.path.beats.jaxb.ScenarioElement();
      edu.berkeley.path.beats.jaxb.ActuatorType at =
          new edu.berkeley.path.beats.jaxb.ActuatorType();
      se.setId(myNode.getId());
      se.setType("node");
      at.setId(-1);
      at.setName("cms");
      jaxbA.setId(-1);
      jaxbA.setScenarioElement(se);
      jaxbA.setActuatorType(at);
      cms = new ActuatorCMS(scenario, jaxbA, new BeatsActuatorImplementation(jaxbA, scenario));
      cms.populate(null, null);
      cms.setMyController(parent);
    }
Example #13
0
		public XMLElement saveSelf () throws XMLCannotSaveException
		{ 	XMLElement result=new XMLElement("pval");
			result.addAttribute(new XMLAttribute("tl-id",tl.getId()));
			result.addAttribute(new XMLAttribute("pos",pos));
			result.addAttribute(new	XMLAttribute("destination",destination.getId()));
			result.addAttribute(new XMLAttribute("light",light));
			result.addAttribute(new XMLAttribute("newtl-id",tl_new.getId()));
			result.addAttribute(new XMLAttribute("new-pos",pos_new));
			result.addAttribute(new XMLAttribute("value",value));
	  		return result;
		}
Example #14
0
  public void run() {
    Controller controller = Controller.getController();
    try {
      String ST_OPENING_FILE = controller.getMsgString("ST_OPENING_FILE");
      controller.setStatusMessage(ST_OPENING_FILE);
      try {
        Thread.sleep(10);
      } catch (Exception e) {
        e.printStackTrace();
      }
      controller.setWaitCursors();

      TreeGrowXMLReader xUtil = new TreeGrowXMLReader(m_FileName, true);
      controller.setEditableContributors(new Vector(xUtil.getEditableContributors()));
      xUtil.gatherContent();

      String treeString = xUtil.getTreeStructure();

      ArrayList actualNodes = new ArrayList();
      ArrayList terminalChildrenNodes = new ArrayList();
      Iterator it = xUtil.getNodeList().iterator();
      while (it.hasNext()) {
        Node node = (Node) it.next();
        if (treeString.indexOf("" + node.getId()) != -1) {
          actualNodes.add(node);
        } else {
          terminalChildrenNodes.add(node);
        }
      }
      Tree tree = xUtil.getTree();
      controller.openTreeEditor(tree);
      controller.getTree().setImages(xUtil.getImageList());
      if (prevUploadId != -1) {
        controller.setUploadId(prevUploadId);
      }
      controller.setDefaultCursors();
      controller.getTreeEditor().setToolbarEnabled();
      it = tree.getNodeList().iterator();
      while (it.hasNext()) {
        Node node = (Node) it.next();
        TreePanel.getTreePanel().setNodeComplete(node);
      }
      it = tree.getImages().iterator();
      while (it.hasNext()) {
        NodeImage img = (NodeImage) it.next();
        img.initializeThumbnail();
      }
      controller.setDownloadComplete(true);
    } catch (Exception error) {
      error.printStackTrace();
      controller.setDefaultCursors();
    }
  }
  /** Pull collapsed node bak onto the tree */
  public void undo() {
    if (nodeToCollapse != null) {
      NodeGraveyard.getGraveyard().getNode(nodeToCollapse.getId());
    }

    node.getParent().setChildrenChanged(oldParentHasChanged);
    if (node.getParent().getParent() != null) {
      node.getParent().getParent().setChildrenChanged(oldGrandParentHasChanged);
    }
    TreePanel.getTreePanel().getTree().updateTree(oldTreeString);

    updateTreePanel();
  }
Example #16
0
		public XMLElement saveSelf () throws XMLCannotSaveException
		{ 	XMLElement result=new XMLElement("count");
			result.addAttribute(new XMLAttribute("tl-id",tl.getId()));
			result.addAttribute(new XMLAttribute("pos",pos));
			result.addAttribute(new	XMLAttribute("destination",destination.getId()));
			result.addAttribute(new XMLAttribute("light",light));
			result.addAttribute(new XMLAttribute("newtl-id",tl_new.getId()));
			result.addAttribute(new XMLAttribute("new-pos",pos_new));
			result.addAttribute(new XMLAttribute("ktl",Ktl));
			result.addAttribute(new XMLAttribute("value",value));
			if ( ! infrastructure.laneDictionary.containsKey
			     (new Integer (tl.getId())))
			{     
			     System.out.println
			     ("WARNING : Unknown Trafficlight ID "+tl.getId()+
			      " in TC3$CountEntry. Loading will go wrong");
			}
	  		return result;
		}
Example #17
0
    private Object toJsonCompatible(Object value) {
      if (value instanceof Node) {
        final Node node = (Node) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) node);
        result.put("_id", node.getId());

        final List<String> labelNames = SubGraph.getLabelNames(node);
        if (!labelNames.isEmpty()) result.put("_labels", labelNames);
        return result;
      }
      if (value instanceof Relationship) {
        final Relationship relationship = (Relationship) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) relationship);
        result.put("_id", relationship.getId());
        result.put("_start", relationship.getStartNode().getId());
        result.put("_end", relationship.getEndNode().getId());
        result.put("_type", relationship.getType().name());
        return result;
      }
      if (value instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) value;
        final Map<String, Object> result = new LinkedHashMap<>(map.size());
        for (Map.Entry<String, Object> entry : map.entrySet()) {
          result.put(entry.getKey(), toJsonCompatible(entry.getValue()));
        }
        return result;
      }
      if (value instanceof Iterable) {
        final List<Object> result = new ArrayList<>();
        for (Object inner : (Iterable) value) {
          result.add(toJsonCompatible(inner));
        }
        return result;
      }
      return value;
    }
 public long getId() {
   return theNode.getId();
 }
Example #19
0
  public static void setJar(final Tile node) {
    node.data.put("type", "Jar");
    List<Node> toRemove = new ArrayList<>();
    for (Node n : node.node.getChildren()) {
      if (!n.getId().equals("delete")) {
        if (n.getId().equals("typeLabel")) {
          Label l = (Label) n;
          l.setText("jar");
          l.setTranslateY(l.getTranslateY() - 1);
        } else {
          toRemove.add(n);
        }
      }
    }

    VBox leftPadding = new VBox();
    leftPadding.setPrefWidth(14);
    VBox buttons = new VBox();
    VBox textBoxes = new VBox();
    VBox extra = new VBox();

    buttons.setSpacing(5);
    textBoxes.setSpacing(5);
    extra.setSpacing(5);

    buttons.setPadding(new Insets(7, 0, 0, 0));
    textBoxes.setPadding(new Insets(7, 0, 0, 0));
    extra.setPadding(new Insets(7, 0, 0, 0));

    textBoxes.setTranslateX(17);
    extra.setTranslateX(32);

    node.node.getChildren().removeAll(toRemove);

    final String name = "Package Name";
    final String name2 = "Jar Name";

    Button findPkg = new Button();
    final TextField pkgText = new TextField();
    final TextField jarName = new TextField();

    findPkg.getStyleClass().add("defaultButton");
    findPkg.setText("Find Package Name");
    findPkg.setPrefHeight(25);
    findPkg.setTranslateX(12);

    findPkg.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            String mainClassName = Util.packageNameFromTile();
            if (mainClassName != null) {
              pkgText.setText(mainClassName);
            }
          }
        });

    pkgText.setText(name);
    pkgText.setPrefSize(150, 27);
    pkgText.setFont(Font.font("Segoe UI"));
    pkgText.setId("textBox");
    pkgText
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("package", pkgText.getText().trim());
              }
            });
    pkgText
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && pkgText.getText().equals(name)) {
                  pkgText.setText("");
                } else if (newValue == false && pkgText.getText().trim().equals("")) {
                  pkgText.setText(name);
                }
              }
            });

    jarName.setText(name2);
    jarName.setPrefSize(150, 27);
    jarName.setFont(Font.font("Segoe UI"));
    jarName.setId("textBox");
    jarName
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("jarname", jarName.getText().trim());
              }
            });
    jarName
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && jarName.getText().equals(name2)) {
                  jarName.setText("");
                } else if (newValue == false && jarName.getText().trim().equals("")) {
                  jarName.setText(name2);
                }
              }
            });

    final String defTxt = "Additional Flags";
    final TextField flags = new TextField();
    flags.setText(defTxt);
    flags.setPrefSize(150, 27);
    flags.setFont(Font.font("Segoe UI"));
    flags.setId("textBox");

    flags
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && flags.getText().equals(defTxt)) {
                  flags.setText("");
                } else if (newValue == false && flags.getText().trim().equals("")) {
                  flags.setText(defTxt);
                }
              }
            });
    flags
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("flags", flags.getText().trim());
              }
            });

    final String defTxt2 = "Output Directory";
    final TextField outputDir = new TextField();
    outputDir.setText(defTxt2);
    outputDir.setPrefSize(150, 27);
    outputDir.setFont(Font.font("Segoe UI"));
    outputDir.setId("textBox");

    outputDir
        .focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue == true && outputDir.getText().equals(defTxt2)) {
                  outputDir.setText("");
                } else if (newValue == false && outputDir.getText().trim().equals("")) {
                  outputDir.setText(defTxt2);
                }
              }
            });
    outputDir
        .textProperty()
        .addListener(
            new ChangeListener<String>() {
              @Override
              public void changed(
                  ObservableValue<? extends String> observable, String oldValue, String newValue) {
                node.data.put("output", outputDir.getText().trim());
              }
            });

    buttons.getChildren().addAll(findPkg);
    textBoxes.getChildren().addAll(pkgText, jarName);
    extra.getChildren().addAll(flags, outputDir);
    node.node.getChildren().addAll(leftPadding, buttons, textBoxes, extra);
  }
Example #20
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");
	}