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


Java DirectedSparseGraph類代碼示例

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


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

示例1: testBfs

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的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() );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:18,代碼來源:GraphToTreeConverterTest.java

示例2: renderElement

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
@Override
public void renderElement(JPanel jp, Object elem) {
    if (elem instanceof ViwnNode) {
        ViwnNode vn = (ViwnNode) elem;

        // one node visualisation
        Graph<ViwnNode, ViwnEdge> g = new DirectedSparseGraph<>();
        g.addVertex(vn);
        VisualizationViewer<ViwnNode, ViwnEdge> vv = new VisualizationViewer<>(new StaticLayout<>(g));
        vv.getRenderer().setVertexRenderer(new ViwnVertexRenderer(vv.getRenderer().getVertexRenderer()));

        vv.getRenderContext().setVertexShapeTransformer((ViwnNode v) -> v.getShape());

        vv.getRenderContext().setVertexFillPaintTransformer(new ViwnVertexFillColor(vv.getPickedVertexState(), null));
        vv.setVertexToolTipTransformer(new ViwnVertexToolTipTransformer());
        vv.setPreferredSize(new Dimension(110, 50));
        Point2D q = vv.getGraphLayout().transform(vn);
        Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter());
        vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(lvc.getX() - q.getX(), lvc.getY() - q.getY());
        jp.add(vv, "vfill br");
    }
}
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:23,代碼來源:ViwnLockerViewUI.java

示例3: getGraph

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
/**
 * Convert FNSS topology to JUNG graph.
 * 
 * @param topology FNSS Topology object
 * @return A JUNG graph
 */
public static Graph<String, Edge> getGraph(Topology topology) {
	Graph<String, Edge> graph = null;
	EdgeType edgeType = null;
	if (topology.isDirected()) {
		graph = new DirectedSparseGraph<String, Edge>();
		edgeType = EdgeType.DIRECTED;
	} else {
		graph = new UndirectedSparseGraph<String, Edge>();
		edgeType = EdgeType.UNDIRECTED;
	}
	for(String node : topology.getAllNodes()) {
		graph.addVertex(node);
	}
	for(Pair<String, String> edge : topology.getAllEdges()) {
		graph.addEdge(topology.getEdge(edge), edge.getU(), edge.getV(), edgeType);
	}
	return graph;
}
 
開發者ID:fnss,項目名稱:fnss-java,代碼行數:25,代碼來源:JUNGConverter.java

示例4: matrixToGraph

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
public static DirectedSparseGraph<Vertex, Edge> matrixToGraph(double[][] matrix){
	DirectedSparseGraph<Vertex, Edge> graph = new DirectedSparseGraph<Vertex,Edge>();
	if(matrix.length != matrix[0].length){
		return null;
	}
	
	Vertex[] vertices = new Vertex[matrix.length];
	for (int i = 0; i < vertices.length; i++) {
		vertices[i] = new Vertex(i);
		graph.addVertex(vertices[i]);
	}
	
	for (int i = 0; i < matrix.length; i++) {
		for (int j = 0; j < matrix[i].length; j++) {
			if(matrix[i][j] != 0.0){
				Edge edge = new Edge();
				graph.addEdge(edge,vertices[i], vertices[j]);
			}
		}
	}
	return graph;
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:23,代碼來源:Conversion.java

示例5: deleteDoubleEdges

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
/**
 * Erases the multiple edges of a graph
 * @param graph
 */
public static void deleteDoubleEdges(DirectedSparseGraph<Vertex,Edge> graph){
	HashSet<Edge> toDelete = new HashSet<Edge>();
	for (Edge edge1 : graph.getEdges()) {
		for (Edge edge2 : graph.getEdges()) {
			if(graph.getSource(edge1) == graph.getDest(edge2) 
					&& graph.getSource(edge2) == graph.getDest(edge1)
					&& !toDelete.contains(edge1)
					&& graph.getSource(edge1).toString().compareTo(graph.getDest(edge1).toString()) > 0){
				toDelete.add(edge1);
			}
		}
	}
	System.out.println(toDelete.size());
	for (Edge edge : toDelete) {
		System.out.println(graph.getEdges().contains(edge));
		graph.removeEdge(edge);	
	}	
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:23,代碼來源:Utils.java

示例6: testDfs

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的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() );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:18,代碼來源:GraphToTreeConverterTest.java

示例7: testPrint

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的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 );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:22,代碼來源:GraphToTreeConverterTest.java

