当前位置: 首页>>代码示例>>Java>>正文


Java DirectedGraph.addVertex方法代码示例

本文整理汇总了Java中edu.uci.ics.jung.graph.DirectedGraph.addVertex方法的典型用法代码示例。如果您正苦于以下问题:Java DirectedGraph.addVertex方法的具体用法?Java DirectedGraph.addVertex怎么用?Java DirectedGraph.addVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.uci.ics.jung.graph.DirectedGraph的用法示例。


在下文中一共展示了DirectedGraph.addVertex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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() );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:18,代码来源:GraphToTreeConverterTest.java

示例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() );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:18,代码来源:GraphToTreeConverterTest.java

示例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 );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:22,代码来源:GraphToTreeConverterTest.java

示例4: 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;
}
 
开发者ID:MKLab-ITI,项目名称:mgraph-summarization,代码行数:18,代码来源:GraphUtils.java

示例5: displayNetwork

import edu.uci.ics.jung.graph.DirectedGraph; //导入方法依赖的package包/类
/** Displays the constraint network graph */
public void displayNetwork() {
	DirectedGraph<Integer, Integer> g = new DirectedSparseGraph<Integer, Integer>();
	HashMap<Integer, String> nodeLabels = new HashMap<Integer, String>();
		
	int edgeId = 0;
	for (PHYNode n : edges.keySet()) {
		g.addVertex(n.getNodeId());
		nodeLabels.put(n.getNodeId(), n.getLabel());
		for(PHYNode n2 : edges.get(n)) {
			if(!g.containsVertex(n2.getNodeId())) {
				g.addVertex(n2.getNodeId());
				nodeLabels.put(n2.getNodeId(), n2.getLabel());
			}
			g.addEdge(edgeId, n.getNodeId(), n2.getNodeId(), EdgeType.DIRECTED);
			edgeId++;
		}
	}
	Visualizer.showNetwork(g, nodeLabels);	
}
 
开发者ID:viq854,项目名称:lichee,代码行数:21,代码来源:PHYNetwork.java

示例6: addGraphLevel

