Results 1 to 10 of 10

Thread: Big problem...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Trondheim, Norway
    Posts
    65

    Question

    How do I say this?

    Let's try...

    I'm doing a program that finds a path between two given points. All points have an integer value, and they reside in an array, like this:

    100 - 101
    100 - 105
    100 - 108
    101 - 102
    101 - 108
    102 - 224
    103 - 224
    ...
    108 - 120
    ...
    120 - 224


    This means that from 100, the path goes either to 101, 105, or 108.

    If the given start and end points were 100 - 224, the answer path would be 100-101-102-224 OR 100-108-120-224.

    But how do I make this program?
    Where do I start?

    Thanks in advanks...

    D

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Are you looking for any path or the shortest path? You could do a brute force search on all possible paths but this rapidly becomes difficult if the number of nodes/chains in each path is even moderately large.

    Few more details please, i.e. Number of nodes, limitations on the array, max array entries, length of the path etc.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  3. #3
    Lively Member
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    89

    Thumbs up

    the easiest way is to use prolog (its backtracking facilities)

    your paths will be stored as
    path(100,101).
    path(101,100).
    path(101,105).

    and so on

    the function is

    getpath(X,Y).
    getpath(X,Y):- getpath(X,Z),print(X),print(" - "),print(Y),getpath(Z,Y).

    to find the shortest path is NP complete problem which is best to solved in ECLIPSE prolog.



  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Trondheim, Norway
    Posts
    65
    Paulw: I'm kinda looking for any path. The Array(2D) have 110 x 3 elements. The path won't have more than 30 nodes.

    Klintsovi: Prolog is something I don't know anything about. Please fill me in.

    Thanks.

    D

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    I'll think about this one. As Klitsovi says, this is a classic Network Path problem.

    Somewhere, way back, I think I wrote some code to create a tree structure to do this. I'll have a look.

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Trondheim, Norway
    Posts
    65
    Have you found it yet?


  7. #7
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Nope. Too many beers at lunch. Probably be Monday - is that OK?

    Basic approach is to define a structure with pointers to the next node, each node also has pointers to the next node etc. Each unique node is a destination so you can set up the start point (root node) and possible destinations, if you have found the destination you then 'walk' back through the pointers to find the route.

    Is that clear.

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Trondheim, Norway
    Posts
    65
    I'm starting to get the hang of it. I'm doing it backwards, kinda convinced that's the way to do it. Still some debugging left to do (endless loops etc.)

    Beer at lunch rules.

    D

  9. #9
    Lively Member
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    89

    Thumbs up

    Send us the code or the description of an algorithm it will be quite interesting to see the solution to the problem in VB

  10. #10
    Lively Member
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    89
    here is a possibly usefull link

    http://hissa.nist.gov/dads/HTML/travelsales.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width