本文整理汇总了Java中org.jgrapht.DirectedGraph.getEdgeTarget方法的典型用法代码示例。如果您正苦于以下问题:Java DirectedGraph.getEdgeTarget方法的具体用法?Java DirectedGraph.getEdgeTarget怎么用?Java DirectedGraph.getEdgeTarget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.DirectedGraph
的用法示例。
在下文中一共展示了DirectedGraph.getEdgeTarget方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
示例3: shortestCycle
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private static List<String> shortestCycle(DirectedGraph<String, DefaultEdge> graph)
{
FloydWarshallShortestPaths<String, DefaultEdge> floyd = new FloydWarshallShortestPaths<>(graph);
int minDistance = Integer.MAX_VALUE;
String minSource = null;
String minDestination = null;
for (DefaultEdge edge : graph.edgeSet()) {
String src = graph.getEdgeSource(edge);
String dst = graph.getEdgeTarget(edge);
int dist = (int) Math.round(floyd.shortestDistance(dst, src)); // from dst to src
if (dist < 0) {
continue;
}
if (dist < minDistance) {
minDistance = dist;
minSource = src;
minDestination = dst;
}
}
if (minSource == null) {
return null;
}
GraphPath<String, DefaultEdge> shortestPath = floyd.getShortestPath(minDestination, minSource);
List<String> pathVertexList = Graphs.getPathVertexList(shortestPath);
// note: pathVertexList will be [a, a] instead of [a] when the shortest path is a loop edge
if (!Objects.equals(shortestPath.getStartVertex(), shortestPath.getEndVertex())) {
pathVertexList.add(pathVertexList.get(0));
}
return pathVertexList;
}
示例4: testThreeNodes
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
@Test public void testThreeNodes() {
final Map<String, NodeDescriptor> map = toMap(ImmutableSet.of("1", "2", "3"),
input -> new NodeDescriptor(input, NodeType.UNKNOWN,
Collections.emptySet()));
final Set<NodeDescriptor> identities = ImmutableSet.copyOf(map.values());
final DirectedGraph<String, DefaultEdge> graph = processor.createGraphFrom(identities);
map.keySet().forEach(nodeId -> {
assertThat(graph.containsVertex(nodeId)).isTrue();
assertThat(graph.inDegreeOf(nodeId)).isEqualTo(1);
assertThat(graph.outDegreeOf(nodeId)).isEqualTo(1);
assertThat(graph.getEdge(nodeId, nodeId)).isNull();
});
final String start = map.keySet().stream().findAny().get();
String current = start;
int counter = 0;
do {
final Set<DefaultEdge> outEdges = graph.outgoingEdgesOf(current);
assertThat(outEdges).hasSize(1);
current = graph.getEdgeTarget(getOnlyElement(outEdges));
counter++;
} while (!Objects.equals(current, start));
assertThat(counter).isEqualTo(3);
}
示例5: addSatisfiedStratum
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
public void addSatisfiedStratum(TGDStratum tgdStratum) {
this.unsatisfiedStrataLock.lock();
try {
if (logger.isDebugEnabled()) logger.debug("** Stratum satisfied: " + tgdStratum);
this.unsatisfiedStrata.remove(tgdStratum);
this.unsatisfiedStrataCondition.signalAll();
DirectedGraph<TGDStratum, DefaultEdge> strataGraph = scenario.getStratification().getTgdStrataGraph();
for (DefaultEdge outEdge : strataGraph.outgoingEdgesOf(tgdStratum)) {
TGDStratum nextStratum = strataGraph.getEdgeTarget(outEdge);
this.startThreadForTGDStratum(nextStratum);
}
} finally {
this.unsatisfiedStrataLock.unlock();
}
}
示例6: addSatisfiedStratum
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
public void addSatisfiedStratum(EGDStratum egdStratum) {
this.unsatisfiedStrataLock.lock();
try {
if (logger.isDebugEnabled()) logger.debug("** Stratum satisfied: " + egdStratum);
this.unsatisfiedStrata.remove(egdStratum);
this.unsatisfiedStrataCondition.signalAll();
DirectedGraph<EGDStratum, DefaultEdge> strataGraph = scenario.getStratification().getEgdStrataGraph();
for (DefaultEdge outEdge : strataGraph.outgoingEdgesOf(egdStratum)) {
EGDStratum nextStratum = strataGraph.getEdgeTarget(outEdge);
this.startThreadForEGDStratum(nextStratum);
}
} finally {
this.unsatisfiedStrataLock.unlock();
}
}
示例7: 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;
}
}
}
示例8: 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;
}
示例9: getDirectDependencies
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
public Collection<MappingDependency<T, C>> getDirectDependencies() {
final Map<MPackageInfo, MappingDependency<T, C>> dependencies = new HashMap<MPackageInfo, MappingDependency<T, C>>();
final DirectedGraph<InfoVertex<T, C>, DependencyEdge> graph = analyzer
.getGraph();
final Collection<InfoVertex<T, C>> vertices = new HashSet<InfoVertex<T, C>>(
getInfoVertices());
for (InfoVertex<T, C> sourceVertex : vertices) {
final Set<DependencyEdge> edges = graph
.outgoingEdgesOf(sourceVertex);
for (DependencyEdge edge : edges) {
if (edge.getType() == DependencyType.HARD) {
final InfoVertex<T, C> targetVertex = graph
.getEdgeTarget(edge);
final MPackageInfo packageInfo = targetVertex
.getPackageInfo();
// If this another package (not this package and not the
// built-in package)
if (packageInfo != null
&& !this.packageInfo.equals(packageInfo)) {
MappingDependency<T, C> dependency = dependencies
.get(packageInfo);
if (dependency == null) {
dependency = new MappingDependency<T, C>(
packageInfo);
dependencies.put(packageInfo, dependency);
}
dependency.addInfoVertex(targetVertex);
}
}
}
}
return dependencies.values();
}
示例10: includeInfoVertex
import org.jgrapht.DirectedGraph; //导入方法依赖的package包/类
private void includeInfoVertex(final InfoVertex<T, C> initialVertex) {
logger.trace(MessageFormat.format("Including the vertex [{0}].",
initialVertex));
final DirectedGraph<InfoVertex<T, C>, DependencyEdge> graph = analyzer
.getGraph();
final SortedMap<ContainmentType, Deque<InfoVertex<T, C>>> deques = new TreeMap<ContainmentType, Deque<InfoVertex<T, C>>>();
deques.put(ContainmentType.INCLUDED_EXPLICITLY,
new LinkedList<InfoVertex<T, C>>());
deques.put(ContainmentType.INCLUDED_AS_HARD_DEPENDENCY,
new LinkedList<InfoVertex<T, C>>());
deques.put(ContainmentType.INCLUDED_AS_SOFT_DEPENDENCY,
new LinkedList<InfoVertex<T, C>>());
deques.get(ContainmentType.INCLUDED_EXPLICITLY).add(initialVertex);
for (Map.Entry<ContainmentType, Deque<InfoVertex<T, C>>> dequeEntry : deques
.entrySet()) {
final ContainmentType dequeContainmentType = dequeEntry.getKey();
final Deque<InfoVertex<T, C>> deque = dequeEntry.getValue();
while (!deque.isEmpty()) {
final InfoVertex<T, C> sourceVertex = deque.removeFirst();
final ContainmentType currentSourceContainmentType = getInfoVertexContainmentType(sourceVertex);
final ContainmentType sourceContainmentType = dequeContainmentType
.combineWith(currentSourceContainmentType);
if (currentSourceContainmentType == null
|| currentSourceContainmentType
.compareTo(sourceContainmentType) > 0) {
if (currentSourceContainmentType != null
&& !currentSourceContainmentType.isIncluded()) {
logger.warn(MessageFormat
.format("The vertex [{0}] was excluded with the containment type [{1}], but it must be included with containment type [{2}], otherwise mappings will not be consistent.",
sourceVertex,
currentSourceContainmentType,
sourceContainmentType));
} else {
logger.trace(MessageFormat
.format("Including the vertex [{0}] with the containment type [{1}].",
sourceVertex, dequeContainmentType));
}
setInfoVertexContainmentType(sourceVertex,
sourceContainmentType);
final Set<DependencyEdge> edges = graph
.outgoingEdgesOf(sourceVertex);
for (DependencyEdge edge : edges) {
final InfoVertex<T, C> targetVertex = graph
.getEdgeTarget(edge);
final DependencyType dependencyType = edge.getType();
final ContainmentType targetContainmentType = dependencyType
.combineWith(sourceContainmentType);
if (targetContainmentType != null) {
final Deque<InfoVertex<T, C>> targetDeque = deques
.get(targetContainmentType);
if (targetDeque != null) {
logger.trace(MessageFormat
.format("Queueing the inclusion of the vertex [{0}] with the containment type [{1}].",
targetVertex,
targetContainmentType));
targetDeque.add(targetVertex);
}
}
}
} else {
logger.trace(MessageFormat
.format("Vertex [{0}] is already included with the containment type [{1}].",
sourceVertex, currentSourceContainmentType));
}
}
}
}