org.jgrapht.graph.DefaultDirectedWeightedGraph Java Examples

The following examples show how to use org.jgrapht.graph.DefaultDirectedWeightedGraph. 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: RuleProviderSorter.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Use the jgrapht cycle checker to detect any cycles in the provided dependency graph.
 */
private void checkForCycles(DefaultDirectedWeightedGraph<RuleProvider, DefaultEdge> graph)
{
    CycleDetector<RuleProvider, DefaultEdge> cycleDetector = new CycleDetector<>(graph);

    if (cycleDetector.detectCycles())
    {
        // if we have cycles, then try to throw an exception with some usable data
        Set<RuleProvider> cycles = cycleDetector.findCycles();
        StringBuilder errorSB = new StringBuilder();
        for (RuleProvider cycle : cycles)
        {
            errorSB.append("Found dependency cycle involving: " + cycle.getMetadata().getID()).append(System.lineSeparator());
            Set<RuleProvider> subCycleSet = cycleDetector.findCyclesContainingVertex(cycle);
            for (RuleProvider subCycle : subCycleSet)
            {
                errorSB.append("\tSubcycle: " + subCycle.getMetadata().getID()).append(System.lineSeparator());
            }
        }
        throw new RuntimeException("Dependency cycles detected: " + errorSB.toString());
    }
}
 
Example #2
Source File: GomoryHuTree.java    From JedAIToolkit with Apache License 2.0 5 votes vote down vote up
private DefaultDirectedWeightedGraph<V, DefaultWeightedEdge> makeDirectedCopy(SimpleWeightedGraph<V, E> graph) {
    final DefaultDirectedWeightedGraph<V, DefaultWeightedEdge> copy = new DefaultDirectedWeightedGraph<>(DefaultWeightedEdge.class);

    Graphs.addAllVertices(copy, graph.vertexSet());
    graph.edgeSet().forEach((e) -> {
        V v1 = graph.getEdgeSource(e);
        V v2 = graph.getEdgeTarget(e);
        Graphs.addEdge(copy, v1, v2, graph.getEdgeWeight(e));
        Graphs.addEdge(copy, v2, v1, graph.getEdgeWeight(e));
    });
    
    return copy;
}
 
Example #3
Source File: RuleProviderSorter.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private void addExecuteBeforeRelationship(DefaultDirectedWeightedGraph<RuleProvider, DefaultEdge> graph, RuleProvider provider,
            List<String> errors, Class<? extends RuleProvider> clz)
{
    RuleProvider otherProvider = getByClass(clz);
    if (otherProvider == null)
    {
        errors.add("RuleProvider " + provider.getMetadata().getID() + " is specified to execute before: "
                    + clz.getName() + " but this class could not be found.");
    }
    else
        graph.addEdge(provider, otherProvider);
}
 
Example #4
Source File: RuleProviderSorter.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
private void addExecuteAfterRelationship(DefaultDirectedWeightedGraph<RuleProvider, DefaultEdge> graph, RuleProvider provider,
            List<String> errors, Class<? extends RuleProvider> clz)
{
    RuleProvider otherProvider = getByClass(clz);
    if (otherProvider == null)
    {
        errors.add("RuleProvider " + provider.getMetadata().getID() + " is specified to execute after class: "
                    + clz.getName() + " but this class could not be found.");
    }
    else
        graph.addEdge(otherProvider, provider);
}
 
Example #5
Source File: GraphExpr.java    From symja_android_library with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Test if the graph is instance of <code>DefaultDirectedWeightedGraph</code> or
 * <code>DefaultUndirectedWeightedGraph</code>
 * 
 * @return <code>true</code> if the graph is a weighted graph
 */
public boolean isWeightedGraph() {
	return fData instanceof DefaultDirectedWeightedGraph || fData instanceof DefaultUndirectedWeightedGraph;
}