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


Java Graph.getEdgeTarget方法代碼示例

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


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

示例1: getMinimumSpanningTree

import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
 * Builds a graph that contains a Minimum Spanning Tree
 * @param graph The input weighted graph
 */
public static Graph<Integer, DefaultWeightedEdge> getMinimumSpanningTree(Graph<Integer, DefaultWeightedEdge> graph) {

	// get the edges of a Minimum Spanning Tree generated for a weighted graph
	PrimMinimumSpanningTree<Integer, DefaultWeightedEdge> tree = new PrimMinimumSpanningTree<Integer, DefaultWeightedEdge>(graph);
	Set<DefaultWeightedEdge> mspEdges = tree.getMinimumSpanningTreeEdgeSet();

	// build a new graph from the MST edges
	Graph<Integer, DefaultWeightedEdge> mspGraph = new SimpleWeightedGraph<Integer, DefaultWeightedEdge>(DefaultWeightedEdge.class);

	for (DefaultWeightedEdge e : mspEdges) {

		int sourceV = graph.getEdgeSource(e);
		int targetV = graph.getEdgeTarget(e);

		mspGraph.addVertex(sourceV);
		mspGraph.addVertex(targetV);

		DefaultWeightedEdge edge = graph.getEdge(sourceV, targetV);
		double w = graph.getEdgeWeight(edge);
		mspGraph.addEdge(sourceV, targetV, edge);
		((AbstractBaseGraph<Integer, DefaultWeightedEdge>) mspGraph).setEdgeWeight(edge, w);
	}

	return mspGraph;
}
 
開發者ID:biojava,項目名稱:biojava-spark,代碼行數:30,代碼來源:WeightedGraph.java

示例2: expandConnectedVertices

import org.jgrapht.Graph; //導入方法依賴的package包/類
/**
 * 
 * @param g
 * @param newVertex
 * @param connectedVertices
 */
public static <V,E> void expandConnectedVertices(Graph<V,E> g, V newVertex, Set<V> connectedVertices){
	//for every edge (ignoring direction) connected newVertex
	for(E edge : g.edgesOf(newVertex)){
		V connectedVertex; //find the other vertex connected to newVertex
		if(g.getEdgeSource(edge).equals(newVertex)){
			connectedVertex = g.getEdgeTarget(edge);
		} else {
			connectedVertex = g.getEdgeSource(edge);
		}
		if(!connectedVertices.contains(connectedVertex)){ //if this vertex is not in connectedVertices
			connectedVertices.add(connectedVertex); //add it and search for more connected Vertices
			expandConnectedVertices(g, connectedVertex, connectedVertices);
		}
	}
}
 
開發者ID:WellingR,項目名稱:Maximal-Common-Subgraph,代碼行數:22,代碼來源:SharedStaticMethods.java

示例3: replaceVertex

import org.jgrapht.Graph; //導入方法依賴的package包/類
public static <T extends Object> boolean replaceVertex(Graph<T, DefaultEdge> completeGraph, T oldVertex, T newVertex) {
    if ((oldVertex == null) || (newVertex == null)) {
        return false;
    }
    final Set<DefaultEdge> relatedEdges = completeGraph.edgesOf(oldVertex);
    completeGraph.addVertex(newVertex);

    T sourceVertex;
    T targetVertex;
    for (DefaultEdge e : relatedEdges) {
        sourceVertex = completeGraph.getEdgeSource(e);
        targetVertex = completeGraph.getEdgeTarget(e);
        if (sourceVertex.equals(oldVertex)
                && targetVertex.equals(oldVertex)) {
            completeGraph.addEdge(newVertex, newVertex);
        } else {
            if (sourceVertex.equals(oldVertex)) {
                completeGraph.addEdge(newVertex, targetVertex);
            } else {
                completeGraph.addEdge(sourceVertex, newVertex);
            }
        }
    }
    completeGraph.removeVertex(oldVertex);
    return true;
}
 
開發者ID:bedla,項目名稱:parkovani-v-praze,代碼行數:27,代碼來源:Utils.java

示例4: buildGraph

