shortest-path

What are some good methods to finding a heuristic for the A* algorithm?

好久不见. 提交于 2019-12-30 06:49:16
问题 You have a map of square tiles where you can move in any of the 8 directions. Given that you have function called cost(tile1, tile2) which tells you the cost of moving from one adjacent tile to another, how do you find a heuristic function h(y, goal) that is both admissible and consistent? Can a method for finding the heuristic be generalized given this setting, or would it be vary differently depending on the cost function? 回答1: Amit's tutorial is one of the best I've seen on A* (Amit's page

is there is a route from city a to city b in no more than x days?

旧街凉风 提交于 2019-12-29 08:01:52
问题 I was in a trading firm interview, I was asked this question, you are travelling accross the state in a buses, the buses can stop at any C possible cities and you need to find a way to go from city a to city b. There are total B buses, each of which travels between two cities. All buses travel on a daily bases, for example each bus x leaves some city c1 on day d1 and arrives at another city b1 on another day d2 (d2>d1). Assume that if you arrive at a city on day d, you can catch any bus

Distance metric heuristic informedness

假装没事ソ 提交于 2019-12-25 08:49:42
问题 Having Manhattan distance heuristic and a heuristic which takes the greater value of (square root(x1-x2),square root(y1-y2)) How would you consider their informedness and are they admissable in searching the shortest path in a grid from a to b, where only horizontal and vertical movements are allowed ? While testing them in all the cases the second heuristic always takes the diagonal ways and sometimes its number of discovered nodes is significantly smaller than Manhattan. But this is not

Shortest Path Finder from CSV in C#

时间秒杀一切 提交于 2019-12-25 08:08:00
问题 Let's say I have the following CSV Sydney,Dubai,1 Dubai,Venice,2 Venice,Rio,3 Venice,Sydney,1 Sydney,Rio,7 First field is From second is To and third is Duration . I need a method which can take a From input and spit out the shortest path to all other To field in the following format- Selected City: Sydney To 1: Dubai, Smallest Path Length: 1, Path: Sydney, Dubai. To 2: Venice, Smallest Path Length: 3, Path: Sydney, Dubai, Venice. To 3: Rio, Smallest Path Length: 6, Path: Sydney, Dubai,

Find the shortest path between two nodes in a graph in (Prolog) and display the result as array

自作多情 提交于 2019-12-25 04:34:07
问题 [ ] How can I write (using print_path ) a rule to print the path from one node to another if exists Print_path(a, c, Res) ---> Res=[a, f, c] What I did was : path(a,b). %there is a path from a to b path(a,f). path(b,c). path(c,d). path(c,e). path(e,d). path(f,g). path(f,c). path(f,e).` I do not know what to do next. 来源: https://stackoverflow.com/questions/41112132/find-the-shortest-path-between-two-nodes-in-a-graph-in-prolog-and-display-the

Finding shortest cycles in directed or undirected graph

China☆狼群 提交于 2019-12-24 14:23:48
问题 I'm looking for an algorithm to find the shortest cycle in a directed or undirected graph. For example, for node 3, the algorithm could return: cycle 1 : 3->10->11->7->8->3 cycle 2 : 3->10->9->8->3 For these cycles and the shortest is cycle 2, at four vertices. I did some research and could find the Dijkstra algorithm, DFS, BFS and some others but they always show a path not a cycle. PS : the arrows are not significant. Thank you for your help. 来源: https://stackoverflow.com/questions/47795348

How can I compute the distance between two patches?

三世轮回 提交于 2019-12-24 12:04:47
问题 I need to find the minimum distance between patches in front of my agent to a certain patch (goal), in order to select the patch that would create the most optimal (shortest) path. The primitive distance only requires one argument so I can't use it as is for this function. 回答1: The distance primitive only requires one argument, yes, but it is a "patch or turtle primitive": it must be run in the context of a particular agent by "asking" it for its distance to another, so you can think of the

Print the shortest path to the java console using orientdb

淺唱寂寞╮ 提交于 2019-12-24 08:25:27
问题 I want to print in the Java console shortestpath between two vertices. I can not print anything or if you have any way to do that would appreciate it. String subquery = "Select shortestpath(17:10, 17:14, BOTH) "; Iterable<OrientVertex> result = orientDBGraph.command(new OSQLSynchQuery<OrientVertex>(subquery)).execute(); Assert.assertTrue(result.iterator().hasNext()); System.out.println(result); for (OrientVertex d : result) { System.out.println("Shortest path from " + ((OrientVertex) d

Shortest path between two nodes in an infinite, complete binary tree?

喜你入骨 提交于 2019-12-24 07:30:06
问题 Suppose we have an infinite, complete binary tree where the nodes are numbered 1, 2, 3, ... by their position in a layer-by-layer traversal of the tree. Given the indices of two nodes u and v in the tree, how can we efficiently find the shortest path between them? Thanks! 回答1: @Jonathan Landrum pointed out the solution in his comment. This answer fleshes out that solution. In any tree, there is exactly one path between any two nodes. Therefore, this problem boils down to determining the

Shortest Path, Least Turns Algorithm

≯℡__Kan透↙ 提交于 2019-12-24 06:45:48
问题 There is a square grid with obstacles . On that grid, there are two members of a class Person . They face a certain direction (up, right, left or down). Each person has a certain amount of energy. Making the persons turn or making them move consumes energy (turning consumes 1 energy unit, moving consumes 5 energy units). My goal is to make them move as close as possible next to each other (expressed as the manhattan distance), consuming the least amount of energy possible. Keep in mind there