• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Graphs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jgrapht.Graphs的典型用法代码示例。如果您正苦于以下问题:Java Graphs类的具体用法?Java Graphs怎么用?Java Graphs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Graphs类属于org.jgrapht包,在下文中一共展示了Graphs类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: reverse

import org.jgrapht.Graphs; //导入依赖的package包/类
@Override
public IContainer reverse(final IScope scope) {
	final GamaGraph g = new GamaGraph(scope, GamaListFactory.create(type.getKeyType()), false, directed,
			vertexRelation, edgeSpecies, type.getKeyType(), type.getContentType());
	Graphs.addGraphReversed(g, this);
	return g;
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:8,代码来源:GamaGraph.java


示例2: testBipartiteMatching2

import org.jgrapht.Graphs; //导入依赖的package包/类
/**
 * Random test graph 2
 */
public void testBipartiteMatching2(){
	UndirectedGraph<Integer, DefaultEdge> graph = new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
	List<Integer> partition1=Arrays.asList(new Integer[]{0,1,2,3,4,5});
	List<Integer> partition2=Arrays.asList(new Integer[]{6,7,8,9,10,11});		
	Graphs.addAllVertices(graph, partition1);
	Graphs.addAllVertices(graph,partition2);
		
	DefaultEdge e00=graph.addEdge(partition1.get(0), partition2.get(0));
	DefaultEdge e01=graph.addEdge(partition1.get(0), partition2.get(1));
	DefaultEdge e04=graph.addEdge(partition1.get(0), partition2.get(4));
	DefaultEdge e10=graph.addEdge(partition1.get(1), partition2.get(0));
	DefaultEdge e13=graph.addEdge(partition1.get(1), partition2.get(3));
	DefaultEdge e21=graph.addEdge(partition1.get(2), partition2.get(1));
	DefaultEdge e32=graph.addEdge(partition1.get(3), partition2.get(2));
	DefaultEdge e34=graph.addEdge(partition1.get(3), partition2.get(4));
	DefaultEdge e42=graph.addEdge(partition1.get(4), partition2.get(2));
	DefaultEdge e52=graph.addEdge(partition1.get(5), partition2.get(2));
	DefaultEdge e55=graph.addEdge(partition1.get(5), partition2.get(5));
	
	HopcroftKarpBipartiteMatching<Integer,DefaultEdge> bm=new HopcroftKarpBipartiteMatching<Integer,DefaultEdge>(graph,new HashSet<Integer>(partition1),new HashSet<Integer>(partition2));
	assertEquals(6, bm.getMatching().size(), 0);
	List<DefaultEdge> l1 = Arrays.asList(new DefaultEdge[] {e21, e13, e00, e42, e34, e55});
    Set<DefaultEdge> matching = new HashSet<DefaultEdge>(l1);
	assertEquals(matching, bm.getMatching());
}
 
开发者ID:j123b567,项目名称:stack-usage,代码行数:29,代码来源:HopcroftKarpBipartiteMatchingTest.java


示例3: populateSig

import org.jgrapht.Graphs; //导入依赖的package包/类
/**
 * Method to be called only when SigValue IDREFs have been fully unmarshalled,
 * to populate the target SIG.
 *
 * @param sig the (rather empty) sig to be completed
 */
public void populateSig (SIGraph sig)
{
    final InterIndex index = sig.getSystem().getSheet().getInterIndex();

    // Allocate vertices
    Graphs.addAllVertices(sig, interRefs);
    Graphs.addAllVertices(sig, interDefs);

    for (Inter inter : sig.vertexSet()) {
        inter.setSig(sig);
        index.insert(inter);
    }

    // Allocate edges
    for (RelationValue rel : relations) {
        try {
            Inter source = index.getEntity(rel.sourceId);
            Inter target = index.getEntity(rel.targetId);
            sig.addEdge(source, target, rel.relation);
        } catch (Throwable ex) {
            logger.error("Error unmarshalling relation " + rel + " ex:" + ex, ex);
        }
    }
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:31,代码来源:SigValue.java


示例4: getClusters

import org.jgrapht.Graphs; //导入依赖的package包/类
public Collection<Collection<V>> getClusters() {
    final Set<V> roots = this.roots.entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).collect(Collectors.toSet());

    return roots.stream().map(root -> {
        final Set<V> visited = new HashSet<>();

        final Queue<V> queue = new LinkedList<>();
        queue.add(root);

        while (!queue.isEmpty()) {
            final V v = queue.remove();
            if (visited.contains(v)) continue;
            visited.add(v);
            queue.addAll(Graphs.successorListOf(digraph, v));
        }

        return visited;
    }).collect(Collectors.toSet());
}
 
开发者ID:nlpub,项目名称:watset-java,代码行数:20,代码来源:MaxMax.java


示例5: getBoundVariables

import org.jgrapht.Graphs; //导入依赖的package包/类
public Set<IVariable> getBoundVariables(final ILiteral literal) {
	if (literal == null) {
		throw new IllegalArgumentException("The literal must not be null");
	}

	if (!sipGraph.containsVertex(literal)) {
		return Collections.<IVariable>emptySet();
	}

	final Set<IVariable> variables = new HashSet<IVariable>();

	for (final ILiteral predicate : Graphs.predecessorListOf(sipGraph, literal)) {
		variables.addAll(sipGraph.getEdge(predicate, literal).getLabel());
	}
	return variables;
}
 
开发者ID:NICTA,项目名称:iris-reasoner,代码行数:17,代码来源:LeftToRightSip.java


示例6: getDepends

import org.jgrapht.Graphs; //导入依赖的package包/类
public Set<ILiteral> getDepends(final ILiteral literal) {
	final Set<ILiteral> dependencies = new HashSet<ILiteral>();
	final Set<ILiteral> todoDependencies = new HashSet<ILiteral>();
	if (literal == null) {
		throw new IllegalArgumentException("The literal must not be null");
	}

	if (!sipGraph.containsVertex(literal)) {
		return Collections.<ILiteral>emptySet();
	}

	todoDependencies.add(literal);
	while (!todoDependencies.isEmpty()) {
		final ILiteral actual = todoDependencies.iterator().next();
		todoDependencies.remove(actual);

		for (final ILiteral vertex : Graphs.predecessorListOf(sipGraph, actual)) {
			if (dependencies.add(vertex)) {
				todoDependencies.add(vertex);
			}
		}
	}

	return dependencies;
}
 
开发者ID:NICTA,项目名称:iris-reasoner,代码行数:26,代码来源:LeftToRightSip.java


示例7: getEdgesEnteringLiteral

import org.jgrapht.Graphs; //导入依赖的package包/类
public Set<LabeledEdge<ILiteral, Set<IVariable>>> getEdgesEnteringLiteral(
		final ILiteral literal) {
	if (literal == null) {
		throw new IllegalArgumentException("The literal must not be null");
	}

	if (!sipGraph.containsVertex(literal)) {
		return Collections.<LabeledEdge<ILiteral, Set<IVariable>>>emptySet();
	}

	final List<ILiteral> predecessors = Graphs.predecessorListOf(sipGraph, literal);
	final Set<LabeledEdge<ILiteral, Set<IVariable>>> edges = 
		new HashSet<LabeledEdge<ILiteral, Set<IVariable>>>(predecessors.size());
	for (final ILiteral predecessor : predecessors) {
		edges.add(sipGraph.getEdge(predecessor, literal));
	}
	return edges;
}
 
开发者ID:NICTA,项目名称:iris-reasoner,代码行数:19,代码来源:LeftToRightSip.java


示例8: getEdgesLeavingLiteral

import org.jgrapht.Graphs; //导入依赖的package包/类
public Set<LabeledEdge<ILiteral, Set<IVariable>>> getEdgesLeavingLiteral(
		final ILiteral literal) {
	if (literal == null) {
		throw new IllegalArgumentException("The literal must not be null");
	}

	if (!sipGraph.containsVertex(literal)) {
		return Collections.<LabeledEdge<ILiteral, Set<IVariable>>>emptySet();
	}

	final List<ILiteral> successors = Graphs.successorListOf(sipGraph, literal);
	final Set<LabeledEdge<ILiteral, Set<IVariable>>> edges = 
		new HashSet<LabeledEdge<ILiteral, Set<IVariable>>>(successors.size());
	for (final ILiteral successor : successors) {
		edges.add(sipGraph.getEdge(literal, successor));
	}
	return edges;
}
 
开发者ID:NICTA,项目名称:iris-reasoner,代码行数:19,代码来源:LeftToRightSip.java


示例9: getDepends

import org.jgrapht.Graphs; //导入依赖的package包/类
public Set<IPredicate> getDepends(final IPredicate p) {
	if (p == null) {
		throw new NullPointerException("The predicate must not be null");
	}
	if (!g.containsVertex(p)) {
		return Collections.EMPTY_SET;
	}

	final Set<IPredicate> todo = new HashSet<IPredicate>();
	todo.add(p);
	final Set<IPredicate> deps = new HashSet<IPredicate>();

	while (!todo.isEmpty()) {
		final IPredicate act = todo.iterator().next();
		todo.remove(act);

		for (final IPredicate depends : Graphs.predecessorListOf(g, act)) {
			if (deps.add(depends)) {
				todo.add(depends);
			}
		}
	}

	return deps;
}
 
开发者ID:NICTA,项目名称:iris-reasoner,代码行数:26,代码来源:PredicateGraph.java


示例10: run

import org.jgrapht.Graphs; //导入依赖的package包/类
@Override
public void run() {
	try {
		synchronized (this) {
			LOGGER.info("Establishing inital connection and getting initial graph");
			IfmapGraphImpl tmp = DataReciever.getInitialGraph();
			mGraph.setLastUpdated(tmp.getLastUpdated());
			Graphs.addGraph(mGraph, tmp);
			while (!mIsDone) {
				if (DataReciever.isUpdateAvailable(mGraph.getLastUpdated())) {
					while (DataReciever.isUpdateAvailable(mGraph.getLastUpdated())) {
						DataReciever.nextUpdate(mGraph);
					}
				}
				wait(mInterval);
			}
		}
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
	LOGGER.info("Loop which updates the Graph has ended.");
}
 
开发者ID:trustathsh,项目名称:irongpm,代码行数:23,代码来源:Pulldozer.java


示例11: getCurrentGraph

import org.jgrapht.Graphs; //导入依赖的package包/类
/**
 * Gets the current graph from the visitmeta dataservice.
 * 
 * @return The graph of the newest timestamp.
 */
public static IfmapGraphImpl getCurrentGraph() {
	if (!isInitialized) {
		LOGGER.warn("DataReciever was not initialized properly. Call init() first! Trying to initilaize now.");
		init();
	}
	String json = visitmeta.get("current");
	JsonArray array = parser.parse(json).getAsJsonArray();
	IfmapGraphImpl graph = new IfmapGraphImpl();
	for (JsonElement elem : array) {
		IfmapGraphImpl graphPart = gson.fromJson(elem, IfmapGraphImpl.class);
		graph.setLastUpdated(graphPart.getLastUpdated());
		Graphs.addGraph(graph, graphPart);
	}
	LOGGER.debug("Recieved current graph: " + graph);
	return graph;
}
 
开发者ID:trustathsh,项目名称:irongpm,代码行数:22,代码来源:DataReciever.java


示例12: buildAdjacencyList

import org.jgrapht.Graphs; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private List<Integer>[] buildAdjacencyList() {

	@SuppressWarnings("rawtypes")
	List[] Ak = new ArrayList[nVertices];
	for (int j = 0; j < nVertices; j++) {
		V v = iToV[j];
		List<V> s = Graphs.successorListOf(graph, v);
		Ak[j] = new ArrayList<Integer>(s.size());

		Iterator<V> iterator = s.iterator();
		while (iterator.hasNext()) {
			Ak[j].add(vToI.get(iterator.next()));
		}
	}

	return Ak;
}
 
开发者ID:lzkill,项目名称:hawickjames,代码行数:19,代码来源:HawickJamesSimpleCycles.java


示例13: createSimpleConnectedWeightedGraph

import org.jgrapht.Graphs; //导入依赖的package包/类
protected Graph<String, DefaultWeightedEdge> createSimpleConnectedWeightedGraph() {

        Graph<String, DefaultWeightedEdge> g =
            new SimpleWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);

        double bias = 1;

        g.addVertex(A);
        g.addVertex(B);
        g.addVertex(C);
        g.addVertex(D);
        g.addVertex(E);

        AB = Graphs.addEdge(g, A, B, bias * 2);
        AC = Graphs.addEdge(g, A, C, bias * 3);
        BD = Graphs.addEdge(g, B, D, bias * 5);
        CD = Graphs.addEdge(g, C, D, bias * 20);
        DE = Graphs.addEdge(g, D, E, bias * 5);
        AE = Graphs.addEdge(g, A, E, bias * 100);

        return g;
    }
 
开发者ID:j123b567,项目名称:stack-usage,代码行数:23,代码来源:MinimumSpanningTreeTest.java


示例14: testBipartiteMatching1

import org.jgrapht.Graphs; //导入依赖的package包/类
/**
 * Random test graph 1
 */
public void testBipartiteMatching1(){
	UndirectedGraph<Integer, DefaultEdge> graph = new SimpleGraph<Integer, DefaultEdge>(DefaultEdge.class);
	List<Integer> partition1=Arrays.asList(new Integer[]{0,1,2,3});
	List<Integer> partition2=Arrays.asList(new Integer[]{4,5,6,7});	
	Graphs.addAllVertices(graph, partition1);
	Graphs.addAllVertices(graph,partition2);
	
	DefaultEdge e00=graph.addEdge(partition1.get(0), partition2.get(0));
	DefaultEdge e01=graph.addEdge(partition1.get(0), partition2.get(1));
	DefaultEdge e02=graph.addEdge(partition1.get(0), partition2.get(2));
	
	DefaultEdge e10=graph.addEdge(partition1.get(1), partition2.get(0));
	DefaultEdge e11=graph.addEdge(partition1.get(1), partition2.get(1));
	DefaultEdge e12=graph.addEdge(partition1.get(1), partition2.get(2));
	DefaultEdge e20=graph.addEdge(partition1.get(2), partition2.get(0));
	DefaultEdge e21=graph.addEdge(partition1.get(2), partition2.get(1));
	
	
	HopcroftKarpBipartiteMatching<Integer,DefaultEdge> bm=new HopcroftKarpBipartiteMatching<Integer,DefaultEdge>(graph,new HashSet<Integer>(partition1),new HashSet<Integer>(partition2));
	assertEquals(3, bm.getMatching().size(), 0);
	List<DefaultEdge> l1 = Arrays.asList(new DefaultEdge[] {e11, e02, e20});
    Set<DefaultEdge> matching = new HashSet<DefaultEdge>(l1);
	assertEquals(matching, bm.getMatching());
}
 
开发者ID:j123b567,项目名称:stack-usage,代码行数:28,代码来源:HopcroftKarpBipartiteMatchingTest.java


示例15: getPath

import org.jgrapht.Graphs; //导入依赖的package包/类
@Override
public RoutingPath getPath(Device from, Device to) {
	List<Channel> path = DijkstraShortestPath.findPathBetween(
			getGraph(), from, to);
	if (path == null) {
		return null;
	}

	List<Device> nodes = new ArrayList<Device>();
	Device v = from;
	nodes.add(from);
	for (Channel e : path) {
		v = Graphs.getOppositeVertex(getGraph(), e, v);
		nodes.add(v);
	}

	return new RoutingPath(nodes, path);
}
 
开发者ID:flyroom,项目名称:PeerfactSimKOM_Clone,代码行数:19,代码来源:StarNetwork.java


示例16: getPath

import org.jgrapht.Graphs; //导入依赖的package包/类
@Override
public RoutingPath getPath(Device from, Device to) {
	List<Channel> path = DijkstraShortestPath.findPathBetween(getGraph(),
			from, to);
	if (path == null) {
		return null;
	}

	List<Device> nodes = new ArrayList<Device>();
	Device v = from;
	nodes.add(from);
	for (Channel e : path) {
		v = Graphs.getOppositeVertex(getGraph(), e, v);
		nodes.add(v);
	}
	return new RoutingPath(nodes, path);
}
 
开发者ID:flyroom,项目名称:PeerfactSimKOM_Clone,代码行数:18,代码来源:RandomNetwork.java


示例17: union

import org.jgrapht.Graphs; //导入依赖的package包/类
@Override
public G union(G a, G b) {
    Graph<V, E> tmp = new GraphUnion<V, E, G>(a, b);
    G result = createNew();
    Graphs.addGraph(result, tmp);

    return result;
}
 
开发者ID:SmartDataAnalytics,项目名称:SubgraphIsomorphismIndex,代码行数:9,代码来源:SetOpsJGraphTBase.java


示例18: findBarPeaks

import org.jgrapht.Graphs; //导入依赖的package包/类
/**
 * Use individual staff projections to retrieve bar peaks.
 */
private void findBarPeaks ()
{
    // Analysis staff per staff
    for (Staff staff : staffManager.getStaves()) {
        StaffProjector projector = new StaffProjector(sheet, staff, this);
        projectors.add(projector);
        projector.process();
        Graphs.addAllVertices(this, projector.getPeaks());
    }
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:14,代码来源:PeakGraph.java


示例19: buildRelationships

import org.jgrapht.Graphs; //导入依赖的package包/类
/**
 * Compute the matrix of inter-chords relationships.
 */
private void buildRelationships ()
{
    // Sort measure standard chords by abscissa
    List<AbstractChordInter> stdChords = new ArrayList<AbstractChordInter>(
            stack.getStandardChords());
    Collections.sort(stdChords, Inter.byAbscissa);

    // Populate graph with chords
    Graphs.addAllVertices(graph, stdChords);

    // BeamGroup-based relationships
    inspectBeams();

    // Mirror-based relationships
    inspectMirrors();

    // RootStem-based relationships
    inspectRootStems();

    // Finally, default location-based relationships
    inspectLocations(stdChords);

    if (logger.isDebugEnabled()) {
        dumpRelationships(stdChords);
    }
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:30,代码来源:SlotsBuilder.java


示例20: getSubGraph

import org.jgrapht.Graphs; //导入依赖的package包/类
/**
 * Extract a subgraph limited to the provided set of glyphs.
 *
 * @param set        the provided set of glyphs
 * @param graph      the global graph to extract from
 * @param checkEdges true if glyph edges may point outside the provided set.
 * @return the graph limited to glyph set and related edges
 */
public static SimpleGraph<Glyph, GlyphLink> getSubGraph (Set<Glyph> set,
                                                         SimpleGraph<Glyph, GlyphLink> graph,
                                                         boolean checkEdges)
{
    // Which edges should be extracted for this set?
    Set<GlyphLink> setEdges = new LinkedHashSet<GlyphLink>();

    for (Glyph glyph : set) {
        Set<GlyphLink> glyphEdges = graph.edgesOf(glyph);

        if (!checkEdges) {
            setEdges.addAll(glyphEdges); // Take all edges
        } else {
            // Keep only the edges that link within the set
            for (GlyphLink link : glyphEdges) {
                Glyph opposite = Graphs.getOppositeVertex(graph, link, glyph);

                if (set.contains(opposite)) {
                    setEdges.add(link);
                }
            }
        }
    }

    SimpleGraph<Glyph, GlyphLink> subGraph = new SimpleGraph<Glyph, GlyphLink>(GlyphLink.class);
    Graphs.addAllVertices(subGraph, set);
    Graphs.addAllEdges(subGraph, graph, setEdges);

    return subGraph;
}
 
开发者ID:Audiveris,项目名称:audiveris,代码行数:39,代码来源:GlyphCluster.java



注:本文中的org.jgrapht.Graphs类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RMIExporter类代码示例发布时间:2022-05-21
下一篇:
Java CoprocessorProtocol类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap