@Test
  public void testSoftDelete() throws Exception {
    Session session = repository.getConnection();
    Node root = session.getRootNode();
    Node folder1 = session.addChildNode(root, "folder1", null, "TestDoc", false);
    Node folder2 = session.addChildNode(root, "folder2", null, "TestDoc", false);
    Node folder3 = session.addChildNode(root, "folder3", null, "TestDoc", false);
    Node folder4 = session.addChildNode(folder1, "folder4", null, "TestDoc", false);
    session.addChildNode(folder4, "folder5", null, "TestDoc", false);
    // create node in folder1
    Node node = session.addChildNode(folder1, "node", null, "TestDoc", false);
    // create version
    Node ver = session.checkIn(node, "foolab1", "desc1");
    // create proxy2 in folder2
    session.addProxy(ver.getId(), node.getId(), folder2, "proxy2", null);
    // create proxy3 in folder3
    session.addProxy(ver.getId(), node.getId(), folder3, "proxy3", null);

    // remove folder2 and contained proxy
    session.removeNode(folder2);
    // remove version
    session.removeNode(ver);
    // remove folder4 and contained folder5
    session.removeNode(folder4);

    RepositoryManagement repoMgmt = RepositoryResolver.getRepository(repository.getName());
    assertEquals(5, repoMgmt.cleanupDeletedDocuments(0, null));
  }
Esempio n. 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");
		}
	}
Esempio n. 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;
  }
Esempio n. 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;
  }
Esempio n. 5
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)
	}
Esempio n. 6
0
  @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);
  }
Esempio n. 7
0
 private void initializeConnectionGenes() {
   this.connections = new Vector<Connection>(this.inputNodes.size() * this.outputNodes.size());
   for (Node inputNode : this.inputNodes) {
     for (Node outputNode : this.outputNodes) {
       this.connections.add(new Connection(inputNode.getId(), outputNode.getId()));
     }
   }
 }
Esempio n. 8
0
 @Override
 public boolean add(Node foo) {
   if (inverse) {
     return ids.remove(foo.getId());
   } else {
     return ids.add(foo.getId());
   }
 }
Esempio n. 9
0
  @Override
  public boolean remove(Object o) {
    Node foo = (Node) o;

    if (inverse) {
      return ids.add(foo.getId());
    } else {
      return ids.remove(foo.getId());
    }
  }
Esempio n. 10
0
  @Override
  public boolean contains(Object o) {
    Node foo = (Node) o;

    if (inverse) {
      return !ids.contains(foo.getId());
    } else {
      return ids.contains(foo.getId());
    }
  }
Esempio n. 11
0
 public Instrument(Node node) {
   Set<Node> children = node.getChildren();
   for (Node child : children) {
     if (child.getId().equals(":bar")) {
       bar = new Bar(child);
     } else if (!child.getId().equals(":")) {
       id = new InstrumentId(child);
     }
   }
 }
Esempio n. 12
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");
		}
	}
  private static Node get(Graph g, Node[][] nodes, Node n0, Node n1) {
    if (nodes[n0.getId()][n1.getId()] == null) {
      Node n = new Node(g);
      String label0 = n0.getStringAttribute("label");
      String label1 = n1.getStringAttribute("label");

      if (label0 == null) {
        label0 = Integer.toString(n0.getId());
      }

      if (label1 == null) {
        label1 = Integer.toString(n1.getId());
      }

      n.setStringAttribute("label", label0 + "+" + label1);

      if (n1.getBooleanAttribute("accepting")) {
        n.setBooleanAttribute("accepting", true);
      }

      return nodes[n0.getId()][n1.getId()] = n;
    }

    return nodes[n0.getId()][n1.getId()];
  }
Esempio n. 14
0
 public Node find(int key) {
   Node current = root;
   while (current.getId() != key) {
     if (current.getId() > key) {
       current = current.getLeftNode();
     } else if (current.getId() < key) {
       current = current.getRightNode();
     }
     if (current == null) {
       return null;
     }
   }
   return current;
 }