示例8: testGenerateVisualise

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
public Graph testGenerateVisualise(String name, LearnOptions lopts) {
        opts.alignmentModel = lopts.alignmentModel;
        if (opts.ngramModelFile != null) {
            ngramModel = new KylmNgramWrapper(opts.ngramModelFile);
        }
        FullStatFig complexity = new FullStatFig();
        double temperature = lopts.initTemperature;
        testPerformance = newPerformance();
        AParams counts = newParams();
//        AExample ex = examples.get(examples.size()-1);
        AExample ex = examples.get(1621);
        Graph graph = new DirectedSparseGraph<>();
        AInferState inferState = createInferState(ex, 1, counts, temperature,
                lopts, 0, complexity, graph);
        testPerformance.add(ex, inferState.bestWidget);
        System.out.println(widgetToFullString(ex, inferState.bestWidget));
        return graph;
    }
 
開發者ID:sinantie,項目名稱:Generator,代碼行數:19,代碼來源:AModel.java

示例9: testSemParseVisualise

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
public Graph testSemParseVisualise(String name, LearnOptions lopts)
    {
        opts.alignmentModel = lopts.alignmentModel;
//        ngramModel = new KylmNgramWrapper(opts.ngramModelFile);
        FullStatFig complexity = new FullStatFig();
        double temperature = lopts.initTemperature;
        testPerformance = newPerformance();
        AParams counts = newParams();
        AExample ex = examples.get(0);
        Graph graph = new DirectedSparseGraph<>();
        AInferState inferState =  createInferState(ex, 1, counts, temperature,
                lopts, 0, complexity, graph);
        testPerformance.add(ex, inferState.bestWidget);
        System.out.println(widgetToFullString(ex, inferState.bestWidget));
                                    
        return graph;
    }
 
開發者ID:sinantie,項目名稱:Generator,代碼行數:18,代碼來源:GenerativeEvent3Model.java

示例10: makeGraph

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
@Nonnull
private Graph<FileVertex, Number> makeGraph(@Nullable final File projectFolder, @Nullable final File startMindMap) {
  final DirectedSparseGraph<FileVertex, Number> result = new DirectedSparseGraph<FileVertex, Number>();

  final AtomicInteger edgeCounter = new AtomicInteger();

  final Set<File> mapFilesInProcessing = new HashSet<File>();

  if (startMindMap != null) {
    addMindMapAndFillByItsLinks(null, result, projectFolder, startMindMap, edgeCounter, mapFilesInProcessing);
  } else if (projectFolder != null) {
    final Iterator<File> iterator = FileUtils.iterateFiles(projectFolder, new String[]{"mmd"}, true); //NOI18N
    while (iterator.hasNext()) {
      final File mmdFile = iterator.next();
      if (mmdFile.isFile()) {
        addMindMapAndFillByItsLinks(null, result, projectFolder, mmdFile, edgeCounter, mapFilesInProcessing);
      }
    }
  }

  return result;
}
 
開發者ID:raydac,項目名稱:netbeans-mmd-plugin,代碼行數:23,代碼來源:FileLinkGraphPanel.java

示例11: toDirected

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的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;
}
 
開發者ID:MKLab-ITI,項目名稱:mgraph-summarization,代碼行數:18,代碼來源:GraphUtils.java

