shortest-path

Graph path define issue

做~自己de王妃 提交于 2019-12-11 07:49:57
问题 The solution ppath(X,Y,M,Path,[Y|Path]) :- edge(X,Y,M),\+ memberchk(Y,Path). path(X,Y,P,SoFar,Path) :- edge(X,W,M), \+ memberchk(W,SoFar), path(W,Y,N,[W|SoFar],Path), P is M+N. pravilo(X,Y,Z) :- aggregate(min(W), P^path(X,Y,W,[],P),Z). Here is the code i have. The question is that starting point is a, and ending point is z. There is an error after execution, the result is displayed like [z, c, h, b]. But the correct answer should [a,b,c,z]. Please help to fix my problem. 回答1: library

how to check if there exists a unique shortest path between two vertices in igraph

时光毁灭记忆、已成空白 提交于 2019-12-11 07:47:38
问题 I'd like to identify if there exist a unique shortest path or multiple shortest paths between two vertices with igraph. If I use length(all_shortest_paths(g, i,j) , that actually helps me, but I feel like there are so many redundant operations. I rather prefer first to get one shortest path with get.shortest.paths(g, i,j) , and then see if there is another. However, I could not figure out how to do this. Can someone help me how to identify whether there is another shortest path different than

What are the procedures that should be taken when there is a line of sight between two points in Theta star algorithm?

牧云@^-^@ 提交于 2019-12-11 05:21:20
问题 I'm working on Theta star algorithm and I need to implement in Python. As you all know, theta star depends on line-of-sight in its work. When there is a line-of-sight between two points, what will be the procedure here after discovering the line-of-sight?. I know, if there is no line-of-sight, it will work as Astar algorithm, but what about the procedure after discovering there is a line-of-sight, what the algorithm will do here? 来源: https://stackoverflow.com/questions/57565748/what-are-the

Find the shortest path between a given source and a set of destinations

a 夏天 提交于 2019-12-11 02:20:39
问题 You are given a weighted connected graph (20 nodes) with all edges having positive weight. We have a robot that starts at point A and it must pass at points B, D and E for example. The idea is to find the shortest path that connects all these 4 points. The robot also has a limited battery, but it can be recharged in some points. After researching on the internet I have two algorithms in mind: Dijkstra's and TSP . Dijkstra's will find the shortest path between a node and every other node and

Shortest path in a 3D maze

故事扮演 提交于 2019-12-11 02:09:13
问题 I'm trying to write a program to find the shortest path in a 3D maze using recursion. I am able to write the code that finds a random path through the maze but I'm wondering how I can modify my code in order to find the shortest path. Please note that I want to keep the recursive approach. Can someone suggest a solution? Here is a sample 2D maze: s XXXX XX X XXX Xe X One starts from s going to e . X is an obstacle and is the route. 回答1: It depends on the algorithm you are implementing. If you

How to find the shortest colored path?

谁说胖子不能爱 提交于 2019-12-11 01:52:30
问题 Given G=(V,E) Which is every edge has one of these three colors {green,red,blue}. We call a path "Colored Path" if he has all the three colors in it. Input: graph G(V,E),weight function w:E->Q+ , colored edges and vertices s . output: algorithm that finds for every vertices v, a shortest path from s that is Colored path My solution is to walk through the graph, and count for every vertex the number of colors that the path has. Create 3 copies of the graph named G1,G2,G3 For every v that c(v)

Shortest Path Algorithm : Uniform distances from one point to adjacent points

[亡魂溺海] 提交于 2019-12-11 01:44:58
问题 I am trying to develop an algorithm wherein I have a Location Class. In each class, I create a list of its adjacent Locations. I want to know, how can I get the shortest path from one Location to another. I am trying to look for different algorithms but it seems that they doesn't answer my problem. For example, I have a point A and I want to go to point B, A - - C - - H - - J | F- - K- -B My idea for this is if B is in the List of adjacent locations of A, then that is the shortest path. If

All shortest paths for weighted graphs with networkx?

落爺英雄遲暮 提交于 2019-12-11 01:14:38
问题 I have a graph composed by two different sets of edges. The first set is made by edges of weight 1 (list 1). The second set is made by edges of weight 2 (list 2). First, I create the graph with networkx and then use add_edges_from to add list 1 and list 2. I would like to compute all the shortest paths in this weighted graph. Basically I'm looking for the analogous of "all_shortest_paths" but with weights (looks like "dijkstra" module does not allow you to know all the possible routes between

find shortest path in a graph that compulsorily visits certain Edges while others are not compulsory to visit

巧了我就是萌 提交于 2019-12-10 23:39:10
问题 I have an undirected graph with about 1000 nodes and 2000 edges, a start node and an end node. I have to traverse from the start node to the end node passing through all the compulsory edges(which are about 10) while its not necessary to traverse through all the vertices or nodes. Is there an easy solution to this like some minor changes in the existing graph traversing algorithms? How do I do it? Thanks for help.:) This question is different from Find the shortest path in a graph which

Find the shortest path between two nodes in a graph in Prolog

穿精又带淫゛_ 提交于 2019-12-10 19:40:31
问题 I want to find the shortest path between two nodes in Prolog. I figured how to find all the paths between two nodes, but unfortunately the following code falls into loops: arc(a,b). arc(b,a). arc(b,c). arc(c,b). arc(c,d). arc(d,c). path(X,Y,[arc(X,Y)]) :- arc(X,Y). path(X,Y,[arc(X,Z)|P]) :- arc(X,Z), path(Z,Y,P). The code run is: ?- path(a,c,R). R = [arc(a, b), arc(b, c)] ; R = [arc(a, b), arc(b, a), arc(a, b), arc(b, c)] ; R = [arc(a, b), arc(b, a), arc(a, b), arc(b, a), arc(a, b), arc(b, c)