Esempio n. 15
0
  public static void main() {

    // fetch the first node
    Node initialNode = scanner.bigGraphOfJustice.getNode(0);

    // initialize all edges to undiscovered
    Arrays.fill(state, UNDISCOVERED);

    // start DFS
    // DFS uses Stack data structure
    Stack<Node> dfsStack = new Stack<Node>();

    dfsStack.push(initialNode);
    state[initialNode.getId()] = VISITED;

    // while we have a stack
    while (dfsStack.isEmpty() == false) {

      Node currentNode = (Node) dfsStack.peek();
      state[currentNode.getId()] = DISCOVERED;

      // visit child
      Node child = getUnvisitedChild(currentNode);
      // if it exists
      if (child != null) {
        state[child.getId()] = VISITED;

        // if a self loop is discovered, print 0. we've found the easy case
        if (child == currentNode) {
          // add one to the length to account for traversing the child and print
          System.out.println("0");
          System.exit(0);
        }

        // the child is not the one, put it in the pile with the others
        dfsStack.push(child);
      }

      // if the node has no children of their own, discard it off the stack
      // get one who might yet yield results off the pile of children
      else {
        dfsStack.pop();
      }
    }

    // there was nothing at all, no loops
    System.out.println("1");
  }
Esempio n. 16
0
  public Node DFS() {
    boolean found;
    Math math;
    int tmp;
    math = new Math();
    found = false;
    currVal = 0;
    while (!found) {
      System.out.println(currNode.getId());
      if (math.equal(currNode.getVal(), value)) {
        found = true;
      } else {
      }

      if (!found && math.equal(currVal, currNode.getNumChilds())) {
        if (stack.isEmpty()) {
          found = true;
        } else {
          currNode = currNode.getParent();
          currVal = stack.pop();
        }
      } else if (!found) {
        tmp = currNode.getNode(currVal).setParent(currNode);
        currNode = currNode.getNode(currVal);

        currVal = currVal + 1;
        tmp = stack.push(currVal);
        currVal = 0;
      } else {
      }
    }

    return currNode;
  }
Esempio n. 17
0
 /**
  * Checks if list of nodes has cycles. If the length of list has no HEAD node, then the cycle
  * exist in the list. HEAD node is the node, which doesn't point for any other node.
  *
  * @param nodes
  * @throws NodeException thrown when list of nodes has cycles
  */
 public void validateCycles(List<Node> nodes) throws NodeException {
   // Checking if head of graph exist
   boolean headExist = false;
   for (Node n : nodes) if (n.getId().equals(n.getPredecessorId())) headExist = true;
   // if no, exception is thrown
   if (!headExist && !nodes.isEmpty()) throw new NodeException(NodeErrorCode.CYCLE);
 }
Esempio n. 18
0
  /**
   * two nodes, my is unmodified, their is updated and has a higher version => their version is
   * going to be the merged version
   */
  @Test
  public void nodeSimple_locallyUnmodifiedNoConflict() {
    Node n = new Node(new LatLon(0, 0));
    n.setOsmId(1, 1);
    n.setModified(false);
    n.put("key1", "value1");
    my.addPrimitive(n);

    Node n1 = new Node(new LatLon(0, 0));
    n1.setOsmId(1, 2);
    n1.setModified(false);
    n1.put("key1", "value1-new");
    n1.put("key2", "value2");
    their.addPrimitive(n1);

    DataSetMerger visitor = new DataSetMerger(my, their);
    visitor.merge();

    Node n2 = (Node) my.getPrimitiveById(1, OsmPrimitiveType.NODE);
    assertTrue(visitor.getConflicts().isEmpty());
    assertSame(n, n2); // make sure the merged node is still the original node
    assertSame(n2.getDataSet(), my);
    assertEquals(1, n2.getId());
    assertEquals(2, n2.getVersion());
    assertFalse(n2.isModified());
    assertEquals("value1-new", n2.get("key1"));
    assertEquals("value2", n2.get("key2"));

    // the merge target should not be modified
    assertFalse(n2.isModified());
  }
