當前位置: 首頁>>代碼示例>>Java>>正文


Java DirectedGraph類代碼示例

本文整理匯總了Java中org.jgrapht.DirectedGraph的典型用法代碼示例。如果您正苦於以下問題:Java DirectedGraph類的具體用法?Java DirectedGraph怎麽用?Java DirectedGraph使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DirectedGraph類屬於org.jgrapht包,在下文中一共展示了DirectedGraph類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testComplexDag

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
@Test
   public void testComplexDag() {
DirectedGraph<String, DefaultEdge> g = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class);

g.addVertex("a");
g.addVertex("b");
g.addVertex("c");
g.addVertex("d");
g.addVertex("e");
g.addVertex("f");
g.addVertex("g");

g.addEdge("a", "b");
g.addEdge("b", "c");
g.addEdge("c", "d");
g.addEdge("d", "f");
g.addEdge("b", "e");
g.addEdge("e", "f");
g.addEdge("f", "g");
g.addEdge("a", "f");

Assert.assertEquals("b", new TarjanLowestCommonAncestor<String, DefaultEdge>(g).calculate("a", "e", "c"));

   }
 
開發者ID:JanaWengenroth,項目名稱:GKA1,代碼行數:25,代碼來源:TarjanLowestCommonAncestorTest.java

示例2: testAllMissingEntitiesAreExpected

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
private boolean testAllMissingEntitiesAreExpected(final DefinitionModel definition, final Consumer<ErrorModel> errorListner,
    final Map<String, ExpectedModel> missing, final DirectedGraph<BaseInstanceModel, DefaultEdge> entityGraph) {
  //check computed expected are actually expected
  boolean errored = false;
  List<String> expectedMissing = definition.getExpectedDefinitions().stream().map(em -> em.getIdentity())
      .collect(Collectors.toList());
  for (ExpectedModel expected : missing.values()) {
    if (!expectedMissing.contains(expected.getIdentity())) {
      List<AbstractModel> dependsOnMissing = Stream.concat(
          Stream.of(definition), 
          entityGraph.incomingEdgesOf(expected).stream().map(edge -> entityGraph.getEdgeSource(edge))
            .filter(m -> m.getSourceElement().isPresent()))
          .collect(Collectors.toList());
      errored = true;
      errorListner.accept(new ErrorModel(ErrorType.MISSING_BEAN_DEFINITIONS, Arrays.asList(expected), dependsOnMissing));
    } else {
      definition.addComputedExpected(expected);
    }
  }
  return errored;
}
 
開發者ID:salesforce,項目名稱:AptSpring,代碼行數:22,代碼來源:DefinitionContentInspector.java

