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


Java DirectedSparseGraph.addEdge方法代碼示例

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


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

示例1: 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

示例2: main

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入方法依賴的package包/類
public static void main(String[] args) {
  DirectedSparseGraph<String, String> g = new DirectedSparseGraph<String, String>();
  g.addVertex("Square");
  g.addVertex("Rectangle");
  g.addVertex("Circle");
  g.addEdge("Edge1", "Square", "Rectangle");
  g.addEdge("Edge2", "Square", "Circle");
  g.addEdge("Edge3", "Circle", "Square");
  
  VisualizationViewer<String, String> vv =
    new VisualizationViewer<String, String>(
      new FRLayout<String, String>(g), new Dimension(400,400));
  Transformer<String, String> transformer = new Transformer<String, String>() {
    @Override public String transform(String arg0) { return arg0; }
  };
  vv.getRenderContext().setVertexLabelTransformer(transformer);
  transformer = new Transformer<String, String>() {
    @Override public String transform(String arg0) { return arg0; }
  };
  vv.getRenderContext().setEdgeLabelTransformer(transformer);
  vv.getRenderer().setVertexRenderer(new MyRenderer());
 
  // The following code adds capability for mouse picking of vertices/edges. Vertices can even be moved!
  final DefaultModalGraphMouse<String,Number> graphMouse = new DefaultModalGraphMouse<String,Number>();
  vv.setGraphMouse(graphMouse);
  graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
 
  JFrame frame = new JFrame();
  frame.getContentPane().add(vv);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.pack();
  frame.setVisible(true);
}
 
開發者ID:marcvanzee,項目名稱:mdp-plan-revision,代碼行數:34,代碼來源:VertexShapes.java

示例3: getJungGraph

import edu.uci.ics.jung.graph.DirectedSparseGraph; //導入方法依賴的package包/類
/**
 * This method creates a graph representation of a concept used to visualize it via JUNG library
 * @return
 */
public DirectedSparseGraph<Node, String> getJungGraph()
{
	DirectedSparseGraph<Node, String> graph = new DirectedSparseGraph<Node, String>();
	
	graph.addVertex(this);
	
	OutLinkElement outLink = _lastOutLink;

	while (outLink != null)
	{
		graph.addVertex(outLink.relation);
		
		graph.addEdge(getNextEdgeLabelId(), this, outLink.relation, EdgeType.DIRECTED);
		
		graph.addVertex(outLink.relation.referent);
		
		graph.addEdge(getNextEdgeLabelId(), outLink.relation, outLink.relation.referent, EdgeType.DIRECTED);
		
		outLink = outLink.previousOutLinkElement;
	}
	
	InLinkElement inLink = _lastInLink;

	while (inLink != null)
	{
		graph.addVertex(inLink.relation);
		
		graph.addEdge(getNextEdgeLabelId(), inLink.relation, this, EdgeType.DIRECTED);
		
		graph.addVertex(inLink.relation.argument);
		
		graph.addEdge(getNextEdgeLabelId(), inLink.relation.argument, inLink.relation, EdgeType.DIRECTED);
		
		inLink = inLink.previousInLinkElement;
	}
			
	return graph;
}
 
開發者ID:darrudi,項目名稱:HPR,代碼行數:43,代碼來源:Node.java


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