Esempio n. 19
0
  /**
   * two identical nodes, even in id and version. No confict expected.
   *
   * <p>Can happen if data is loaded in two layers and then merged from one layer on the other.
   */
  @Test
  public void nodeSimple_IdenticalNoConflict() {
    Node n = new Node(new LatLon(0, 0));
    n.setOsmId(1, 1);
    n.setModified(false);
    n.put("key1", "value1");
    my.addPrimitive(n);

    Node n1 = new Node(new LatLon(0, 0));
    n1.setOsmId(1, 1);
    n1.setModified(false);
    n1.put("key1", "value1");
    their.addPrimitive(n1);

    DataSetMerger visitor = new DataSetMerger(my, their);
    visitor.merge();

    Node n2 = (Node) my.getPrimitiveById(1, OsmPrimitiveType.NODE);
    assertTrue(visitor.getConflicts().isEmpty());
    assertNotSame(n1, n2); // make sure we have a clone
    assertEquals(1, n2.getId());
    assertEquals(1, n2.getVersion());
    assertFalse(n2.isModified());
    assertEquals("value1", n2.get("key1"));

    // merge target not modified after merging
    assertFalse(n2.isModified());
  }
  public void getRequestToken(Message msg) {
    if (msg.getMessageType() != MTRequest) {
      System.err.println("??? (getRequestToken)");
      return;
    }

    int originator = Integer.parseInt(msg.getParam());
    try {
      this.mutex.acquire();

      if (this.parent == -1) {
        if (holding) {
          node.send(MTToken, originator, "");
          this.holding = false;
        } else {
          this.deferred = originator;
        }
      } else {
        node.send(MTRequest, parent, msg.getParam());
      }
      this.parent = msg.getSource();

      this.mutex.release();
    } catch (InterruptedException ex) {
      System.err.println("Error (getRequestToken " + node.getId() + "): " + ex.getMessage());
    }
  }
Esempio n. 21
0
 /**
  * Serialize all nodes in the non-dense format.
  *
  * @param parentbuilder Add to this PrimitiveBlock.
  */
 public Osmformat.PrimitiveGroup serializeNonDense() {
   if (contents.size() == 0) {
     return null;
   }
   // System.out.format("%d Nodes   ",nodes.size());
   StringTable stable = serializer.getStringTable();
   Osmformat.PrimitiveGroup.Builder builder = Osmformat.PrimitiveGroup.newBuilder();
   for (Node i : contents) {
     long id = i.getId();
     int lat = mapDegrees(i.getLat());
     int lon = mapDegrees(i.getLon());
     Osmformat.Node.Builder bi = Osmformat.Node.newBuilder();
     bi.setId(id);
     bi.setLon(lon);
     bi.setLat(lat);
     Iterator<Element.Tag> tags = i.tagsIterator();
     while (tags.hasNext()) {
       Element.Tag t = tags.next();
       bi.addKeys(stable.getIndex(t.getKey()));
       bi.addVals(stable.getIndex(t.getValue()));
     }
     if (!omit_metadata) {
       bi.setInfo(serializeMetadata(i));
     }
     builder.addNodes(bi);
   }
   return builder.build();
 }
Esempio n. 22
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;
	}
Esempio n. 23
0
 public void insert(int id, String data) {
   // 1.创建新节点
   Node newNode = new Node(id, data);
   if (root == null) {
     root = newNode;
   } else {
     // 2.查找插入位置
     Node current = root;
     Node parent = null;
     while (true) {
       parent = current;
       if (id < current.getId()) {
         current = current.getLeftNode();
         if (current == null) {
           // 3.修改节点属性
           parent.setLeftNode(newNode);
           return;
         }
       } else {
         current = current.getRightNode();
         if (current == null) {
           // 3.修改节点属性
           parent.setRightNode(newNode);
           return;
         }
       }
     }
   }
 }
Esempio n. 24
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;
	}
Esempio n. 25
0
 private static void printDescendents(Node n, int padding) {
   int i;
   for (i = 0; i < padding; i++) System.out.print("  ");
   System.out.println("Node id : " + n.getId() + " children : " + n.numChildren());
   for (i = 0; i < n.numChildren(); i++) {
     printDescendents(n.getChild(i), padding + 2);
   }
 }
Esempio n. 26
0
 public Bar(Node node) {
   Set<Node> children = node.getChildren();
   for (Node child : children) {
     if (child.getId().equals(":beats")) {
       beats = new Beats(child);
     }
   }
 }
  public void preprotocol() {
    try {
      this.mutex.acquire();
      if (!this.holding) {
        node.send(MTRequest, parent, String.valueOf(node.getId()));
        this.parent = -1;
        this.mutex.release();
        this.token.acquire();
        this.mutex.acquire();
      }

      this.holding = false;
      this.mutex.release();
    } catch (InterruptedException ex) {
      System.err.println("Error (preprotocol " + node.getId() + "): " + ex.getMessage());
    }
  }
Esempio n. 28
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");
		}

	}
Esempio n. 29
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof Node)) return false;

    Node<?> node = (Node<?>) o;

    if (getId() != node.getId()) return false;
    return !(getData() != null ? !getData().equals(node.getData()) : node.getData() != null);
  }
Esempio n. 30
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;
		}
	}