本文整理汇总了Java中edu.uci.ics.jung.graph.DirectedGraph类的典型用法代码示例。如果您正苦于以下问题:Java DirectedGraph类的具体用法?Java DirectedGraph怎么用?Java DirectedGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectedGraph类属于edu.uci.ics.jung.graph包,在下文中一共展示了DirectedGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBfs
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
@Test
public void testBfs() throws Exception {
DirectedGraph<URI, URI> graph = new DirectedSparseGraph<>();
graph.addVertex( YURI );
graph.addVertex( YUGO );
graph.addEdge( YPY, YURI, YUGO, EdgeType.DIRECTED );
Collection<URI> roots = Arrays.asList( YURI );
GraphToTreeConverter.Search search = GraphToTreeConverter.Search.BFS;
Forest<URI, URI> result = GraphToTreeConverter.convert( graph, roots, search );
assertEquals( 1, result.getTrees().size() );
Tree<URI, URI> tree = result.getTrees().iterator().next();
assertEquals( YURI, tree.getRoot() );
assertEquals( YUGO, tree.getChildren( YURI ).iterator().next() );
}
示例2: testDfs
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
@Test
public void testDfs() throws Exception {
DirectedGraph<URI, URI> graph = new DirectedSparseGraph<>();
graph.addVertex( YURI );
graph.addVertex( YUGO );
graph.addEdge( YPY, YURI, YUGO, EdgeType.DIRECTED );
Collection<URI> roots = Arrays.asList( YURI );
GraphToTreeConverter.Search search = GraphToTreeConverter.Search.DFS;
Forest<URI, URI> result = GraphToTreeConverter.convert( graph, roots, search );
assertEquals( 1, result.getTrees().size() );
Tree<URI, URI> tree = result.getTrees().iterator().next();
assertEquals( YURI, tree.getRoot() );
assertEquals( YUGO, tree.getChildren( YURI ).iterator().next() );
}
示例3: testPrint
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
@Test
public void testPrint() throws Exception {
DirectedGraph<URI, URI> graph = new DirectedSparseGraph<>();
graph.addVertex( YURI );
graph.addVertex( YUGO );
graph.addEdge( YPY, YURI, YUGO, EdgeType.DIRECTED );
Collection<URI> roots = Arrays.asList( YURI );
GraphToTreeConverter.Search search = GraphToTreeConverter.Search.DFS;
Forest<URI, URI> result = GraphToTreeConverter.convert( graph, roots, search );
Logger log = Logger.getLogger( GraphToTreeConverter.class );
StringWriter stringy = new StringWriter();
WriterAppender app = new WriterAppender( new SimpleLayout(), stringy );
log.setLevel( Level.DEBUG );
log.addAppender( app );
GraphToTreeConverter.printForest( result );
String output = stringy.toString().replaceAll( "\\s", "" );
assertEquals( "DEBUG-http://semoss.va.gov/database/T44889381-85ce-43e3-893d-6267fd480660/YuriDEBUG-http://semoss.va.gov/database/T44889381-85ce-43e3-893d-6267fd480660/Yugo", output );
}
示例4: LayoutPopup
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
/**
* Constructor for LayoutPopup.
*
* @param name String
* @param ps IPlaySheet
*/
public LayoutPopup( String name, GraphPlaySheet ps, Collection<SEMOSSVertex> verts ) {
super( name );
DirectedGraph<SEMOSSVertex, SEMOSSEdge> viz = ps.getVisibleGraph();
boolean forestok = ( viz instanceof Forest || !verts.isEmpty() );
for ( Class<? extends Layout> layout : LAYOUTS ) {
LayoutMenuItem mi = new LayoutMenuItem( layout, ps, verts );
add( mi );
if ( TREELAYOUTS.contains( layout ) ) {
mi.setEnabled( forestok );
}
}
}
示例5: actionPerformed
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
/**
* Method actionPerformed. Dictates what actions to take when an Action Event
* is performed.
*
* @param arg0 ActionEvent - The event that triggers the actions in the
* method.
*/
@Override
public void actionPerformed( ActionEvent arg0 ) {
logger.debug( "Export button has been pressed" );
DirectedGraph<SEMOSSVertex, SEMOSSEdge> graph = gps.getVisibleGraph();
ValueFactory vf = new ValueFactoryImpl();
List<Value[]> vals = new ArrayList<>();
for ( SEMOSSEdge edge : graph.getEdges() ) {
SEMOSSVertex src = graph.getSource( edge );
SEMOSSVertex dst = graph.getDest( edge );
Value subj = vf.createLiteral( src.getLabel() );
Value obj = vf.createLiteral( dst.getLabel() );
vals.add( new Value[] { subj, obj } );
}
GridRAWPlaySheet.convertUrisToLabels( vals, gps.getEngine() );
GridRAWPlaySheet newGps = new GridRAWPlaySheet();
newGps.setTitle( "EXPORT: " + gps.getTitle() );
newGps.create( vals, Arrays.asList( "Source", "Destination" ), gps.getEngine() );
gps.addSibling( "Graph Edge List", newGps );
}
示例6: getEdge
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
/**
* Gets nodes that have both in- and out- edges and are of the given type
*
* @param graph the graph to inspect
* @param type the node type that has the edges
* @param endpoint
* @return
*/
public static MultiMap<SEMOSSVertex, CondenserTuple>
findNodesToCondense( DirectedGraph<SEMOSSVertex, SEMOSSEdge> graph,
URI type, URI endpoint ) {
MultiMap<SEMOSSVertex, CondenserTuple> removers = new MultiMap<>();
for ( SEMOSSVertex middle : graph.getVertices() ) {
if ( type.equals( middle.getType() ) ) {
SEMOSSEdge upstream = getEdge( endpoint, middle, graph, true );
SEMOSSEdge downstream = getEdge( endpoint, middle, graph, false );
// FIXME: we might have multiple pairs of
// endpoints through our middle, so loop
//while ( !( null == upstream || null == downstream ) ) {
if ( !( null == upstream || null == downstream ) ) {
removers.add( middle, new CondenserTuple( upstream, downstream ) );
}
// upstream = getVertex( endpoint, middle, graph, true );
//downstream = getVertex( endpoint, middle, graph, false );
//}
}
}
return removers;
}
示例7: select
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
public String select( DirectedGraph<QueryNode, QueryEdge> graph,
List<QueryOrder> ordering ) {
List<QueryGraphElement> todo = new ArrayList<>();
todo.addAll( graph.getVertices() );
todo.addAll( graph.getEdges() );
Set<QueryOrder> linkedOrderSet = new LinkedHashSet<>( ordering );
for ( QueryGraphElement v : todo ) {
for ( URI prop : v.getAllValues().keySet() ) {
QueryOrder qo = new QueryOrder( v, prop );
if ( !linkedOrderSet.contains( qo ) ) {
linkedOrderSet.add( qo );
}
}
}
List<QueryOrder> fullOrdering = new ArrayList<>( linkedOrderSet );
return buildSelect( fullOrdering ) + buildWhere( graph, fullOrdering );
}
示例8: build
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
public static DirectedGraph<GraphNode, GraphEdge> build(
GraphModel graphModel, EdgeMatcher<String> matcher) {
DirectedGraph<GraphNode, GraphEdge> result =
new DirectedSparseMultigraph<GraphNode, GraphEdge>();
Set<GraphNode> includedNodes = graphModel.getNodesSet();
for (GraphEdge edge : graphModel.getEdges()) {
// Filter on nodes first
if (!includedNodes.contains(edge.getHead()))
continue;
if (!includedNodes.contains(edge.getTail()))
continue;
if (matcher.edgeForward(edge)) {
result.addEdge(edge, edge.getHead(), edge.getTail());
}
else if (matcher.edgeReverse(edge)) {
result.addEdge(edge, edge.getTail(), edge.getHead());
}
}
return result;
}
示例9: addEdges
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
private void addEdges(
DirectedGraph<GraphNode, GraphEdge> result,
Set<GraphNode> includedNodes) {
EdgeMatcher<String> matcher = edgeMatcher.getInfo();
for (GraphEdge edge : graphModel.getEdges()) {
// Filter on nodes first
if (!includedNodes.contains(edge.getHead()))
continue;
if (!includedNodes.contains(edge.getTail()))
continue;
if (matcher.edgeForward(edge)) {
addForwardEdge(result, edge);
}
else if (matcher.edgeReverse(edge)) {
addReverseEdge(result, edge);
}
}
}
示例10: buildJungLayout
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
@Override
protected Layout<GraphNode,GraphEdge> buildJungLayout(
DirectedGraph<GraphNode, GraphEdge> jungGraph,
Dimension layoutSize) {
SpringLayout<GraphNode, GraphEdge> result =
new SpringLayout<GraphNode, GraphEdge>(jungGraph);
result.setSize(layoutSize);
if (force.isSet()) {
result.setForceMultiplier(force.getValue());
}
if (range.isSet()) {
result.setRepulsionRange(range.getValue());
}
if (stretch.isSet()) {
result.setStretch(stretch.getValue());
}
return result;
}
示例11: toDirected
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
public static <V> DirectedGraph<V, WeightedEdge> toDirected(Graph<V, WeightedEdge> graph) {
DirectedGraph<V, WeightedEdge> directedGraph = new DirectedSparseGraph<V, WeightedEdge>();
// Add all vertices first
Collection<V> vertices = graph.getVertices();
for(V vertex : vertices) {
directedGraph.addVertex(vertex);
}
// Add directed edges
for(WeightedEdge edge : graph.getEdges()) {
Pair<V> endpoints = graph.getEndpoints(edge);
directedGraph.addEdge(new WeightedEdge(edge.getWeight()), endpoints.getFirst(), endpoints.getSecond());
directedGraph.addEdge(new WeightedEdge(edge.getWeight()), endpoints.getSecond(), endpoints.getFirst());
}
return directedGraph;
}
示例12: buildGraphInternal
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
private void buildGraphInternal(final DirectedGraph<Object, JobGraphLink> graph,
final AnalysisJobBuilder analysisJobBuilder, final List<Table> sourceTables,
final JobGraphElementFactory linkFactory) {
// note: currently SourceColumnFinder cannot cross links from
// OutputDataStreams to the main/parent AnalysisJobBuilder, so we create
// a new SourceColumnFinder for each AnalysisJobBuilder instead of
// reusing the instance.
final SourceColumnFinder sourceColumnFinder = new SourceColumnFinder();
sourceColumnFinder.addSources(analysisJobBuilder);
for (final Table table : sourceTables) {
addNodes(graph, sourceColumnFinder, linkFactory, table, -1);
}
final Collection<ComponentBuilder> componentBuilders = analysisJobBuilder.getComponentBuilders();
for (final ComponentBuilder componentBuilder : componentBuilders) {
addNodes(graph, sourceColumnFinder, linkFactory, componentBuilder, -1);
}
removeUnnecesaryEdges(graph, sourceColumnFinder);
}
示例13: MacroMicroSearchRequestor
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
/*******************************************************
* Creates a new instance of this class
*
* @param invokingFile
* The file that invokes methods whose declarations will be
* searched
* @param macroGraph
* The macro graph to be filled
* @param microGraph
* The micro graph to be filled
* @throws IllegalArgumentException
* If any of the parameters is null
*******************************************************/
public MacroMicroSearchRequestor(ICompilationUnit invokingFile, DirectedGraph<ICompilationUnit, EdgeWrapper> macroGraph,
DirectedGraph<ICompilationUnit, EdgeWrapper> microGraph)
{
if (invokingFile == null || macroGraph == null || microGraph == null)
{
throw new IllegalArgumentException();
}
mInvokingFile = invokingFile;
mMacroGraph = macroGraph;
mMicroGraph = microGraph;
// Add the invoking file vertices
mMacroGraph.addVertex(mInvokingFile);
mMicroGraph.addVertex(mInvokingFile);
}
示例14: transform
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public List<Set<V>> transform(DirectedGraph<V, E> graph) {
WeakComponentClusterer<V, E> clust = new WeakComponentClusterer<V, E>();
Set<Set<V>> components = clust.transform(graph);
ArrayList<Set<V>> res = new ArrayList<Set<V>>();
for (Set<V> comp : components) {
List<Set<V>> r = rank(graph, comp);
for (int i = 0; i < r.size(); i++) {
Set<V> s = r.get(i);
if (res.size() <= i) {
res.add(s);
}
else {
res.get(i).addAll(s);
}
}
}
return res;
}
示例15: EdmondsKarpMaxFlow
import edu.uci.ics.jung.graph.DirectedGraph; //导入依赖的package包/类
/**
* Constructs a new instance of the algorithm solver for a given graph, source, and sink.
* Source and sink vertices must be elements of the specified graph, and must be
* distinct.
* @param directedGraph the flow graph
* @param source the source vertex
* @param sink the sink vertex
* @param edgeCapacityKey the UserDatum key that stores the capacity for each edge.
* @param edgeFlowKey the UserDatum key where the solver will place the value of the flow for each edge
*/
public EdmondsKarpMaxFlow(DirectedGraph directedGraph, Vertex source, Vertex sink, String edgeCapacityKey, String edgeFlowKey)
{
if (source.getGraph() != directedGraph || sink.getGraph() != directedGraph)
throw new IllegalArgumentException("source and sink vertices must be elements of the specified graph");
if (source.equals(sink))
throw new IllegalArgumentException("source and sink vertices must be distinct");
mOriginalGraph = directedGraph;
mFlowGraph = (DirectedGraph) directedGraph.copy();
mSource = (Vertex) source.getEqualVertex(mFlowGraph);
mTarget = (Vertex) sink.getEqualVertex(mFlowGraph);
mEdgeFlowKey = edgeFlowKey;
mEdgeCapacityKey = edgeCapacityKey;
mMaxFlow = 0;
mSinkPartitionNodes = new HashSet();
mSourcePartitionNodes = new HashSet();
mMinCutEdges = new HashSet();
}