本文整理匯總了Java中org.jgrapht.DirectedGraph.vertexSet方法的典型用法代碼示例。如果您正苦於以下問題:Java DirectedGraph.vertexSet方法的具體用法?Java DirectedGraph.vertexSet怎麽用?Java DirectedGraph.vertexSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jgrapht.DirectedGraph
的用法示例。
在下文中一共展示了DirectedGraph.vertexSet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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);
}
}
示例4: findReachableSourceAttributes
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
private Set<AttributeRef> findReachableSourceAttributes(AttributeRef targetAttribute, DirectedGraph<AttributeRef, DefaultEdge> dependencyGraph) {
Set<AttributeRef> result = new HashSet<AttributeRef>();
for (AttributeRef attribute : dependencyGraph.vertexSet()) {
if (!attribute.isSource()) {
continue;
}
if (result.contains(attribute)) {
continue;
}
List path = DijkstraShortestPath.findPathBetween(dependencyGraph, attribute, targetAttribute);
if (path != null) {
result.add(attribute);
}
}
return result;
}
示例5: collapseGraph
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
public DirectedGraph<FunctionVertex, CallEdge> collapseGraph() {
DirectedGraph<FunctionVertex, CallEdge> g = cloneGraph(graph);
List<FunctionVertex> vToRemove = new ArrayList<>();
for (int i = 0; i < 10; i++) {
vToRemove.clear();
/* remove all vertrtices with zero stack and no childs */
for (FunctionVertex fn : g.vertexSet()) {
Set<CallEdge> oe = g.outgoingEdgesOf(fn);
if (oe.isEmpty() && fn.stack == 0) {
vToRemove.add(fn);
}
}
g.removeAllVertices(vToRemove);
}
for (int i = 0; i < 1000; i++) {
traverseMaxStack(g);
}
return g;
}
示例6: createPackageVerticesMap
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
private Map<String, Set<InfoVertex<T, C>>> createPackageVerticesMap(
DirectedGraph<InfoVertex<T, C>, DependencyEdge> graph) {
final Map<String, Set<InfoVertex<T, C>>> packageVerticesMap = new HashMap<String, Set<InfoVertex<T, C>>>();
for (InfoVertex<T, C> vertex : graph.vertexSet()) {
final MPackageInfo packageInfo = vertex.getPackageInfo();
if (packageInfo != null) {
Set<InfoVertex<T, C>> packageVertices = packageVerticesMap
.get(packageInfo.getPackageName());
if (packageVertices == null) {
packageVertices = new HashSet<InfoVertex<T, C>>();
packageVerticesMap.put(packageInfo.getPackageName(),
packageVertices);
}
packageVertices.add(vertex);
}
}
return packageVerticesMap;
}
示例7: SSA
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
protected SSA(DirectedGraph<V, E> graph, Dominators<V, E> dom) {
if (!(graph instanceof CFG)) {
throw new IllegalArgumentException();
}
this.cfg = (CFG) graph;
this.dom = dom;
this.domFrontier = dom.getDF();
this.cdgTree = new SSAGraph<>();
for (V v : graph.vertexSet()) {
cdgTree.addVertex(v);
}
for (E e : graph.edgeSet()) {
cdgTree.addEdge(graph.getEdgeSource(e), graph.getEdgeTarget(e));
}
this.cdgBlockTree = new SSABlockTree<>(this.cdgTree, dom.getStart());
// gather variables
discoverVariables();
//this.count = new int[variables.size()];
this.count = new HashMap<>(variables.size());
this.stack = new HashMap<>(variables.size());
// for each variable a
for (int i : variables) {
//count[i] = 0;
count.put(i, 0);
stack.put(i, new LinkedList<Integer>());
stack.get(i).add(0); // push 0 onto Stack[a]
}
}
示例8: write
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
public static <V, E> void write(DirectedGraph<V, E> g, String fileName) throws FileNotFoundException {
try (PrintWriter out = new PrintWriter(fileName)) {
out.print("digraph \"DirectedGraph\" { \n graph [label=\"");
out.print(g.toString());
out.print("\", labelloc=t, concentrate=true]; ");
out.print("center=true;fontsize=12;node [fontsize=12];edge [fontsize=12]; \n");
for (V node : g.vertexSet()) {
out.print(" \"");
out.print(getId(node));
out.print("\" ");
out.print("[label=\"");
out.print(node.toString());
out.print("\" shape=\"box\" color=\"blue\" ] \n");
}
for (V src : g.vertexSet()) {
for (E e : g.outgoingEdgesOf(src)) {
V tgt = g.getEdgeTarget(e);
out.print(" \"");
out.print(getId(src));
out.print("\" -> \"");
out.print(getId(tgt));
out.print("\" ");
out.print("[label=\"");
out.print(e.toString());
out.print("\"]\n");
}
}
out.print("\n}");
out.flush();
}
}
示例9: findAttributes
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
public AttributesInSameCellGroups findAttributes(DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph) {
AttributesInSameCellGroups attributesInSameCallGroups = new AttributesInSameCellGroups();
Set<String> pathCache = new HashSet<String>();
for (AttributeRef attributeRef : dependencyGraph.vertexSet()) {
Set<AttributeRef> relatedAttributes = findRelatedAttributes(attributeRef, pathCache, dependencyGraph);
attributesInSameCallGroups.addAttribute(attributeRef, relatedAttributes);
}
if (logger.isDebugEnabled()) logger.debug("Map for dependency graph " + dependencyGraph + "\n:" + attributesInSameCallGroups.toString());
return attributesInSameCallGroups;
}
示例10: findRelatedAttributes
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
private Set<AttributeRef> findRelatedAttributes(AttributeRef attribute, Set<String> pathCache, DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph) {
//All attributes corresponding to vertices of paths that pass throught the vertex of attribute
Set<AttributeRef> result = new HashSet<AttributeRef>();
for (AttributeRef otherAttribute : dependencyGraph.vertexSet()) {
if (attribute.equals(otherAttribute)) {
result.add(otherAttribute);
continue;
}
String attributePair = buildAttributePair(attribute, otherAttribute);
if (pathCache.contains(attributePair)) {
result.add(otherAttribute);
continue;
}
List<ExtendedEdge> outPath = DijkstraShortestPath.findPathBetween(dependencyGraph, attribute, otherAttribute);
if (logger.isDebugEnabled()) logger.debug("Finding path between " + attribute + " and " + otherAttribute);
if (outPath != null) {
if (logger.isDebugEnabled()) logger.debug("Path found");
addVerticesInPath(outPath, result, pathCache, dependencyGraph);
continue;
}
List<ExtendedEdge> inPath = DijkstraShortestPath.findPathBetween(dependencyGraph, otherAttribute, attribute);
if (logger.isDebugEnabled()) logger.debug("Finding path between " + otherAttribute + " and " + attribute);
if (inPath != null) {
if (logger.isDebugEnabled()) logger.debug("Path found");
addVerticesInPath(inPath, result, pathCache, dependencyGraph);
}
}
return result;
}
示例11: findReachableAttribuesOnGraph
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
private Set<AttributeRef> findReachableAttribuesOnGraph(Set<AttributeRef> initialAttributes, DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph) {
Set<AttributeRef> result = new HashSet<AttributeRef>(initialAttributes);
for (AttributeRef attribute : dependencyGraph.vertexSet()) {
if (result.contains(attribute)) {
continue;
}
if (isReachable(attribute, initialAttributes, dependencyGraph)) {
result.add(attribute);
}
}
return result;
}
示例12: traverseMaxStack
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
private void traverseMaxStack(DirectedGraph<FunctionVertex, CallEdge> g) {
int maxStack, fnStack;
for (FunctionVertex fn : g.vertexSet()) {
Set<CallEdge> ces = g.outgoingEdgesOf(fn);
if (ces.isEmpty()) {
if (fn.stack >= 0) {
fn.maxStack = fn.stack;
} else {
fn.maxStack = 0;
}
continue;
}
maxStack = -1;
for (CallEdge ce : ces) {
fnStack = g.getEdgeTarget(ce).maxStack;
if (fnStack >= 0) {
maxStack = Math.max(maxStack, fnStack);
} else {
maxStack = -1;
break;
}
}
if (maxStack >= 0) {
if (isRecursive(fn)) {
} else {
fn.maxStack = maxStack + fn.stack;
}
} else if (isRecursive(fn)) {
fn.maxStack = fn.stack;
}
}
}
示例13: cloneGraph
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
private static DirectedGraph<FunctionVertex, CallEdge> cloneGraph(DirectedGraph<FunctionVertex, CallEdge> g) {
DirectedGraph<FunctionVertex, CallEdge> result;
result = new DefaultDirectedGraph<>(CallEdge.class);
List<FunctionVertex> list = new ArrayList<>();
for (FunctionVertex v : g.vertexSet()) {
FunctionVertex v2 = new FunctionVertex();
v2.clone(v);
list.add(v2);
result.addVertex(v2);
}
list.indexOf(g);
FunctionVertex src;
FunctionVertex dst;
for (CallEdge e : g.edgeSet()) {
src = g.getEdgeSource(e);
dst = g.getEdgeTarget(e);
/* get clonned vertex */
src = list.get(list.indexOf(src));
dst = list.get(list.indexOf(dst));
result.addEdge(src, dst, new CallEdge(e.type));
}
return result;
}
示例14: NetworkFlow
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
public NetworkFlow(DirectedGraph<V, E> graph) {
// init the flow graph
this.graph = graph;
this.vertices = graph.vertexSet();
this.numOfEdges = graph.edgeSet().size();
this.maximumFlow = new HashMap<E, Double>();
}
示例15: LinearProgrammingMaxFlow
import org.jgrapht.DirectedGraph; //導入方法依賴的package包/類
public LinearProgrammingMaxFlow(DirectedGraph<V, E> graph) {
this.graph = graph;
this.vertices = graph.vertexSet();
this.edgesIndex = new ArrayList<E>();
this.numOfEdges = graph.edgeSet().size();
this.maximumFlow = new HashMap<E, Double>();
}