/** * Creates an instance backed by a new {@code DirectedSparseGraph} instance. */ public DelegateForest() { this(new DirectedSparseGraph<V,E>()); }
/** * create some vertices * @param count how many to create * @return the Vertices in an array */ private void createGraph(int vertexCount) { for (int i = 0; i < vertexCount; i++) { graph.addVertex(i); } int j=0; graph.addEdge(j++, 0, 1, EdgeType.DIRECTED); graph.addEdge(j++, 3, 0, EdgeType.DIRECTED); graph.addEdge(j++, 0, 4, EdgeType.DIRECTED); graph.addEdge(j++, 4, 5, EdgeType.DIRECTED); graph.addEdge(j++, 5, 3, EdgeType.DIRECTED); graph.addEdge(j++, 2, 1, EdgeType.DIRECTED); graph.addEdge(j++, 4, 1, EdgeType.DIRECTED); graph.addEdge(j++, 8, 2, EdgeType.DIRECTED); graph.addEdge(j++, 3, 8, EdgeType.DIRECTED); graph.addEdge(j++, 6, 7, EdgeType.DIRECTED); graph.addEdge(j++, 7, 5, EdgeType.DIRECTED); graph.addEdge(j++, 0, 9, EdgeType.DIRECTED); graph.addEdge(j++, 9, 8, EdgeType.DIRECTED); graph.addEdge(j++, 7, 6, EdgeType.DIRECTED); graph.addEdge(j++, 6, 5, EdgeType.DIRECTED); graph.addEdge(j++, 4, 2, EdgeType.DIRECTED); graph.addEdge(j++, 5, 4, EdgeType.DIRECTED); graph.addEdge(j++, 4, 10, EdgeType.DIRECTED); graph.addEdge(j++, 10, 4, EdgeType.DIRECTED); }
@Override public boolean isDest(V vertex, E edge) { if (!containsEdge(edge) || !containsVertex(vertex)) { return false; } return vertex.equals(this.getEndpoints(edge).getSecond()); }
@Override public Collection<E> getInEdges(V vertex) { if (!containsVertex(vertex)) { return null; } return Collections.unmodifiableCollection(getIncoming_internal(vertex)); }
@Override public Collection<E> getOutEdges(V vertex) { if (!containsVertex(vertex)) { return null; } return Collections.unmodifiableCollection(getOutgoing_internal(vertex)); }
@Override public Collection<V> getSuccessors(V vertex) { if (!containsVertex(vertex)) { return null; } return Collections.unmodifiableCollection(getSuccs_internal(vertex)); }
DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); if (!graph.containsVertex(source)) { System.err.println("Error: source node not found in the graph!"); System.exit(-1); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid));
public static Map<Long, Double> calculatePageRank(Map<Long, LinkedHashMap<Long, Integer>> graphObject) { DirectedSparseGraph<Long, Integer> graph = new DirectedSparseGraph<>(); graphObject.keySet().forEach(n -> graph.addVertex(n)); graph.addEdge(count[0], g, lh); count[0]++; double sum = 0; Set<Long> sortedVerticesSet = new TreeSet<Long>(graph.getVertices()); for (Long v : sortedVerticesSet) { double score = ranker.getVertexScore(v);
private void load() { List<OnmsNode> nodes = nodeDao.findAll(); this.sparseGraph = new DirectedSparseGraph(); PathOutageVertex vertexChild = new PathOutageVertex(node); if (node.getParent() == null) { this.sparseGraph.addVertex(vertexChild); } else { PathOutageVertex vertexParent = new PathOutageVertex(node.getParent()); vertexChild.setParent(vertexParent); this.sparseGraph.addVertex(vertexChild); this.sparseGraph.addVertex(vertexParent); this.sparseGraph.addEdge(new AbstractEdge(NAMESPACE, String.valueOf(edgeID), vertexParent, vertexChild), vertexParent, vertexChild, EdgeType.DIRECTED); edgeID++; for (PathOutageVertex vertex : this.sparseGraph.getVertices()) { Collection<PathOutageVertex> predecessors = this.sparseGraph.getPredecessors(vertex); if (predecessors.isEmpty()) { vertex.setLevel(0); for (AbstractEdge abstractEdge : this.sparseGraph.getEdges()) { this.addEdges(abstractEdge);
DirectedSparseGraph<LocalId,Integer> graph = new DirectedSparseGraph<LocalId, Integer>(); for (LocalId curSource : ills.keySet()){ graph.addVertex(curSource); for (LocalId curDest : ills.get(curSource)){ if (outCounter.get(curSource).get(new Integer(curDest.getLanguage().getId())) <= maxVotesPerLang){ if (totalVotes >= minVotes){ if (counter.get(curDest).get(new Integer(curSource.getLanguage().getId())) <= maxVotesPerLang){ graph.addEdge(edgeCounter++, curSource, curDest);
Object[] edges = g.getEdges().toArray(); for(int i=0; i<edges.length; i++) g.removeEdge(edges[i]); Object[] vers= g.getVertices().toArray(); for(int i=0; i<vers.length; i++) g.removeVertex(vers[i]); g.addVertex(current); todo.add(cons[j]); g.addEdge(new ReteEdge(current, cons[j], false), current, cons[j]); todo.add(cons[j]); g.addEdge(new ReteEdge(current, cons[j], true), current, cons[j]);
public void run(Document document, Map<NamedEntityInText, List<CandidatesScore>> candidatesPerNE) { try { NamedEntitiesInText namedEntities = document.getNamedEntitiesInText(); DirectedSparseGraph<Node, String> graph = new DirectedSparseGraph<Node, String>(); log.info("\tGraph size before BFS: " + graph.getVertexCount()); BreadthFirstSearch bfs = new BreadthFirstSearch(index, algorithm); bfs.run(maxDepth, graph, edgeType, nodeType); log.info("\tGraph size after BFS: " + graph.getVertexCount()); orderedList.addAll(graph.getVertices()); Collections.sort(orderedList); for (NamedEntityInText entity : namedEntities) {
public void run(int maxDepth, DirectedSparseGraph<Node, String> graph, String edgeType, String nodeType) throws UnsupportedEncodingException, IOException { Queue<Node> q = new LinkedList<Node>(); for (Node node : graph.getVertices()) { findNode.put(node.getCandidateURI(), node); q.add(node); q.add(Node); graph.addEdge(graph.getEdgeCount() + ";" + targetNode.getPredicate(), currentNode, Node);
@Override public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType) { this.validateEdgeType(edgeType); Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints); if (new_endpoints == null) return false; V source = new_endpoints.getFirst(); V dest = new_endpoints.getSecond(); if (findEdge(source, dest) != null) return false; edges.put(edge, new_endpoints); if (!vertices.containsKey(source)) this.addVertex(source); if (!vertices.containsKey(dest)) this.addVertex(dest); // map source of this edge to <dest, edge> and vice versa vertices.get(source).getSecond().put(dest, edge); vertices.get(dest).getFirst().put(source, edge); return true; }
/** * create some vertices * @param count how many to create * @return the Vertices in an array */ private String[] createVertices(int count) { String[] v = new String[count]; for (int i = 0; i < count; i++) { v[i] = "V"+i; graph.addVertex(v[i]); } return v; }
Object[] nodes = g.getVertices().toArray(); for(int n=0; n<nodes.length; n++) Object[] edges = g.getInEdges(nodes[n]).toArray(); for(int i=0; i<edges.length; i++) g.removeEdge(edges[i]); edges = g.getOutEdges(nodes[n]).toArray(); for(int i=0; i<edges.length; i++) g.removeEdge(edges[i]); g.removeVertex(nodes[n]);
public boolean removeVertex(V vertex) { if (!containsVertex(vertex)) return false; // copy to avoid concurrent modification in removeEdge ArrayList<E> incident = new ArrayList<E>(getIncoming_internal(vertex)); incident.addAll(getOutgoing_internal(vertex)); for (E edge : incident) removeEdge(edge); vertices.remove(vertex); return true; }
/** * create edges for this demo graph * @param v an array of Vertices to connect */ void createEdges(String[] v) { graph.addEdge(new Double(Math.random()), v[0], v[1], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[0], v[3], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[0], v[4], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[4], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[3], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[1], v[2], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[1], v[4], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[8], v[2], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[3], v[8], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[6], v[7], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[7], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[0], v[9], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[9], v[8], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[7], v[6], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[6], v[5], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[4], v[2], EdgeType.DIRECTED); graph.addEdge(new Double(Math.random()), v[5], v[4], EdgeType.DIRECTED); }
public Collection<V> getNeighbors(V vertex) { if (!containsVertex(vertex)) return null; Collection<V> neighbors = new HashSet<V>(); neighbors.addAll(getPreds_internal(vertex)); neighbors.addAll(getSuccs_internal(vertex)); return Collections.unmodifiableCollection(neighbors); }
public Collection<E> getIncidentEdges(V vertex) { if (!containsVertex(vertex)) return null; Collection<E> incident_edges = new HashSet<E>(); incident_edges.addAll(getIncoming_internal(vertex)); incident_edges.addAll(getOutgoing_internal(vertex)); return Collections.unmodifiableCollection(incident_edges); }