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

Java DijkstraShortestPath类代码示例

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

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



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

示例1: exampleGraph

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
/**
 * Shows how to create an FNSS Topology, convert it to a JGraphT Graph and
 * then compute shortest paths
 */
public static void exampleGraph() {
	// create a simple FNSS topology
	Topology topology = new Topology();
	topology.addEdge("1", "2", new Edge());
	topology.addEdge("2", "3", new Edge());
	
	// convert to JGraphT
	Graph<String, Edge> graph = JGraphTConverter.getGraph(topology);
	
	// Find shortest paths
	String source = "3";
	String destination = "1";
	List<Edge> sp = DijkstraShortestPath.findPathBetween(graph, source, destination);
	
	// Print results
	System.out.println("Shortest path from " + source + " to " + destination + ":");
	for (Edge e : sp) {
		System.out.println(graph.getEdgeSource(e) + " -> " + graph.getEdgeTarget(e));
	}
}
 
开发者ID:fnss,项目名称:fnss-java,代码行数:25,代码来源:ExampleJGraphT.java


示例2: findShortestPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
public boolean findShortestPath(int startVertex, int endVertex, List<Integer> result)
{
	DijkstraShortestPath<Integer, LocationEdge> dijkstra = new DijkstraShortestPath<Integer, LocationEdge>(graph, startVertex, endVertex);
	if (dijkstra.getPathEdgeList() == null){			
		System.err.println("There is no shortest path between startVertex "  + startVertex + " and endVertex " + endVertex);
		return false;
 
	} else {
		
		for(LocationEdge edge : dijkstra.getPathEdgeList())
		{
			if (!result.contains(edge.getSource()))
				result.add(edge.getSource());
			if (!result.contains(edge.getTarget()))
				result.add(edge.getTarget());
		}
		return true;
	}			
}
 
开发者ID:GIScience,项目名称:openrouteservice,代码行数:20,代码来源:TrafficLocationGraph.java


示例3: checkDeadlocks

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
/**
    * Verify deadlock situation from serviceToID to serviceFromID, i.e., checks
    * if the serviceFromID is not a children node of the serviceToID! If a deadlock
    * is detected, the composition is not possible
    * 
    * @param serviceToID - ID of the service that has an input in the service for composition
    * @param serviceFromID - ID of the service that provides an output in the service composition
    * 
    * @return true if a deadlock situation is found and false otherwise
    * 
    */
   public boolean checkDeadlocks(String serviceToID, String serviceFromID){
       
       // - We do this, because the  was generating errors
       // when we were trying to find deadlock in not connected graphs, i.e., graphs
       // with parts that are connected!
       //If serviceToID has no children nodes, deadlock can not occur
       if(graphComposition.outgoingEdgesOf(serviceToID).isEmpty())
           return false;
       
       //Run DijkstraShortestPath algorithm to find paths between serviceToID and serviceFromID
       List path = DijkstraShortestPath.findPathBetween(graphComposition, serviceToID, serviceFromID);
     
       //If no paths were found, deadlock situation can not occur. Otherwise, deadlock is detected
       if(path == null)
           return false; 
else
           return true;
   }
 
开发者ID:usplssb,项目名称:SemanticSCo,代码行数:30,代码来源:ServiceComposer.java


示例4: getPathLengthInEdges

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
/**
 * Gets the path length between two category nodes - measured in "edges".
 * @param node1 The first category node.
 * @param node2 The second category node.
 * @return The number of edges of the path between node1 and node2. 0, if the nodes are identical. -1, if no path exists.
 */
