Java Code Examples for org.jgrapht.DirectedGraph#addEdge()

The following examples show how to use org.jgrapht.DirectedGraph#addEdge() . 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: GenerateStratification.java    From BART with MIT License 6 votes vote down vote up
private DirectedGraph<Dependency, DefaultEdge> initDependencyGraph(List<Dependency> dependencies, Map<Dependency, Set<AttributeRef>> affectedAttributes, Map<Dependency, Set<AttributeRef>> queriedAttributes) {
    DirectedGraph<Dependency, DefaultEdge> dependencyGraph = new DefaultDirectedGraph<Dependency, DefaultEdge>(DefaultEdge.class);
    for (Dependency dependency : dependencies) {
        dependencyGraph.addVertex(dependency);
    }
    for (int i = 0; i < dependencies.size(); i++) {
        Dependency d1 = dependencies.get(i);
        for (int j = 0; j < dependencies.size(); j++) {
            if (i == j) {
                continue;
            }
            Dependency d2 = dependencies.get(j);
            if (haveOverlap(d1, d2, affectedAttributes, queriedAttributes)) {
                if (logger.isDebugEnabled()) logger.debug("Edge btw " + d1.getId() + " and " + d2.getId());
                dependencyGraph.addEdge(d1, d2);
            }
        }
    }
    return dependencyGraph;
}
 
Example 2
Source File: ModelAssembler.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private Iterable<SpeciesDescription> getSpeciesInHierarchicalOrder(final ModelDescription model) {
	final DirectedGraph<SpeciesDescription, Object> hierarchy = new SimpleDirectedGraph<>(Object.class);
	final DescriptionVisitor visitor = desc -> {
		if (desc instanceof ModelDescription) { return true; }
		final SpeciesDescription sd = ((SpeciesDescription) desc).getParent();
		if (sd == null || sd == desc) { return false; }
		hierarchy.addVertex((SpeciesDescription) desc);
		if (!sd.isBuiltIn()) {
			hierarchy.addVertex(sd);
			hierarchy.addEdge(sd, (SpeciesDescription) desc);
		}
		return true;
	};
	model.visitAllSpecies(visitor);
	return () -> new TopologicalOrderIterator<>(hierarchy);
}
 
Example 3
Source File: BuildEGDStratification.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
private DirectedGraph<EGDStratum, DefaultEdge> buildEGDStrataGraph(DirectedGraph<ExtendedEGD, DefaultEdge> dependencyGraph, List<EGDStratum> egdStrata) {
    DirectedGraph<EGDStratum, DefaultEdge> strataGraph = new DefaultDirectedGraph<EGDStratum, DefaultEdge>(DefaultEdge.class);
    for (EGDStratum stratum : egdStrata) {
        strataGraph.addVertex(stratum);
    }
    for (EGDStratum stratumA : egdStrata) {
        for (EGDStratum stratumB : egdStrata) {
            if(stratumA.equals(stratumB)){
                continue;
            }
            if (existsPath(dependencyGraph, stratumA, stratumB)) {
                strataGraph.addEdge(stratumA, stratumB);
            }
        }
    }
    return strataGraph;
}
 
Example 4
Source File: BuildTGDStratification.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
private DirectedGraph<TGDStratum, DefaultEdge> buildStrataGraph(DirectedGraph<Dependency, DefaultEdge> dependencyGraph, List<TGDStratum> tgdStrata) {
    DirectedGraph<TGDStratum, DefaultEdge> strataGraph = new DefaultDirectedGraph<TGDStratum, DefaultEdge>(DefaultEdge.class);
    for (TGDStratum stratum : tgdStrata) {
        strataGraph.addVertex(stratum);
    }
    for (TGDStratum stratumA : tgdStrata) {
        for (TGDStratum stratumB : tgdStrata) {
            if(stratumA.equals(stratumB)){
                continue;
            }
            if (existsPath(dependencyGraph, stratumA, stratumB)) {
                strataGraph.addEdge(stratumA, stratumB);
            }
        }
    }
    return strataGraph;
}
 