示例12: groupCluster

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
private static void groupCluster(AggregateLayout<VisualNode,VisualEdge> layout, Set<VisualNode> vertices) {
	if(vertices.size() < layout.getGraph().getVertexCount()) {
		Point2D center = layout.transform(vertices.iterator().next());
		Graph<VisualNode,VisualEdge> subGraph = DirectedSparseGraph.<VisualNode,VisualEdge>getFactory().create();
		for(VisualNode v : vertices) {
			subGraph.addVertex(v);
		}
		Layout<VisualNode,VisualEdge> subLayout =  new VisualCirclesLayout(subGraph);

		subLayout.setInitializer(HecataeusViewer.getActiveViewer().getGraphLayout());
		subLayout.setSize(new Dimension(40,40));
		
		layout.put(subLayout,center);
		HecataeusViewer.vv.getRenderContext().setVertexFillPaintTransformer(MapTransformer.<VisualNode,Paint>getInstance(vertexPaints));
		HecataeusViewer.getActiveViewer().repaint();
	}
}
 
開發者ID:pmanousis,項目名稱:Hecataeus,代碼行數:18,代碼來源:VisualEdgeBetweennessClustering.java

示例13: DrawnIconVertexDemo

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
public DrawnIconVertexDemo(final Deployment dm) {
    this.dmodel = dm;
    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Vertex, Edge>();
    vv = new VisualizationViewer<Vertex, Edge>(new SpringLayout2<Vertex, Edge>(graph));

    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));

    vv.getRenderContext().setVertexIconTransformer(vertexColor);


    vv.getRenderContext().setVertexFillPaintTransformer(new PickableVertexPaintTransformer<Vertex>(vv.getPickedVertexState(), Color.white, Color.yellow));
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgeColor);

    vv.setBackground(Color.white);

    // add my listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Vertex>());
}
 
開發者ID:SINTEF-9012,項目名稱:cloudml,代碼行數:21,代碼來源:DrawnIconVertexDemo.java

示例14: addNodeToGraph

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
public void addNodeToGraph(DirectedSparseGraph<Node, String> graph, HashMap<String, Node> nodes,
		NamedEntityInText entity, Triple c, String candidateURL) throws IOException {
	Node currentNode = new Node(candidateURL, 0, 0, algorithm);
	log.debug("CandidateURL: " + candidateURL);
	// candidates are connected to a specific label in the text via their
	// start position
	if (!graph.addVertex(currentNode)) {
		int st = entity.getStartPos();
		if (nodes.get(candidateURL) != null) {
			nodes.get(candidateURL).addId(st);
		} else {
			log.error("This vertex couldn't be added because of an bug in Jung: " + candidateURL);
		}
	} else {
		currentNode.addId(entity.getStartPos());
		nodes.put(candidateURL, currentNode);
	}
}
 
開發者ID:dice-group,項目名稱:AGDISTIS,代碼行數:19,代碼來源:CandidateUtil.java

示例15: test3

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入依賴的package包/類
/**
    * Test for discovery of a strongly connected component with 4 nodes (a cycle).
    */

@Test
public void test3() {
	DirectedGraph<Integer, WeightedEdge> dg = new DirectedSparseGraph<Integer, WeightedEdge>();
	dg.addEdge(new WeightedEdge(1.0f), 5, 6);
	dg.addEdge(new WeightedEdge(1.0f), 6, 7);
	dg.addEdge(new WeightedEdge(1.0f), 7, 8);
	dg.addEdge(new WeightedEdge(1.0f), 8, 5);
	Tarjan<Integer, WeightedEdge> t = new Tarjan<Integer, WeightedEdge>(dg);
	List<List<Integer>> sccs = t.tarjan();
	assertTrue(sccs.size() == 1);
	assertTrue(sccs.get(0).contains(5));
	assertTrue(sccs.get(0).contains(6));
	assertTrue(sccs.get(0).contains(7));
	assertTrue(sccs.get(0).contains(8));
}
 
開發者ID:1123,項目名稱:johnson,代碼行數:20,代碼來源:TestTarjan.java


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