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


Java Graph.edgesOf方法代碼示例

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


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

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

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

示例3: buildAdjacencyMatrix

import org.jgrapht.Graph; //導入方法依賴的package包/類
protected INDArray buildAdjacencyMatrix(Graph<V, E> graph, Map<V, Integer> index) {
    final double[][] matrix = new double[graph.vertexSet().size()][graph.vertexSet().size()];

    for (Map.Entry<V, Integer> entry : index.entrySet()) {
        for (final E edge : graph.edgesOf(entry.getKey())) {
            final V neighbor = Graphs.getOppositeVertex(graph, edge, entry.getKey());
            matrix[entry.getValue()][index.get(neighbor)] = graph.getEdgeWeight(edge);
        }
    }

    for (int r = 0; r < matrix.length; r++) matrix[r][r] = 1;

    return Nd4j.create(matrix);
}
 
開發者ID:nlpub,項目名稱:watset-java,代碼行數:15,代碼來源:MarkovClustering.java

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