Example 5
Source File: CheckConflicts.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
private void addEdges(DirectedGraph<AttributeRef, DefaultEdge> dependencyGraph, Dependency extTGD) {
    if (logger.isDebugEnabled()) logger.debug("Analyzing dependency " + extTGD.toLogicalString());
    for (FormulaVariable variable : extTGD.getPremise().getLocalVariables()) {
        if (variable.getConclusionRelationalOccurrences().isEmpty()) {
            continue;
        }
        for (FormulaVariableOccurrence premiseRelationalOccurrence : variable.getPremiseRelationalOccurrences()) {
            AttributeRef premiseNode = getPosition(premiseRelationalOccurrence);
            for (FormulaVariableOccurrence conclusionRelationalOccurrence : variable.getConclusionRelationalOccurrences()) {
                AttributeRef conclusionNode = getPosition(conclusionRelationalOccurrence);
                dependencyGraph.addEdge(premiseNode, conclusionNode);
            }
        }
    }
}
 
Example 6
Source File: BuildTGDStratification.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
private DirectedGraph<Dependency, DefaultEdge> buildChaseGraph(Map<Dependency, Set<Dependency>> affectedDependencies) {
    DirectedGraph<Dependency, DefaultEdge> chaseGraph = new DefaultDirectedGraph<Dependency, DefaultEdge>(DefaultEdge.class);
    for (Dependency tgd : affectedDependencies.keySet()) {
        chaseGraph.addVertex(tgd);
    }
    for (Dependency dependency : affectedDependencies.keySet()) {
        for (Dependency connectedDependency : affectedDependencies.get(dependency)) {
            chaseGraph.addEdge(dependency, connectedDependency);
        }
    }
    return chaseGraph;
}
 
Example 7
Source File: GenerateDOTMojo.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param info
 * @param graph
 */
private void addGraphDependencies(AddonInfo info, DirectedGraph<AddonVertex, AddonDependencyEdge> graph)
{
   AddonId addon = info.getAddon();
   AddonVertex rootVertex = new AddonVertex(addon.getName(), addon.getVersion());
   graph.addVertex(rootVertex);
   for (AddonDependencyEntry entry : info.getDependencyEntries())
   {
      AddonVertex depVertex = new AddonVertex(entry.getName(), entry.getVersionRange().getMax());
      graph.addVertex(depVertex);
      graph.addEdge(rootVertex, depVertex,
               new AddonDependencyEdge(entry.getVersionRange(), entry.isExported(), entry.isOptional()));
   }
}
 
Example 8
Source File: GraphUtils.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * Add dependencies to the given source vertex. Whether duplicates are created is dependent
 * on the underlying {@link DirectedGraph} implementation.
 * @param graph graph to be mutated
 * @param source source vertex of the new edges
 * @param targets target vertices for the new edges
 */
public static <V> void addOutgoingEdges(DirectedGraph<V, DefaultEdge> graph, V source, Set<V> targets) {
    if (!graph.containsVertex(source)) {
        graph.addVertex(source);
    }
    for (V target : targets) {
        if (!graph.containsVertex(target)) {
            graph.addVertex(target);
        }
        graph.addEdge(source, target);
    }
}
 
Example 9
Source File: GraphUtils.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * Add dependents on the give target vertex. Whether duplicates are created is dependent
 * on the underlying {@link DirectedGraph} implementation.
 * @param graph graph to be mutated
 * @param target target vertex for the new edges
 * @param sources source vertices for the new edges
 */
public static <N> void addIncomingEdges(DirectedGraph<N, DefaultEdge> graph, N target, Set<N> sources) {
    if (!graph.containsVertex(target)) {
        graph.addVertex(target);
    }
    for (N source : sources) {
        if (!graph.containsVertex(source)) {
            graph.addVertex(source);
        }
        graph.addEdge(source, target);
    }
}
 
Example 10
Source File: GraphUtils.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * Copy the source graph into the target graph
 */
public static <V> void copyGraph(DirectedGraph<V, DefaultEdge> sourceGraph, DirectedGraph<V, DefaultEdge> targetGraph) {
    addAllVertices(targetGraph, sourceGraph.vertexSet());
    for (DefaultEdge edge : sourceGraph.edgeSet()) {
        targetGraph.addEdge(sourceGraph.getEdgeSource(edge), sourceGraph.getEdgeTarget(edge));
    }
}
 
Example 11
Source File: TridentTopology.java    From jstorm with Apache License 2.0 4 votes vote down vote up
private static void addEdge(DirectedGraph g, Object source, Object target, int index) {
    g.addEdge(source, target, new IndexedEdge(source, target, index));
}