import org.jgrapht.Graph; //導入方法依賴的package包/類
public static ListenableGraph<String, MyEdge> buildGraph(double threshold, boolean showEdgeLabels) {

		ListenableDirectedWeightedGraph<String, MyEdge> g = 
				new ListenableDirectedWeightedGraph<String, MyEdge>(MyEdge.class);

		Graph<Integer, DefaultWeightedEdge> inGraph = getGraph();		
		Set<DefaultWeightedEdge> edgeSet = inGraph.edgeSet();

		for (DefaultWeightedEdge e : edgeSet) {

			int sourceV = inGraph.getEdgeSource(e);
			String v1 = names[sourceV];

			int targetV = inGraph.getEdgeTarget(e);
			String v2 = names[targetV];

			g.addVertex(v1);
			g.addVertex(v2);

			double w = inGraph.getEdgeWeight(e);
			if(w>threshold) {
				MyEdge edge = g.addEdge(v1, v2);
				if(showEdgeLabels){
					g.setEdgeWeight(edge, w);
				}
			}

		}

		return g;
	}
 
開發者ID:biojava,項目名稱:biojava-spark,代碼行數:32,代碼來源:ShowGraph.java

示例5: write

import org.jgrapht.Graph; //導入方法依賴的package包/類
private void write(Path path, Graph<Sense<String>, DefaultWeightedEdge> graph) throws IOException {
    try (final BufferedWriter writer = Files.newBufferedWriter(path)) {
        for (final DefaultWeightedEdge edge : graph.edgeSet()) {
            final IndexedSense<String> source = (IndexedSense<String>) graph.getEdgeSource(edge);
            final IndexedSense<String> target = (IndexedSense<String>) graph.getEdgeTarget(edge);
            writer.write(String.format(Locale.ROOT, "%s#%d\t%s#%d\t%f\n",
                    source.get(), source.getSense(),
                    target.get(), target.getSense(),
                    graph.getEdgeWeight(edge)));
        }
    }
}
 
開發者ID:nlpub,項目名稱:watset-java,代碼行數:13,代碼來源:CommandWatset.java

示例6: getOppositeVertex

import org.jgrapht.Graph; //導入方法依賴的package包/類
public static IShape getOppositeVertex(final Graph<IShape, IShape> g, final IShape e, final IShape v) {
	final IShape source = g.getEdgeSource(e);
	final IShape target = g.getEdgeTarget(e);
	if (v.equals(source)) {
		return target;
	} else if (v.equals(target)) {
		return source;
	} else {
		return v.euclidianDistanceTo(source) > v.euclidianDistanceTo(target) ? target : source;
	}
}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:12,代碼來源:GamaSpatialPath.java

示例7: getPathsFromGraphHopper

import org.jgrapht.Graph; //導入方法依賴的package包/類
private List<Path> getPathsFromGraphHopper(Graph<AutomatVertex, DefaultEdge> completeGraph) {
        LOG.info("--- getPathsFromGraphHopper ---");

        final Set<AutomatEdge> automatEdges = Sets.newHashSet();
        final Iterator<AutomatVertex> graphIterator = new DepthFirstIterator<>(completeGraph);
        while (graphIterator.hasNext()) {
            final AutomatVertex vertex = graphIterator.next();
            Set<DefaultEdge> edges = completeGraph.edgesOf(vertex);

            for (DefaultEdge edge : edges) {
                AutomatVertex source = completeGraph.getEdgeSource(edge);
                AutomatVertex target = completeGraph.getEdgeTarget(edge);
                automatEdges.add(new AutomatEdge(source, target));
            }
        }

        final List<Path> paths = Lists.newArrayList();

        final int count = automatEdges.size();
        int idx = 0;
        int errors = 0;
        final StopWatch stopWatch = new StopWatch("route");
        for (AutomatEdge automatEdge : automatEdges) {
//            if (idx == 10) break;
            stopWatch.start();
            final Path computedPath = graphHopperGetPath(automatEdge.source, automatEdge.target);
            if (computedPath != null) {
                paths.add(computedPath);
            } else {
                errors++;
            }
            stopWatch.stop();
            if (idx % 1000 == 0) {
                LOG.info(String.format("%.2f %s", (float) idx / (float) count * 100.0f, "%"));
            }
            idx++;
        }
        LOG.info(String.format("%.2f %s", (float) idx / (float) count * 100.0f, "%"));
        LOG.info(stopWatch.shortSummary());
        if (errors > 0) {
            LOG.error("Errors count is {} which is {} from all data {}", errors, String.format("%.4f %s", (float) errors / (float) automatEdges.size() * 100.0f, "%"), automatEdges.size());
        }
        return paths;
    }
 
開發者ID:bedla,項目名稱:parkovani-v-praze,代碼行數:45,代碼來源:GraphDataLoaderController.java


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