import edu.uci.ics.jung.graph.DirectedGraph; //导入方法依赖的package包/类
@Override
public Collection<GraphElement> addGraphLevel( Collection<URI> nodes,
		IEngine engine, int overlayLevel ) {
	DirectedGraph<SEMOSSVertex, SEMOSSEdge> graph = super.getGraph();

	for ( URI u : nodes ) {
		SEMOSSVertex src = super.createOrRetrieveVertex( u, overlayLevel );
		src.setType( RDFS.CLASS );
		graph.addVertex( src );
	}

	fireModelChanged( overlayLevel );
	return elementsFromLevel( overlayLevel );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:15,代码来源:MetamodelPlaySheet.java

示例7: addFisher

import edu.uci.ics.jung.graph.DirectedGraph; //导入方法依赖的package包/类
/**
 * this is supposed to be called not so much when initializing the network but later on if any agent is created
 * while the model is running
 *
 * @param fisher
 * @param currentNetwork
 * @param state
 */
@Override
public void addFisher(
        Fisher fisher, DirectedGraph<Fisher, FriendshipEdge> currentNetwork, FishState state) {
    Preconditions.checkArgument(!currentNetwork.containsVertex(fisher));

    currentNetwork.addVertex(fisher);
    ObservableList<Fisher> fishers = state.getFishers();
    int populationSize = fishers.size();

    int degree = computeDegree(state.getRandom());
    Set<Fisher> friends = new HashSet<>(degree);
    while(friends.size() < Math.min(degree,populationSize))
    {
        final Fisher candidate = fishers.get(state.getRandom().nextInt(populationSize));
        if(candidate != fisher)
        {
            boolean allowed = true;
            for(NetworkPredicate predicate : predicates)
                allowed = allowed && predicate.test(fisher,candidate);
            if(allowed)
                friends.add(candidate);
        }
    }
    //now make them your friends!
    addSetOfFriends(currentNetwork, fisher, friends);
}
 
开发者ID:CarrKnight,项目名称:POSEIDON,代码行数:35,代码来源:EquidegreeBuilder.java

示例8: toDirected

import edu.uci.ics.jung.graph.DirectedGraph; //导入方法依赖的package包/类
/**
 * Transforms <code>graph</code> (which may be of any directionality)
 * into a directed graph.  
 * Specifically:
 * <ul>
 * <li/>Vertices are copied from <code>graph</code>.
 * <li/>Undirected edges are 'converted' into two new antiparallel directed edges in the new graph.
 * <li/>Each directed edge (if any) in <code>graph</code> is 'recreated' with a new edge in the new
 * graph if <code>create_new</code> is true, or copied from <code>graph</code> otherwise.
 * </ul>
 * 
 * @param graph     the graph to be transformed
 * @param create_new specifies whether existing directed edges are to be copied or recreated
 * @param graph_factory used to create the new graph object
 * @param edge_factory used to create new edges
 * @return          the transformed <code>Graph</code>
 */
public static <V,E> Graph<V,E> toDirected(Graph<V,E> graph, Factory<DirectedGraph<V,E>> graph_factory,
        Factory<E> edge_factory, boolean create_new)
{
    DirectedGraph<V,E> out = graph_factory.create();
    
    for (V v : graph.getVertices())
        out.addVertex(v);
    
    for (E e : graph.getEdges())
    {
        Pair<V> endpoints = graph.getEndpoints(e);
        if (graph.getEdgeType(e) == EdgeType.UNDIRECTED)
        {
            V v1 = endpoints.getFirst();
            V v2 = endpoints.getSecond();
            out.addEdge(edge_factory.create(), v1, v2, EdgeType.DIRECTED);
            out.addEdge(edge_factory.create(), v2, v1, EdgeType.DIRECTED);
        }
        else // if the edge is directed, just add it 
        {
            V source = graph.getSource(e);
            V dest = graph.getDest(e);
            E to_add = create_new ? edge_factory.create() : e;
            out.addEdge(to_add, source, dest, EdgeType.DIRECTED);
        }
            
    }
    return out;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:47,代码来源:DirectionTransformer.java

示例9: createDirectedAcyclicGraph

import edu.uci.ics.jung.graph.DirectedGraph; //导入方法依赖的package包/类
/**
 * Creates a sample directed acyclic graph by generating several "layers",
 * and connecting nodes (randomly) to nodes in earlier (but never later)
 * layers. Each layer has some random number of nodes in it 1 less than n
 * less than maxNodesPerLayer.
 * 
 * @return the created graph
 */
public static Graph<String,Number> createDirectedAcyclicGraph(
	int layers,
	int maxNodesPerLayer,
	double linkprob) {

	DirectedGraph<String,Number> dag = new DirectedSparseMultigraph<String,Number>();
	Set<String> previousLayers = new HashSet<String>();
	Set<String> inThisLayer = new HashSet<String>();
	for (int i = 0; i < layers; i++) {

		int nodesThisLayer = (int) (Math.random() * maxNodesPerLayer) + 1;
		for (int j = 0; j < nodesThisLayer; j++) {
               String v = i+":"+j;
			dag.addVertex(v);
			inThisLayer.add(v);
			// for each previous node...
               for(String v2 : previousLayers) {
				if (Math.random() < linkprob) {
                       Double de = new Double(Math.random());
					dag.addEdge(de, v, v2);
				}
			}
		}

		previousLayers.addAll(inThisLayer);
		inThisLayer.clear();
	}
	return dag;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:38,代码来源:TestGraphs.java

示例10: createDirectedAcyclicGraph

import edu.uci.ics.jung.graph.DirectedGraph; //导入方法依赖的package包/类
/**
 * Creates a sample directed acyclic graph by generating several "layers",
 * and connecting nodes (randomly) to nodes in earlier (but never later)
 * layers. Each layer has some random number of nodes in it 1 less than n
 * less than maxNodesPerLayer.
 * 
 * @return the created graph
 */
public static Graph createDirectedAcyclicGraph(
	int layers,
	int maxNodesPerLayer,
	double linkprob) {
	DirectedGraph dag = new DirectedSparseGraph();
	StringLabeller sl = StringLabeller.getLabeller(dag);
	Set previousLayers = new HashSet();
	Set inThisLayer = new HashSet();
	for (int i = 0; i < layers; i++) {

		int nodesThisLayer = (int) (Math.random() * maxNodesPerLayer) + 1;
		for (int j = 0; j < nodesThisLayer; j++) {
			Vertex v = dag.addVertex(new SparseVertex());
			inThisLayer.add(v);
			try {
				sl.setLabel(v, i + ":" + j);
			} catch (Exception e) {
			}
			// for each previous node...
			for (Iterator iter = previousLayers.iterator();
				iter.hasNext();
				) {
				Vertex v2 = (Vertex) iter.next();
				if (Math.random() < linkprob) {
					GraphUtils.addEdge(dag, v, v2);
				}
			}
		}

		previousLayers.addAll(inThisLayer);
		inThisLayer.clear();
	}
	return dag;
}
 
开发者ID:markus1978,项目名称:clickwatch,代码行数:43,代码来源:TestGraphs.java


注:本文中的edu.uci.ics.jung.graph.DirectedGraph.addVertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。