public int getPathLengthInEdges(Category node1, Category node2) {
    if (this.graph.containsVertex(node1.getPageId()) && this.graph.containsVertex(node2.getPageId())) {
        if (node1.getPageId() == node2.getPageId()) {
            return 0;
        }

        // get the path from root node to node 1
        List edgeList = DijkstraShortestPath.findPathBetween(undirectedGraph, node1.getPageId(), node2.getPageId());
        if (edgeList == null) {
            return -1;
        }
        else {
            return edgeList.size();
        }
    }
    // if the given nodes are not in the category graph, return -1
    else {
        return -1;
    }
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:27,代码来源:CategoryGraph.java


示例5: getShortestPathBetween

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
private DijkstraShortestPath<TaxiNode, TaxiEdge> getShortestPathBetween(TaxiNode tn0, TaxiNode tn1) {
	// in the cache?
	Map<TaxiNode, DijkstraShortestPath<TaxiNode, TaxiEdge>> pathsForTN0 = shortestPathCache.get(tn0);
	if (pathsForTN0 == null) {
		pathsForTN0 = new ConcurrentHashMap<>();
		shortestPathCache.put(tn0, pathsForTN0);
	}
	
	DijkstraShortestPath<TaxiNode, TaxiEdge> dsp = pathsForTN0.get(tn1);
	if (dsp == null) {
		dsp = new DijkstraShortestPath<TaxiNode, TaxiEdge>(graph, tn0, tn1);
		pathsForTN0.put(tn1, dsp);
	}
	
	return dsp;
}
 
开发者ID:gm-tools,项目名称:gm-tools,代码行数:17,代码来源:SnapTracksThread.java


示例6: getParseTreePath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
public List<GraphEdge> getParseTreePath(Artifact headWord1, Artifact headWord2) {
	
	List<GraphEdge> path = null;
	
	//link tokens
	 try {
		int word1Offset = headWord1.getWordIndex()+1;
		int word2Offset = headWord2.getWordIndex()+1;
		
		path = 
			DijkstraShortestPath.findPathBetween(sentenceTree, 
					headWord1.getContent()+word1Offset, 
					headWord2.getContent()+word2Offset);
	} catch (Exception e) {
		e.printStackTrace();
		System.out.println("error in getParseTreeDistance:"+headWord1+headWord2);
	}
	
	return path;
}
 
开发者ID:ehsane,项目名称:rainbownlp,代码行数:21,代码来源:DependenciesTreeUtil.java


示例7: findReachableSourceAttributes

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
private Set<AttributeRef> findReachableSourceAttributes(AttributeRef targetAttribute, DirectedGraph<AttributeRef, DefaultEdge> dependencyGraph) {
    Set<AttributeRef> result = new HashSet<AttributeRef>();
    for (AttributeRef attribute : dependencyGraph.vertexSet()) {
        if (!attribute.isSource()) {
            continue;
        }
        if (result.contains(attribute)) {
            continue;
        }
        List path = DijkstraShortestPath.findPathBetween(dependencyGraph, attribute, targetAttribute);
        if (path != null) {
            result.add(attribute);
        }
    }
    return result;
}
 
开发者ID:donatellosantoro,项目名称:Llunatic,代码行数:17,代码来源:CheckConflicts.java


示例8: findPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
/**
 * Find the list of point to be traversed from the start to the end using the DijkstraShortestPath algorithm.
 * 
 * @param graph
 *            the graph upon which we need to find the path
 * @param start
 *            the start node from which to navigate
 * @param end
 *            the end node to which to navigate to
 * @return the succession of node to traverse from start to end, empty if no path was found
 */
public static List<NdPoint> findPath(WeightedGraph<NdPoint, DefaultWeightedEdge> graph, NdPoint start,
        NdPoint end) {
    List<DefaultWeightedEdge> edgeList = DijkstraShortestPath.findPathBetween(graph, start, end);
    if (edgeList == null) {
        return new ArrayList<>(0);
    }

    List<NdPoint> path = new LinkedList<>();
    NdPoint current = start;
    path.add(current);
    // Add each path node, but also check for the order of the edges so that
    // the correct point (source or target) is added.
    for (DefaultWeightedEdge edge : edgeList) {
        current = GraphHelper.getOpposite(graph, edge, current);
        if (current != null) {
            path.add(current);
        }
    }
    return path;
}
 
开发者ID:eishub,项目名称:BW4T,代码行数:32,代码来源:PathPlanner.java


示例9: getPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的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


示例10: getPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的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


示例11: exampleWeightedGraph

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
/**
 * Shows how to create an FNSS Topology with weighted edges, convert it to
 * a JGraphT WeightedGraph and then compute shortest paths
 */
public static void exampleWeightedGraph() {
	
	// create unidrected topology
	Topology topology = new Topology();
	
	// Create edge with high weight and edge with low weight
	Edge edgeHighWeight = new Edge();
	edgeHighWeight.setWeight(1000);
	
	Edge edgeLowWeight = new Edge();
	edgeLowWeight.setWeight(1);
	
	// Assign edges to topology
	topology.addEdge("1", "4", edgeHighWeight);
	topology.addEdge("2", "3", edgeLowWeight);
	topology.addEdge("1", "2", edgeLowWeight);
	topology.addEdge("4", "3", edgeLowWeight);
	
	// convert to JGraphT
	WeightedGraph<String, DefaultWeightedEdge> graph = 
			JGraphTConverter.getWeightedGraph(topology);
	
	// Find shortest paths
	String source = "1";
	String destination = "3";
	List<DefaultWeightedEdge> sp = 
			DijkstraShortestPath.findPathBetween(graph, source, destination);
	
	// Print results
	System.out.println("Shortest path from " + source + " to " + destination + ":");
	for (DefaultWeightedEdge e : sp) {
		System.out.println(graph.getEdgeSource(e) + " -> " + graph.getEdgeTarget(e));
	}
}
 
开发者ID:fnss,项目名称:fnss-java,代码行数:39,代码来源:ExampleJGraphT.java


示例12: getPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
public List<ITableRecordReference> getPath()
{
	final List<ITableRecordReference> result = new ArrayList<>();

	final AsUndirectedGraph<ITableRecordReference, DefaultEdge> undirectedGraph = new AsUndirectedGraph<>(g);

	final List<DefaultEdge> path = DijkstraShortestPath.<ITableRecordReference, DefaultEdge> findPathBetween(
			undirectedGraph, start, goal);
	if (path == null || path.isEmpty())
	{
		return ImmutableList.of();
	}
	result.add(start);
	for (final DefaultEdge e : path)
	{
		final ITableRecordReference edgeSource = undirectedGraph.getEdgeSource(e);
		if (!result.contains(edgeSource))
		{
			result.add(edgeSource);
		}
		else
		{
			result.add(undirectedGraph.getEdgeTarget(e));
		}
	}

	return ImmutableList.copyOf(result);
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:29,代码来源:FindPathIterateResult.java


示例13: existsPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
private boolean existsPath(Set<Dependency> s1, Set<Dependency> s2) {
    for (Dependency dependency1 : s1) {
        for (Dependency dependency2 : s2) {
            List<DefaultEdge> path = DijkstraShortestPath.findPathBetween(dependencyGraph, dependency1, dependency2);
            if (path != null) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:dbunibas,项目名称:BART,代码行数:12,代码来源:GenerateStratification.java


示例14: getDestinos

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
public List<Integer> getDestinos(int inicio, int tirada){
	List<Integer> destinos = new ArrayList<Integer>();
	for (int i = 0; i < casillas.length; i++) {
		DijkstraShortestPath<Casilla, DefaultEdge> dijkstra = new DijkstraShortestPath<Casilla, DefaultEdge>(
				grafo, casillas[inicio], casillas[i]);
		GraphPath<Casilla, DefaultEdge> path = dijkstra.getPath();
		if (path.getWeight() == tirada)
			destinos.add(i);
	}
	return destinos;
}
 
开发者ID:Arquisoft,项目名称:Trivial4b,代码行数:12,代码来源:Grafo.java


示例15: getShortestPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
public GraphPath<Representation, ConvertFunction> getShortestPath(Representation startVertex,
    Representation endVertex) {
  try {
    return new DijkstraShortestPath<Representation, ConvertFunction>(this.mGraph, startVertex, endVertex).getPath();
  } catch (Exception e) {
    return null;
  }
}
 
开发者ID:ddf-project,项目名称:DDF,代码行数:9,代码来源:RepresentationsGraph.java


示例16: findRelatedAttributes

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
private Set<AttributeRef> findRelatedAttributes(AttributeRef attribute, Set<String> pathCache, DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph) {
    //All attributes corresponding to vertices of paths that pass throught the vertex of attribute
    Set<AttributeRef> result = new HashSet<AttributeRef>();
    for (AttributeRef otherAttribute : dependencyGraph.vertexSet()) {
        if (attribute.equals(otherAttribute)) {
            result.add(otherAttribute);
            continue;
        }
        String attributePair = buildAttributePair(attribute, otherAttribute);
        if (pathCache.contains(attributePair)) {
            result.add(otherAttribute);
            continue;
        }
        List<ExtendedEdge> outPath = DijkstraShortestPath.findPathBetween(dependencyGraph, attribute, otherAttribute);
        if (logger.isDebugEnabled()) logger.debug("Finding path between " + attribute + " and " + otherAttribute);
        if (outPath != null) {
            if (logger.isDebugEnabled()) logger.debug("Path found");
            addVerticesInPath(outPath, result, pathCache, dependencyGraph);
            continue;
        }
        List<ExtendedEdge> inPath = DijkstraShortestPath.findPathBetween(dependencyGraph, otherAttribute, attribute);
        if (logger.isDebugEnabled()) logger.debug("Finding path between " + otherAttribute + " and " + attribute);
        if (inPath != null) {
            if (logger.isDebugEnabled()) logger.debug("Path found");
            addVerticesInPath(inPath, result, pathCache, dependencyGraph);
        }
    }
    return result;
}
 
开发者ID:donatellosantoro,项目名称:Llunatic,代码行数:30,代码来源:FindAttributesInSameCellGroup.java


示例17: existsPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
private boolean existsPath(EGDStratum t1, EGDStratum t2) {
    for (ExtendedEGD dependency1 : t1.getExtendedDependencies()) {
        for (ExtendedEGD dependency2 : t2.getExtendedDependencies()) {
            List<DefaultEdge> path = DijkstraShortestPath.findPathBetween(dependencyGraph, dependency1, dependency2);
            if (path != null) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:donatellosantoro,项目名称:Llunatic,代码行数:12,代码来源:AnalyzeDependencies.java


示例18: isReachable

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
private boolean isReachable(AttributeRef attribute, Set<AttributeRef> initialAttributes, DirectedGraph<AttributeRef, ExtendedEdge> dependencyGraph) {
    for (AttributeRef initialAttribute : initialAttributes) {
        if (logger.isTraceEnabled()) logger.trace("Checking reachability of " + attribute + " from " + initialAttribute);
        if (!dependencyGraph.containsVertex(initialAttribute)) {
            continue;
        }
        List path = DijkstraShortestPath.findPathBetween(dependencyGraph, initialAttribute, attribute);
        if (path != null) {
            if (logger.isTraceEnabled()) logger.trace("Found!");
            return true;
        }
    }
    return false;
}
 
开发者ID:donatellosantoro,项目名称:Llunatic,代码行数:15,代码来源:FindAttributesWithLabeledNulls.java


示例19: testDijkstra

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
/**
 * Rigourous Test :-)
 */
public void testDijkstra() {
	// Create the graph object; it is null at this point
	DefaultDirectedWeightedGraph<Integer, DefaultEdge> dag = new DefaultDirectedWeightedGraph<Integer, DefaultEdge>(
			DefaultEdge.class);

	// add a number of vertices
	for (int i = 0; i < this.numberOfEdges; i++) {
		Integer nextV = new Integer(i);
		dag.addVertex(nextV);
	}

	Set<Integer> vertices = dag.vertexSet();
	// fill in edges
	Random rand = new Random();
	for (Integer one : vertices)
		for (Integer other : vertices) {
			if (other != one) {
				DefaultWeightedEdge edge = new DefaultWeightedEdge();
				dag.addEdge(one, other, edge);
				dag.setEdgeWeight(edge, rand.nextDouble());
			}
		}

	// get shortest path in two ways
	Iterator<Integer> iter = vertices.iterator();
	Integer startVertex = iter.next();
	Integer endVertex = iter.next();

	DijkstraShortestPath<Integer, DefaultEdge> path1 = new DijkstraShortestPath<Integer, DefaultEdge>(
			dag, startVertex, endVertex);

	Dijkstra path2 = new Dijkstra(dag, startVertex, endVertex);

	assertEquals(path1.getPathLength(), path2.getPathLength());

}
 
开发者ID:yubinbai,项目名称:javatemplates,代码行数:40,代码来源:DijkstraTest.java


示例20: getShortestPath

import org.jgrapht.alg.DijkstraShortestPath; //导入依赖的package包/类
@Override
public ImmutableList<Eventable> getShortestPath(StateVertex start, StateVertex end) {
	readLock.lock();
	try {
		return ImmutableList.copyOf(DijkstraShortestPath.findPathBetween(sfg, start, end));
	} finally {
		readLock.unlock();
	}
}
 
开发者ID:aminmf,项目名称:crawljax,代码行数:10,代码来源:InMemoryStateFlowGraph.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java ClusterJoinResponseMessage类代码示例发布时间:2022-05-21
下一篇:
Java ConsumerFactory类代码示例发布时间: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