for (V v : h.getVertices()) target.addVertex(v); for (E e : h.getEdges()) ArrayList<V> incident = new ArrayList<V>(h.getIncidentVertices(e)); populateTarget(target, e, incident);
G subgraph = null; try { subgraph = (G) graph.newInstance(); if (!graph.containsVertex(v)) { throw new IllegalArgumentException( "Vertex " + v + " is not an element of " + graph); subgraph.addVertex(v); for (E e : graph.getEdges()) { Collection<V> incident = graph.getIncidentVertices(e); if (vertices.containsAll(incident)) { subgraph.addEdge(e, incident, graph.getEdgeType(e));
private void determineLevel(final int level, final Hypergraph<V, E> graph, final Collection<V> vertices) { for (V eachVertex : vertices) { if (graph.containsVertex(eachVertex)) { levelMap.put(eachVertex, Math.max(level, levelMap.get(eachVertex).intValue())); verticesIndexedSet.add(eachVertex); determineLevel(level + 1, graph, graph.getSuccessors(eachVertex)); } } }
public Double apply(VEPair<V, E> ve_pair) { E e = ve_pair.getE(); V v = ve_pair.getV(); EdgeType edge_type = graph.getEdgeType(e); if (edge_type == EdgeType.UNDIRECTED) return 1.0 / graph.degree(v); if (edge_type == EdgeType.DIRECTED) return 1.0 / graph.outDegree(graph.getSource(e)); throw new IllegalArgumentException("can't handle edge type: " + edge_type); }
for (E e : h.getEdges()) target.addVertex(e); for (V v : h.getVertices()) ArrayList<E> incident = new ArrayList<E>(h.getIncidentEdges(v)); populateTarget(target, v, incident);
/** * Given a vertex, returns the shortest distance from any node in the root set to v * @param g the graph in which the distances are to be measured * @param v the vertex whose distance is to be retrieved * @return the shortest distance from any node in the root set to v */ public int getDistance(Hypergraph<V,E> g, V v) { if (!g.getVertices().contains(v)) { throw new IllegalArgumentException("Vertex is not contained in the graph."); } return distanceDecorator.get(v).intValue(); }
/** * <p>Returns the last edge on a shortest path from <code>source</code> * to <code>target</code>, or null if <code>target</code> is not * reachable from <code>source</code>.</p> * * <p>If either vertex is not in the graph for which this instance * was created, throws <code>IllegalArgumentException</code>.</p> */ public E getIncomingEdge(V source, V target) { if (!g.containsVertex(source)) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (!g.containsVertex(target)) throw new IllegalArgumentException("Specified target vertex " + target + " is not part of graph " + g); Set<V> targets = new HashSet<V>(); targets.add(target); singleSourceShortestPath(source, targets, g.getVertexCount()); Map<V,E> incomingEdgeMap = ((SourcePathData)sourceMap.get(source)).incomingEdges; E incomingEdge = incomingEdgeMap.get(target); if (!cached) reset(source); return incomingEdge; }
/** * Updates the value for this vertex. Called by <code>step()</code>. */ @Override public double update(V v) { collectDisappearingPotential(v); double v_input = 0; for (E e : graph.getInEdges(v)) { // For graphs, the code below is equivalent to // V w = graph.getOpposite(v, e); // total_input += (getCurrentValue(w) * // getEdgeWeight(w,e).doubleValue()); // For hypergraphs, this divides the potential coming from w // by the number of vertices in the connecting edge e. int incident_count = getAdjustedIncidentCount(e); for (V w : graph.getIncidentVertices(e)) { if (!w.equals(v) || hyperedges_are_self_loops) { v_input += (getCurrentValue(w) * getEdgeWeight(w, e).doubleValue() / incident_count); } } } // modify total_input according to alpha double new_value = alpha > 0 ? v_input * (1 - alpha) + getVertexPrior(v) * alpha : v_input; setOutputValue(v, new_value); return Math.abs(getCurrentValue(v) - new_value); }
Map<V,E> currentSourceEdgeMap = new HashMap<V,E>(); for(V vertex : mGraph.getVertices()) { for(E incomingEdge : mGraph.getInEdges(vertex)) for (V neighbor : mGraph.getIncidentVertices(incomingEdge))
if (g.getVertices().contains(source) == false) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (numDests < 1 || numDests > g.getVertexCount()) throw new IllegalArgumentException("numDests must be >= 1 " + "and <= g.numVertices()");
for (E e : graph.getInEdges(v)) for (V w : graph.getIncidentVertices(e)) for (E e : graph.getOutEdges(v)) for (V w : graph.getIncidentVertices(e))
protected void writeEdgeData(Hypergraph<V,E> g, Writer w) throws IOException for (E e: g.getEdges()) Collection<V> vertices = g.getIncidentVertices(e); String id = edge_ids.transform(e); String e_string; e_string += "id=\"" + id + "\" "; EdgeType edge_type = g.getEdgeType(e); if (directed && edge_type == EdgeType.UNDIRECTED) e_string += "directed=\"false\" ";
public T getVertexScore(V v) { if (!graph.containsVertex(v)) throw new IllegalArgumentException("Vertex " + v + " not an element of this graph"); return output.get(v); }
for (V w : g.getIncidentVertices(e))
current_graph.addEdge(current_edge, hyperedge_vertices); hyperedge_vertices.clear(); current_edge = null;
@SuppressWarnings("unchecked") protected void createVertex(Attributes atts) throws SAXNotSupportedException { Map<String, String> vertex_atts = getAttributeMap(atts); String id = vertex_atts.remove("id"); if (id == null) throw new SAXNotSupportedException("node attribute list missing " + "'id': " + atts.toString()); V v = vertex_ids.getKey(id); if (v == null) { if (vertex_factory != null) v = vertex_factory.create(); else v = (V)id; vertex_ids.put(v, id); this.current_graph.addVertex(v); // put remaining attribute/value pairs in vertex_data addExtraData(vertex_atts, vertex_metadata, v); } else throw new SAXNotSupportedException("Node id \"" + id + " is a duplicate of an existing node ID"); this.current_vertex = v; }
/** * Returns the degree of the vertex. * @return the degree of the vertex */ public Integer getVertexScore(V v) { return graph.degree(v); } }
for (E e : h.getEdges()) target.addVertex(e); for (V v : h.getVertices()) ArrayList<E> incident = new ArrayList<E>(h.getIncidentEdges(v)); for (int i = 0; i < incident.size(); i++) for (int j = i+1; j < incident.size(); j++)
/** * Given a vertex, returns the shortest distance from any node in the root set to v * @param v the vertex whose distance is to be retrieved * @return the shortest distance from any node in the root set to v */ public int getDistance(Hypergraph<V,E> g, V v) { if (!g.getVertices().contains(v)) { throw new IllegalArgumentException("Vertex is not contained in the graph."); } return distanceDecorator.get(v).intValue(); }
/** * @see org.apache.commons.collections15.Transformer#transform(java.lang.Object) */ public Double transform(VEPair<V, E> ve_pair) { E e = ve_pair.getE(); V v = ve_pair.getV(); EdgeType edge_type = graph.getEdgeType(e); if (edge_type == EdgeType.UNDIRECTED) return 1.0 / graph.degree(v); if (edge_type == EdgeType.DIRECTED) return 1.0 / graph.outDegree(graph.getSource(e)); throw new IllegalArgumentException("can't handle edge type: " + edge_type); }