Java Code Examples for edu.uci.ics.jung.graph.Graph#findEdge()

The following examples show how to use edu.uci.ics.jung.graph.Graph#findEdge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DependencyGraph.java    From baleen with Apache License 2.0 6 votes vote down vote up
private void addAnnotatorDependencies(
    Graph<AnalysisEngine, Integer> graph, AnalysisEngine ae1, AnalysisEngine ae2) {
  // If there's already a dependency, then just return as we don't want multiple edges
  if (graph.findEdge(ae1, ae2) != null) return;

  // If the inputs of ae1 match the outputs of ae2, then ae1 is dependent on ae2
  // We don't need to check both ways as this will be caught by the loop, although
  // we could be more efficient here.
  AnalysisEngineAction a1 = getAction(ae1);
  AnalysisEngineAction a2 = getAction(ae2);

  if (overlaps(a1.getInputs(), a2.getOutputs())) {
    graph.addEdge(++edgeId, ae2, ae1, EdgeType.DIRECTED);
    return;
  }
}
 
Example 2
Source File: DependencyGraph.java    From baleen with Apache License 2.0 6 votes vote down vote up
/** Find and remove simple loops (e.g. a &rarr; b &rarr; a) from a Jung graph */
public static <V, E> void removeLoops(Graph<V, E> graph) {
  for (V v : graph.getVertices()) {
    for (E e : graph.getOutEdges(v)) {
      V dest = graph.getDest(e);

      E returnEdge = graph.findEdge(dest, v);
      if (returnEdge != null) {
        LOGGER.warn(
            "Loop detected between {} and {}. Original order will be preserved.",
            getName(v),
            getName(dest));
        graph.removeEdge(returnEdge);
      }
    }
  }
}
 
Example 3
Source File: ScanCommunityDetector.java    From topic-detection with Apache License 2.0 6 votes vote down vote up
private boolean isCore(Graph<V,E> g, V seed, ScanCommunityStructure<V, E> cs, int cId){
	Collection<V> neighbors = g.getNeighbors(seed);
	if (neighbors == null)	return false;
	Iterator<V> nIter = neighbors.iterator();
	int count = 0;
	while (nIter.hasNext()){
		V v = nIter.next();
		int cid = cs.getCommunityIndex(v);
		if (cid >= 0 && cid != cId){
			continue;
		}
		E e = g.findEdge(seed, v);
		double ss = ssScorer.getEdgeScore(e);
		if (ss > epsilon){
			count++;
			if (count >= mu){
				return true;
			}
		}
	}
	return false;
}
 
Example 4
Source File: LWPCommunityDetector.java    From topic-detection with Apache License 2.0 6 votes vote down vote up
public LocalModularity getIncrementalLWPModularity(Community<V,E> community, V candMember, LocalModularity mod) {
	int indS0 = mod.getInDegree();
	int outdS0 = mod.getOutDegree();
	
	Graph<V, E> graph = community.getReferenceGraph();
	List<V> communityMembers = community.getMembers();
	int M = community.getNumberOfMembers();
	
	int currentMemberInDegree = 0;
	for (int i = 0; i < M; i++){
		if (graph.findEdge(candMember, communityMembers.get(i))!= null){
			currentMemberInDegree++;
		} 
	}
	/* update out- and in-degree counts of community */
	outdS0 += graph.degree(candMember) - currentMemberInDegree;
	/* in-edges were counted twice so divide by 2 */
	//indS0 += (int)Math.round(currentMemberInDegree/2.0); // this is probably wrong!
	indS0 += currentMemberInDegree;
	
	return new LocalModularity(indS0, outdS0);

}
 
Example 5
Source File: AbstractFunctionGraphTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/** 
 * Finds an edge that represents the given edge, which may no longer exist with 
 * the same (==) edge instances.
 */
private FGEdge getCurrentEdge(FunctionGraph functionGraph, FGEdge edge) {
	FGVertex start = edge.getStart();
	FGVertex end = edge.getEnd();
	Address startAddress = start.getVertexAddress();
	Address endAddress = end.getVertexAddress();
	FGVertex v1 = functionGraph.getVertexForAddress(startAddress);
	FGVertex v2 = functionGraph.getVertexForAddress(endAddress);
	Graph<FGVertex, FGEdge> graph = functionGraph;
	return graph.findEdge(v1, v2);
}
 
Example 6
Source File: AbstractFunctionGraphTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void removeEdge(FunctionGraph functionGraph, Address startAddress,
		Address destinationAddress) {

	Graph<FGVertex, FGEdge> graph = functionGraph;

	FGVertex startVertex = functionGraph.getVertexForAddress(startAddress);
	FGVertex destinationVertex = functionGraph.getVertexForAddress(destinationAddress);

	FGEdge edge = graph.findEdge(startVertex, destinationVertex);
	runSwing(() -> graph.removeEdge(edge));
	FGController controller = getFunctionGraphController();
	controller.repaint();
}
 
Example 7
Source File: AbstractFunctionGraphTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected void verifyEdge(FGVertex start, FGVertex destination) {
	FGData data = getFunctionGraphData();
	FunctionGraph functionGraph = data.getFunctionGraph();
	Graph<FGVertex, FGEdge> graph = functionGraph;

	FGEdge edge = graph.findEdge(start, destination);
	assertNotNull("No edge exists for vertices: " + start + "   and   " + destination, edge);
}
 
Example 8
Source File: ScanCommunityDetector.java    From topic-detection with Apache License 2.0 5 votes vote down vote up
private Stack<V> getEpsilonNeighborhood(Graph<V, E> g, V seed){
	Stack<V> nQ = new Stack<V>();
	Collection<V> neighbors = g.getNeighbors(seed);
	if (neighbors == null)	return nQ;
	Iterator<V> nIter = neighbors.iterator();
	while (nIter.hasNext()){
		V n = nIter.next();
		E e = g.findEdge(seed, n);
		double ss = ssScorer.getEdgeScore(e);
		if (ss > epsilon){
			nQ.push(n);
		}
	}
	return nQ;
}
 
Example 9
Source File: LWPCommunityDetector.java    From topic-detection with Apache License 2.0 5 votes vote down vote up
/**
 * Compute the LPW modularity measure introduced by Luo, Wang and Promislow. This method
 * has been made public so that other algorithms can use the same measure (but a different
 * search strategy).
 * 
 * @param community Input community.
 * @return
 */
public LocalModularity getLWPModularity(Community<V,E> community){
	/* check community validity*/
	if (!community.isValid()) throw new IllegalArgumentException(
			"You should provide a valid community as argument to the algorithm!");

	Graph<V, E> graph = community.getReferenceGraph();
	
	List<V> communityMembers = community.getMembers();
	int M = community.getNumberOfMembers();
	int indS = 0;
	int outdS = 0;
	for (int i = 0; i < M; i++){
		V currentMember = communityMembers.get(i);
		int currentMemberInDegree = 0;
		for (int j = 0; j < M; j++){
			if (i==j) continue;
			if (graph.findEdge(currentMember, communityMembers.get(j))!= null){
				currentMemberInDegree++;
			}
		}
		/* update out- and in-degree counts of community */
		outdS += graph.degree(currentMember) - currentMemberInDegree;
		/* in-edges were counted twice so divide by 2 */
		indS += (int)Math.round(currentMemberInDegree/2.0); 
	}
	return new LocalModularity(indS, outdS);
}