Shortest Path Algorithm:

Hi,
I have about 20,000 (double) points and trying to find a shortest path between any two. I know that the best algorithm for doing that is Dijkstra's one. What is the best data structure for this? I read that usually heaps but the time it needs to sort the list is too long, maybe some one knows a better way? Maybe there is another algorithm that solves this problem? Please give me any suggestion about anything that I said above.
Thank you in advance.

I don't know no Dijkstra's algorithm for this problem. The only algorithm of Dijkstra for something like that that I know is to find the shortest path between two nodes in a weight network.
I think that the lower bound for what you are trying to do is the same lower bound for sorting the points, so I think that the best you can do is to apply a good sorting algorithm (like quicksort, mergesort, heapsort or shellsort).
The best data structure depends about how much info do you have previously about the number of points and memory that you have available. If you know that the max number of points that you'll work can be fit in the available memory, then the best data holder to use is an array (it's aways the fastest). If you'll see it as an array or as stack (for example) depends on the algorithm that you'll choose to sort the points.
One last tip: if you choose using a List, prefer the ArrayList over LinkedList. LinkedList is slower than ArrayList for almost all kind of operations. If you'll work with a lot of elemts, do some testing before pick one of the two.
Hope it helps,
RGB

Similar Messages

  • Best shortest path algorithm ??

    Hi
    I am developing an application to guide a user from one point to another. I need to work out the shortest path between these two points.
    Is Dijkstra's algorithm the best to use? or should I be looking for a different one? I am looking for speed.
    Thanks

    Choosing a "single source shortest path" algorithm depends on if you are going to use a weighted or not weighted graph, if all weights are non-negative or negative etc. If negative -weight edges are allowed, Djikstra's algorithm can not be used. Instead you can use the Bellman-Ford algorithm.
    The running time of Djikstra's algorithm is lower than that of the Bellman-Ford algorithm. Runningtime for the Bellman-Ford algorithm is in general O(V^2E). Because Djikstra's algorithm always chooses the "closest" vertex (in a weigthed directed graph G=(V,E)) , we say it uses a greedy strategy. This strategy does not always yield optimal result. How fast the Djiktra algorithm is, depends how the min-priority queue is implemented. f.example: if you use the linear array implementation of the min-priority queue, the runningtime for Djikstra's algorithm is O(v^3) while a binary min-heap implementation of min-priority queue gives a runningtime of O(V E lg V).

  • Shortest Path Algorithm with Djikstra

    Hi all,
    im developing a shortest path searching techniques by using Djikstra's algorithm. My search space is very huge and it is about 100,000 nodes or we can call it Vertex. I store all the nodes and weight of edges in MySql as follows:
    From | To | PathCost
    A B 2
    B A 2
    A D 9
    D A 9
    B C 7
    C B 7
    B E 5
    E B 5
    C D 5
    D C 9
    Whenever the class receive any request from someone who want to go from point A to point Z, it will load the data from mysql by using "Select * FROM table WHERE From='Variable' ", and declare it as new Vertex, and perform the search. The reason i load it from MySql everytime i receive a new request is because any new node can be added to database anytime.
    In a nut shell, im developing a system to search for a shortest path in real world, i represent buildings as a Vertex, and road as edges, any idea of what can i improve my current djikstra searching method or any new developement to reduce the running time to lowest??
    regards,
    howsen

    minimal spanning tree != shortest path...
    Mr. Pike is indeed correct. Consider this simple example. arrange a bunch of dots around the rim of a circle. Consider the distance between them to be just the standard measure of distance in the plane. Assume that the points are fairly evenly spaced, but not exactly evenly spaced.
    The minimal spanning tree, which you got by first joining the two closest points and then the next two, and then by joining more points to that structure, will end up looking like a letter C going around the circle and leaving a gap between the two points that were the furthest apart on the circle.
    Every point connects to every other point, possibly by passing through other points and it is minimal because it left out the widest gap.
    On the other hand, the quickest way to get from one tip of the C to the other tip is to go straight from the one to the other, not to walk all the way around the circle following a path that goes through every single other point in the system.
    Reducing a graph to a minimal spanning tree, gets you a single subgraph of the original grpah that has the least total distance. That, unfortunately, has nothing to do with telling you the fastest way to get from point A to point B traveling along the original graph.
    hence minimal spanning tree != shortest path...

  • Shortest Path Algorithm. Need help.

    Hey, Im having trouble coming up with an algorithm for a shortest path. I have an NxN weighted matrix and need to get from the upper left corner to the lower right corner. The length of the path must be the shortest possible for the number of moves and total weight (ie. a 3X3 matrix would use 4 moves, a 4X4 uses 6 and a 5X5 uses 8).
    im using a 2-dimensional array like matrix[x][y] with the storage at this location being a random integer.
    I came up with some guidelines:
    1) the path can never move left because it would break the shortest moves requirement.
    2) the path can never move up for the same reason.
    when traversing through the matrix if x == N then go down to N,N. If y == n go right until N,N.
    I can visualize how to do it. Its just putting my algorithm into a program is beyond me right now.
    Any help would be appreciated greatly.

    Dijkstra's algorithm only works on a weighted graph.
    I have a weighted matrix.
    Its like a chess board where every square has a
    number on it. I have to get from the upper left to
    the lower right using as little squares as possible
    and then amongst those paths find the one with the
    smallest weight or total.So something where individual squares have a certain toughness to get through, then?
    Yeah, A* will own that...
    I really don't want to write a tutorial on how to find the shortest path. But basically, you need to have a queue of paths. For each iteration until you find your goal, you pop the path with the least cost and you find the four paths you could get from it (move up, down, left, and right).
    The key here is the cost function (heuristic). It must approximate the actual cost of a path WITHOUT over-approximating.
    For your problem, you should probably factor in cost of the path so far, and the lowest possible expectable distance from the end of the path you're considering to the goal (think "distance formula").
    Also, since these are general algorithms, you should probably code them up to work with an arbitrary start/end, instead of concrete values.
    ~Cheers

  • Shortest path code

    hi
    if nyone cud give me the code for finding the shortest path between 2 points but in this case all the paths have equal weights i.e. the shortest path would be the involvement of minimum number of nodes between the start & the end node.
    Please am stuck up if anyone can provide me with the code.
    Thanks in advance

    Related to Dijkstra's shortest path algorithm if all edges have equal
    weight, just the heap management (priority queue) will be much simpler.
    If the graph to be traversed isn't too big, a simple linear array could do the
    job fine where entry i indexes paths of length i. Nothing much else is to
    be gained though: it stil will be a permanent graph labeling algoritm.
    kind regards,
    Jos

  • Cost Factor in Shortest Path

    Hi,
    I need a little help.
    I am performing routing on geodatic data (i.e., locations with Lat/Long).
    I think the AStar shortest path algorithms are finding the shortest path on the basis of distance betwwen two nodes.
    I am not quite sure whether they are taking care of the cost column in the link table.
    for eg., say A-B-C and A-D-C are two alternative routes from A to C .
    such that A-B-C is the shortest path on the basis of geodatic distance between the locations A an C.
    But may be the cost-wise A-D-C would have been a shorter path.
    So, which path will the algo return?
    Also I do not want to implement AStarCostFunction class and provide a distance function.
    Please help me out.
    Regards.

    Hi,
    Any/all cost-based analysis in the network data model is done using the cost column. If the cost column contains geodetic distances then that is what will be used.
    Hope this helps,
    Dan

  • Fitness for Shortest path using a genetic algorithm

    Hi.
    I have this problem:
    I'm doing a program that has a map and two points. the map has wall that are not valid positions.
    I have used a A* algorithm to calculate the shortest path and is working fine.
    now i'm implementing a genetic algorithm to solve the problem but i'm not having sucess.
    My genetic operator are directions (left, right, up and down).
    I'm not being able to find a goodfitness function to solve the problem.
    can someone tell me a god function or here I can found information about that?
    I have been searching on google and I have not yet had sucess.
    I have tryed two diferent fitness tecniques:
    - add 1 for each step and if it finds a wall or gets out of the map add the maximum value (mapsize*mapsize).
    - the other one is add the valid steps and if it finds a wall or gets out of the map add the number of necessary steps to gets to destination. the valid steps has a weight of 30% and the necessary steps has a weight of 70% (i have tryed to use diferent weight).
    Can someone help me?
    thanks

    How about adapting your TSP code as follows. Your graph G(V, E) has two special vertices: v_s and v_d (start and destination). Let a candidate solution consist of a permutation of V\{v_s, v_d}u{v_m} where v_m is a new marker vertex whose purpose is to allow you to treat part of the candidate solution as irrelevant. Given candidate solution v_0 v_1 v_2 ... v_n v_m v_n+1 ... the weight is c(v_s, v_0) + c(v_0, v_1) + ... + c(v_n-1, v_n) where c(v_a, v_b) is the cost of the edge ab.

  • Finding the shortest path router for the router tracking purpose

    Hi all,
    A Question asking you regarding to routers' tracking information.
    We keeps all the router infomation of our subnet in a file name "routers.txt" in this format:
    1 2 1
    2 4 1
    4 3 1
    1 3 5
    This states there are four routers, the distance between routers 1 and 2 is 1, between 2 and 4 is 1, etc.
    I need to write a Java program to keep track the shortest path between routers, I would understand that we can get this done easily in Java, but I am not a Java Savvy. I'm new in Java, would somebody help me to the right direction?
    In order to keep track the routers in our subnet easily,the output would look something like:
    Router 1
    To Router Distance Vector
    2 1 2
    3 3 2
    4 2 2
    Thanks very much,
    Cait.

    Hi kksenji,
    Well, because of the webform, it's not obvious to see. The output would be simple. From the input, for router 1 to router 2, the shortest distance is 1. For router 1 to router 3, the shortest distance is 3, for router 1 to router 4, the shortest distance is 2 and so on. The middle vector that it went through is 2 for every route. Hope this makes sense.
    Just try to solve the problem with the shortest distance, and I have a hard time to figure out the algorithm for this as well as how to get this started.
    Thanks, Cait.

  • Aco  implemenataion for shortest paths.

    has anyone used ant colony optimization algorithm for finding shortest paths other than for the tsp? please i need some help and advice. thanks

    sorry for not being specific and the insubsequent reply. am just doing some research on aco, i want to try and implement it for best bath planning on a map/graph. I've been looking around for some example on such and noticed that this algorithm is mainly used for tsp problem which got me questioning the possibility of my task. I just want to know if it is definitely possible with aco as i will give it a go in this case. Implementing this algorthm successfully is the main challenge of my project so i cannot contemplate another algorithm option. Thanks for your time.

  • Shortest path problem

    hello,
    We have a street-layer (spatial). Now we should calculate the shortest path between two nodes. Does Oracle assist in this? Has anybody some experiences with this problem?
    Any help will be appreciated.
    regards
    Anna

    Well, I know there are several algorithms for this problem, but I wanted to know, if and how Oracle assist�s in this point. I get an answer from Oracle, that 10g include such functionality and now I am waiting on it.
    Thanks for your try to help.
    Monika-Anna

  • Shortest path which includes all subset

    In graphs (V,E) with negative edge weights but with no negative cycles , X <V and s, t in V .I need an algorithm to decide if exist in the graph ,shortest path from s to t with which includes all the nodes from X

    Unfortunately the problem you are trying to solve in NP-complete (it means that the best known algorithm for doing this is exponential in time with respect to size of X) so the best solution is to check every possibility. But if your graph has some special form there may be efficient solution for this problem. In general it's special case is finding [Hamiltonian path|http://en.wikipedia.org/wiki/Hamiltonian_path].

  • Shortest path calculation in huge spatial network

    Looks like I have to load the whole network in order to perform shortest path calculation.
    such as NetworkManager.shortestPathAStar, NetworkManager.shortestPath
    Suppose the network is too big to be loaded at one time, what is the possible solution in Oracle spatial to solve this issue???

    I can’t think of a way of analysing the network in chunks as it would increase the complexity of the calculation and may miss routes. If you know the start and end point have you considered drawing a connecting line between the two, buffering it and just loading the network inside the area.
    You would need to check the route by increasing the buffer size and finding the shortest route again.
    Another option could be to divide the network into primary and secondary routes. Find the route from the start to the nearest primary node and from the end point to the nearest primary point then connect the primary nodes. Based in a quick Google this is sounds a bit like the algorithms Garmin and Tom Tom use.
    Message was edited by:
    grahamallan

  • Shortest path between two arbitrary point in the network

    Hi All,
    In oracle NDM, it's possible to find shortest path between two nodes (e.g. using SDO_NET_MEM.NETWORK_MANAGER.SHORTEST_PATH), but I need to find shortest path between 2 points which are on the network edges. I suppose I should use (Interface SubPath) in network java apis. However I want to do it via PLSQL api. Should I code it myself or there exists a function?
    Any help is appreciated.
    Edited by: Fa on Dec 15, 2011 2:51 AM

    pritamg wrote:
    I have to build an application in which the user will draw the graph by creating nodes and edges.and then the start node will be marked.Then the shortest paths to other nodes will be displayed.Give me any possible clue how to start.I am in deep deep trouble.I have to use Dijkstra's Algorithm.
    please help some one...pleaseDo you know Dijkstra's Algorithm for shortest path? I believe that one was also called the traveling salesman problem. You can easily Google to find out what it is.
    Did you listen to your instructor when he/she did his/her lectures on recursion and halting contitions? If not, then please go talk to him/her and read your book, the forum is not a place to try to learn a basic concept that you should have paid attention in class for the first time.
    If you have code and you have specific questions post them and we will be glad to help, but we are not here to develop your homework solutions for you, no matter how that may affect your future.

  • Shortest path for Maze !

    Sorry guy i know this topic look familiar but i have been "turn the whole internet updown" but it does seen to have see any source code for maze using Dijkstra's Algorithm. I have try the back-tracking method but i realise that they do not lead to the shortest paths if the maze is too complicated. I even have 12 different different test but sad nope of them took the shortest paths in this maze . I hope some one can help me .
    The original Maze
    =================
    +---------+-------------+---+
    |         |             |   |
    +-+ + +---+-------+ +---+ +-+
    |   |     |             |   |
    +---+ +-+-+ +-+-+ + + +-+-+ +
    |       |     |     |     | |
    +-+ +-+ + +---+---+-+ + +-+ |
    | |  v    |   |   |   |     |
    | +-+ +-+ | +-+-+ + +-+ +-+ |
    | |   |   |             |   |
    | | +-+---+-----+---+-+ | + |
    | | |           |   |   | | |
    | + | +---+-+ +-+ + + +-+ | |
    |   |  X  |       |       | |
    +---+-----+-------+-------+-+
    Robot location is at X :7 Y :5
    The goal is at location X =13  Y =7
    this is the Test calling solveTest1 method
    =============================
    +---------+-------------+---+
    |.........|.............|...|
    +-+.+.+---+-------+.+---+.+-+
    |...|.....|******* ***  |...|
    +---+.+-+-+*+-+-+*+*+*+-+-+.+
    |.......|***  |  ***|*....|.|
    +-+.+-+.+*+---+---+-+*+.+-+.|
    |.|..v****|   |   |***|.....|
    |.+-+.+-+.| +-+-+ +*+-+.+-+.|
    |.|...|...|        *****|...|
    |.|.+-+---+-----+---+-+*|.+.|
    |.|.|*********..|***|***|.|.|
    |.+.|*+---+-+*+-+*+*+*+-+.|.|
    |...|***  |  *****|***....|.|
    +---+-----+-------+-------+-+
    this is the Test calling solveTest2 method
    =============================
    +---------+-------------+---+
    |.........|.............|...|
    +-+.+.+---+-------+.+---+.+-+
    |...|.....|*******.***  |...|
    +---+.+-+-+*+-+-+*+*+*+-+-+.+
    |..*****|***  |..***|*....|.|
    +-+*+-+*+*+---+---+-+*+.+-+.|
    |.|**>.***|...|...|***|*****|
    |.+-+.+-+ |.+-+-+.+*+-+*+-+*|
    |.|...|   |........*****|***|
    |.|.+-+---+-----+---+-+.|*+.|
    |.|.|*********  |***|...|*|.|
    |.+.|*+---+-+*+-+*+*+.+-+*|.|
    |...|***  |  *****|*******|.|
    +---+-----+-------+-------+-+
    this is the Test calling solveTest3 method
    =============================
    +---------+-------------+---+
    |         |             |   |
    +-+ + +---+-------+ +---+ +-+
    |   |     |***********..|   |
    +---+ +-+-+*+-+-+ + +*+-+-+ +
    |       |***..|     |***..| |
    +-+ +-+ +*+---+---+-+ +*+-+ |
    | |  >****|   |   |   |*****|
    | +-+ +-+.| +-+-+ + +-+ +-+*|
    | |   |...|             |***|
    | | +-+---+-----+---+-+ |*+ |
    | | |*********..|***|   |*| |
    | + |*+---+-+*+-+*+*+ +-+*| |
    |   |***  |..*****|*******| |
    +---+-----+-------+-------+-+
    this is the Test calling solveTest4 method
    =============================
    +---------+-------------+---+
    |         |             |   |
    +-+ + +---+-------+ +---+ +-+
    |   |     |***********..|   |
    +---+ +-+-+*+-+-+ + +*+-+-+ +
    |..*****|***..|     |***..| |
    +-+*+-+*+*+---+---+-+ +*+-+ |
    | |**>.***|   |   |   |*****|
    | +-+ +-+.| +-+-+ + +-+ +-+*|
    | |   |...|             |***|
    | | +-+---+-----+---+-+ |*+ |
    | | |*********  |***|   |*| |
    | + |*+---+-+*+-+*+*+ +-+*| |
    |   |***  |..*****|*******| |
    +---+-----+-------+-------+-+

    public boolean solve (int row, int column) {
          boolean done = false;
          if (valid (row, column)) {
             grid[row][column] = 3;  // cell has been tried
             if (row == grid.length-1 && column == grid[0].length-1)
                done = true;  // maze is solved
             else {
                done = solve (row+1, column);  // down
                if (!done)
                   done = solve (row, column+1);  // right
                if (!done)
                   done = solve (row-1, column);  // up
                if (!done)
                   done = solve (row, column-1);  // left
             if (done)  // part of the final path
                grid[row][column] = 7;
          return done;
       }  // method solvea typical code which i got from the net .I realise it was commonly use.

  • Help needed in a shortest path search problem..

    Basically the problem is that there is a network of nodes with different paths to other nodes and I am supposed to find a shortest path from a random node to another random node.There are other criteria like weight, capacity etc. but that shouldnt affect the search algorithm... What is the best way to do this type of problem? Example would be great,thanks!

    what about Breadth first search? Also for Dijkstra's, it seems to be dependent only on the weight of paths but if the paths have same weight, how do i go back to the previous node if a path wasn't found?

Maybe you are looking for

  • Problem using a SQL database Catalogue to insert data to a table

    I am developing with Version: 10.3.1.0, Build: #99765.... as part of a step in my process I need to store some data in an audit table. I have setup the SQL Catalogue entry and then use the following code: sentMail is defined as a local variable sentM

  • Purchase order condition type price is changed

    Hi Experts, After the GR has completed.. through work flow batch job ,the main condition type ZRUP( Roll up price) is changed ....Now for invoice verfication system using the new price not the price in which GR has been done. Basically a subcontract

  • Has anyone had a problem with the letters literally rubbing off the keyboard?

    Has anyone had a problem with the letters actually disappearing from the keybord, like being gradually rubbed out? My macbook air had this problem one year after purchase. They fixed it for free. Now, a year later, I have the same prob. Apple doesnt

  • SCO permissions to access runbooks remotely from web console

    Hi. I have single server SCO 2012 R2 deployment. I need to give some users access to the runbooks (to execute them) via the web console. So I've created a group in AD, made the users members of this group and configured the folder permissions in Runb

  • Playback garbled

    When I try and watch Apple keynotes the video and audio playback are jumpy and garbled. Windows & Quicktime are fully up to date. I have tried uninstalling and reinstalling quicktime - no help. I can watch videos in iTunes no problems. My Internet co