示例3: getConnectedTo

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
@Override
public Object[] getConnectedTo(Object entity) {
    if (entity instanceof PgStatement){
        DirectedGraph<PgStatement, DefaultEdge> currentGraph = depRes.getOldGraph();
        if (currentGraph != null){
            List<PgStatement> connected = new ArrayList<>();
            for (DefaultEdge e : currentGraph.outgoingEdgesOf((PgStatement)entity)){
                PgStatement connectedVertex = currentGraph.getEdgeTarget(e);
                if (!(connectedVertex instanceof PgColumn)) {
                    connected.add(connectedVertex);
                }
            }
            return connected.toArray();
        }
    }
    return null;
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:18,代碼來源:DepcyGraphView.java

示例4: intersect

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
@Override
public DirectedGraph<Node, Triple> intersect(DirectedGraph<Node, Triple> baseGraph, DirectedGraph<Node, Triple> removalGraph) {
    DirectedGraph<Node, Triple> result = new DirectedSubgraph<>(baseGraph, removalGraph.vertexSet(), removalGraph.edgeSet());

    //Materialize the intersection
    //DirectedGraph<Node, Triple> tmp = createNew();
    //Graphs.addGraph(tmp, result);
    //result = tmp

    return result;
}
 
開發者ID:SmartDataAnalytics,項目名稱:SubgraphIsomorphismIndex,代碼行數:12,代碼來源:SetOpsJGraphTRdfJena.java

示例5: handleChanges

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
private MutableList<ExecuteChangeCommand> handleChanges(MutableCollection<Change> fromSourceList) {
    final MutableList<ExecuteChangeCommand> commands = Lists.mutable.empty();

    DirectedGraph<Change, DefaultEdge> graph = enricher.createDependencyGraph(fromSourceList, false);

    if (graph != null) {
        ConnectivityInspector<Change, DefaultEdge> connectivityInspector
                = new ConnectivityInspector<Change, DefaultEdge>(graph);
        for (Set<Change> connectedSet : connectivityInspector.connectedSets()) {
            // once we have a connectedSet, sort within those changes to ensure that we still sort them in the
            // right order (i.e. via topological sort)
            ImmutableList<Change> fullChanges = sorter.sortChanges(graph, SetAdapter.adapt(connectedSet), SortableDependency.GRAPH_SORTER_COMPARATOR);
            commands.add(changeCommandFactory.createDeployCommand(new GroupChange(fullChanges)));
        }
    }

    return commands;
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:19,代碼來源:StaticDataChangeTypeCommandCalculator.java

示例6: getCycleComponents

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
/**
 * Returns the components of the graph that are cycles.
 * Taken from the implementation of {@link CycleDetector#findCycles()}. (EPL)
 */
private static <T, E> ListIterable<Set<T>> getCycleComponents(final DirectedGraph<T, E> graph) {
    StrongConnectivityInspector<T, E> inspector =
            new StrongConnectivityInspector<T, E>(graph);

    return ListAdapter.adapt(inspector.stronglyConnectedSets()).select(new Predicate<Set<T>>() {
        @Override
        public boolean accept(Set<T> each) {
            if (each.size() > 1) {
                // multi-vertex strongly-connected component is a cycle
                return true;
            }

            // vertex with an edge to itself is a cycle
            T vertex = each.iterator().next();
            return graph.containsEdge(vertex, vertex);
        }
    });
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:23,代碼來源:GraphUtil.java

示例7: sortChanges

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
/**
 * Sorts the graph to provide a consistent topological ordering.
 *
 * @param graph          The input graph
 * @param subsetVertices The subset vertices of the graph we want to sort
 * @param comparator     The comparator on which to order the vertices to guarantee a consistent topological ordering
 */
public <T> ImmutableList<T> sortChanges(DirectedGraph<T, DefaultEdge> graph, RichIterable<T> subsetVertices, Comparator<? super T> comparator) {
    if (subsetVertices.toSet().size() != subsetVertices.size()) {
        throw new IllegalStateException("Unexpected state - have some dupe elements here: " + subsetVertices);
    }

    DirectedGraph<T, DefaultEdge> subsetGraph = new DirectedSubgraph<T, DefaultEdge>(
            graph, subsetVertices.toSet(), null);

    // At one point, we _thought_ that the DirectedSubGraph was dropping vertices that don't have edges, so we
    // manually add them back to the graph to ensure that we can still order them.
    // However, that no longer seems to be the case. We add a check here just in case this comes up again.
    if (subsetVertices.size() != subsetGraph.vertexSet().size()) {
        throw new IllegalArgumentException("This case should never happen! [subsetVertices: " + subsetVertices + ", subsetGraphVertices: " + subsetGraph.vertexSet());
    }

    return sortChanges(subsetGraph, comparator);
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:25,代碼來源:GraphSorter.java

示例8: testSchemaObjectDependencies

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
/**
 * The test data in this class is all written w/ case-sensitivy as the default.
 * If we pass caseInsensitive == true, then we enable that mode in the graph enricher and tweak the object names
 * a bit so that we can verify that the resolution works either way.
 */
public void testSchemaObjectDependencies(boolean caseInsensitive) {
    this.enricher = new GraphEnricherImpl(caseInsensitive ? StringFunctions.toUpperCase() : Functions.getStringPassThru());

    SortableDependencyGroup sch1Obj1 = newChange(schema1, type1, "obj1", Sets.immutable.with("obj3", schema2 + ".obj2"));
    SortableDependencyGroup sch1Obj2 = newChange(schema1, type2, "obj2", Sets.immutable.<String>with());
    // change the case of the object name to ensure others can still point to it
    SortableDependencyGroup sch1Obj3 = newChange(schema1, type1, caseInsensitive ? "obj3".toUpperCase() : "obj3", Sets.immutable.with("obj2"));
    // change the case of the dependency name to ensure that it can point to others
    SortableDependencyGroup sch2Obj1 = newChange(schema2, type1, "obj1", Sets.immutable.with(caseInsensitive ? "obj2".toUpperCase() : "obj2"));
    SortableDependencyGroup sch2Obj2 = newChange(schema2, type2, "obj2", Sets.immutable.with(schema1 + ".obj3"));

    DirectedGraph<SortableDependencyGroup, DefaultEdge> sortGraph = enricher.createDependencyGraph(Lists.mutable.with(
            sch1Obj1, sch1Obj2, sch1Obj3, sch2Obj1, sch2Obj2), false);

    validateChange(sortGraph, sch1Obj1, Sets.immutable.with(sch1Obj3, sch2Obj2), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sch1Obj2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sch1Obj3));
    validateChange(sortGraph, sch1Obj3, Sets.immutable.with(sch1Obj2), Sets.immutable.with(sch1Obj1, sch2Obj2));
    validateChange(sortGraph, sch2Obj1, Sets.immutable.with(sch2Obj2), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sch2Obj2, Sets.immutable.with(sch1Obj3), Sets.immutable.with(sch1Obj1, sch2Obj1));
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:26,代碼來源:GraphEnricherImplTest.java

示例9: testGetChangesCaseInsensitive

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
@Test
public void testGetChangesCaseInsensitive() {
    this.enricher = new GraphEnricherImpl(StringFunctions.toUpperCase());
    String schema1 = "schema1";
    String schema2 = "schema2";
    String type1 = "type1";

    SortableDependencyGroup sp1 = newChange(schema1, type1, "SP1", "n/a", 0, Sets.immutable.with("sp2"));
    SortableDependencyGroup sp2 = newChange(schema1, type1, "SP2", Sets.immutable.<String>with());
    SortableDependencyGroup sp3 = newChange(schema1, type1, "SP3", Sets.immutable.with("sp1", "sp2"));
    SortableDependencyGroup spA = newChange(schema1, type1, "SPA", Sets.immutable.with("sp3"));
    SortableDependencyGroup sp1Schema2 = newChange(schema2, type1, "sp1", "n/a", 0, Sets.immutable.with("sp2", schema1 + ".sp3"));
    SortableDependencyGroup sp2Schema2 = newChange(schema2, type1, "sP2", "n/a", 0, Sets.immutable.<String>with());

    DirectedGraph<SortableDependencyGroup, DefaultEdge> sortGraph = enricher.createDependencyGraph(Lists.mutable.with(
            sp1, sp2, sp3, spA, sp1Schema2, sp2Schema2), false);

    validateChange(sortGraph, sp1, Sets.immutable.with(sp2), Sets.immutable.with(sp3));
    validateChange(sortGraph, sp2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sp1, sp3));
    validateChange(sortGraph, sp3, Sets.immutable.with(sp1, sp2), Sets.immutable.with(spA, sp1Schema2));
    validateChange(sortGraph, spA, Sets.immutable.with(sp3), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sp1Schema2, Sets.immutable.with(sp2Schema2, sp3), Sets.immutable.<SortableDependencyGroup>with());
    validateChange(sortGraph, sp2Schema2, Sets.immutable.<SortableDependencyGroup>with(), Sets.immutable.with(sp1Schema2));
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:25,代碼來源:GraphEnricherImplTest.java

示例10: determineAndSolveConflicts

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
protected static void determineAndSolveConflicts(final PathBlockSet resultBlocks) {
    // determine conflicts
    final PathBlockSet deletedBlocks = new PathBlockSet();
    final DirectedGraph<Block, BlockConflict> blockConflictGraph = new SimpleDirectedGraph<>(BlockConflict::of);
    for (final Block block : resultBlocks.getBlocks()) {
        blockConflictGraph.addVertex(block);
    }
    for (final Block x : blockConflictGraph.vertexSet()) {
        createArcs(blockConflictGraph, resultBlocks, x);
    }
    // solve conflicts
    while (true) {
        final Optional<BlockConflict> mostUsefulConflictsFirst =
                blockConflictGraph.edgeSet().stream().max(Comparator.comparingInt(BlockConflict::getQuality));
        if (!mostUsefulConflictsFirst.isPresent()) {
            break;
        }
        final BlockConflict blockConflict = mostUsefulConflictsFirst.get();
        solveConflict(blockConflict, blockConflictGraph, resultBlocks, deletedBlocks);
    }
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:jamocha,代碼行數:22,代碼來源:PathBlocks.java

示例11: solveConflict

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
protected static void solveConflict(final BlockConflict blockConflict,
        final DirectedGraph<Block, BlockConflict> blockConflictGraph, final PathBlockSet resultBlocks,
        final PathBlockSet deletedBlocks) {
    final Block replaceBlock = blockConflict.getReplaceBlock();
    final Set<FilterInstance> xWOcfi =
            replaceBlock.getFlatFilterInstances().stream().filter(negate(blockConflict.getCfi()::contains))
                    .collect(toSet());
    resultBlocks.remove(replaceBlock);
    // remove replaceBlock and update qualities
    removeArc(blockConflictGraph, blockConflict);
    // find the horizontally maximal blocks within xWOcfi
    final PathBlockSet newBlocks = findAllMaximalBlocksInReducedScope(xWOcfi, new PathBlockSet());
    // for every such block,
    for (final Block block : newBlocks.getBlocks()) {
        if (!deletedBlocks.isContained(block)) {
            if (resultBlocks.addDuringConflictResolution(block)) {
                blockConflictGraph.addVertex(block);
                createArcs(blockConflictGraph, resultBlocks, block);
            }
        }
    }
    deletedBlocks.addDuringConflictResolution(replaceBlock);
}
 
開發者ID:RWTH-i5-IDSG,項目名稱:jamocha,代碼行數:24,代碼來源:PathBlocks.java

示例12: getParameterOrdering

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
private List<Field> getParameterOrdering(DirectedGraph<Field, DefaultEdge> dependencyGraph) {
	CycleDetector<Field, DefaultEdge> cycleDetector = new CycleDetector<Field, DefaultEdge>(dependencyGraph);
	if (cycleDetector.detectCycles()) {
		throw new RuntimeException("Cyclic dependency detected!");
	} else {
		TopologicalOrderIterator<Field, DefaultEdge> orderIterator;
		Field f;
		orderIterator = new TopologicalOrderIterator<Field, DefaultEdge>(dependencyGraph);
	
		List<Field> output = new ArrayList<>(dependencyGraph.vertexSet().size());

		while (orderIterator.hasNext()) {
			f = orderIterator.next();
			output.add(f);
		}

		return output;
	}
}
 
開發者ID:isse-augsburg,項目名稱:minibrass,代碼行數:20,代碼來源:ConfigurationProvider.java

示例13: getAverageTwoTermReliability

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
/**
 * Returns the average two-term reliability (A2TR) of the network. A2TR is computed
 * as the ratio between the number of node-pair for which a path can be found
 * and the same number when the network is connected (<i>Nx(N-1)</i>, where
 * <i>N</i> is the number of nodes in the network). The value is in range [0, 1].
 *
 * @return Average two-term reliability
 */
public double getAverageTwoTermReliability()
{
	if (E == 0) return 0;

	DirectedGraph<Node, Link> graph = getGraph_JGraphT();
	StrongConnectivityInspector<Node, Link> ci = new StrongConnectivityInspector<Node, Link>(graph);
	List<Set<Node>> connectedComponents = ci.stronglyConnectedSets();

	double sum = 0;
	Iterator<Set<Node>> it = connectedComponents.iterator();
	while (it.hasNext())
	{
		int componentSize = it.next().size();
		sum += componentSize * (componentSize - 1);
	}

	return sum / (N * (N - 1));
}
 
開發者ID:girtel,項目名稱:Net2Plan,代碼行數:27,代碼來源:GraphTheoryMetrics.java

示例14: getLinkConnectivity

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
/**
 * <p>Returns the link connectivity. The link connectivity is equal to the smallest
 * number of link-disjoint paths between each node pair.</p>
 *
 * <p>Internally it makes use of the Edmonds-Karp algorithm to compute the maximum
 * flow between each node pair, assuming a link capacity equal to one for every link.</p>
 *
 * @return Link connectivity
 */
public int getLinkConnectivity()
{
	if (E == 0) return 0;

	DirectedGraph<Node, Link> graph = getGraph_JGraphT();
	EdmondsKarpMaximumFlow<Node, Node> ek = new EdmondsKarpMaximumFlow(graph);
	int k = Integer.MAX_VALUE;

	for (Node originNode : nodes)
	{
		for (Node destinationNode : nodes)
		{
			if (originNode.equals(destinationNode)) continue;

			ek.calculateMaximumFlow(originNode, destinationNode);
			k = Math.min(k, ek.getMaximumFlowValue().intValue());

			if (k == 0) break;
		}
	}

	return k == Integer.MAX_VALUE ? 0 : k;
}
 
開發者ID:girtel,項目名稱:Net2Plan,代碼行數:33,代碼來源:GraphTheoryMetrics.java

示例15: getNodeConnectivity

import org.jgrapht.DirectedGraph; //導入依賴的package包/類
/**
 * Returns the node connectivity. The node connectivity is equal to the smallest
 * number of node-disjoint paths between each node pair.
 *
 * <p>Internally it makes use of the (modified) Edmonds-Karp algorithm to compute the maximum
 * flow between each node pair, assuming a link capacity equal to one for every link.</p>
 *
 * @return Node connectivity
 */
public int getNodeConnectivity()
{
	if (E == 0) return 0;
	
	DirectedGraph<Node, Link> graph = getGraph_JGraphT();
	int k = Integer.MAX_VALUE;

	for (Node originNode : nodes)
	{
		for (Node destinationNode : nodes)
		{
			if (originNode.equals(destinationNode)) continue;
			
			DirectedGraph<Node, Link> auxGraph = (DirectedGraph<Node, Link>) JGraphTUtils.buildAuxiliaryNodeDisjointGraph(graph, originNode, destinationNode);
			EdmondsKarpMaximumFlow<Node, Node> ek = new EdmondsKarpMaximumFlow(auxGraph);
			ek.calculateMaximumFlow(originNode, destinationNode);
			k = Math.min(k, ek.getMaximumFlowValue().intValue());

			if (k == 0) break;
		}
	}

	return k == Integer.MAX_VALUE ? 0 : k;
}
 
開發者ID:girtel,項目名稱:Net2Plan,代碼行數:34,代碼來源:GraphTheoryMetrics.java


注:本文中的org.jgrapht.DirectedGraph類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。