Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search results for query: *

  1. kahleen

    member predicate

    Well, I really think that you should try yourself taking little steps to fulfill your goal. Asking some random guy on a forum solve each and every step is neither appropriate for learning, nor rewarding. Rewarding is when you discover by yourself that using this or that condition helps in...
  2. kahleen

    member predicate

    'start_algorithm' ends with a comma. It should end with a dot. So probably Prolog won't even compile your code, you shouldn't try to run it when the compilation reports error, but rather try to fix those errors.
  3. kahleen

    member predicate

    Anyway, I suggest you rely on node IDs for the moment and not names. Let the user enter IDs. From what I see, most of the nodes in your 'leuven.pl' don't have a node_tag with name information.
  4. kahleen

    member predicate

    and how do i replace the node Ids with name of node_tag?" Come on, this is easy. node(16387325, 50.8686270, 4.6984337). node_tag(16387325, 'name', 'Kardinaal Mercierlaan'). If the program expects user input (read(X)) and the user enters 'Kardinaal Mercierlaan', then X would take that...
  5. kahleen

    Find route in a system

    Glad to help. Without that rule, recursivity doesn't end. Prolog will successively shorten the list and will arrive at an empty list and no rule will tell it how to get the minimum out of that list, so it will fail. We have to provide the answer manually when the list gets to be 1-element long...
  6. kahleen

    Find route in a system

    Well, you forgot one min rule. Read the previous post, you will find 3 min rules. 1st step and 2nd step are both mandatory, you only have 2nd step PS: You're Romanian, so this means we're co-nationals :)
  7. kahleen

    Find route in a system

    Post the entire code then ... It works on my machine
  8. kahleen

    Find route in a system

    The only thing I suspect besides a typo is the call to 'link' from the 'route' predicate'. You have something like this: link(Ori, C,_, X), This is a call with 4 parameters. Do you have 'link' facts that take 4 parameters? Because I would say that 'link' should take 3 parameters: first...
  9. kahleen

    member predicate

    Make sure you replaced your original code with the one I provided. 'start_algorithm' should take 1 parameter, like in the last code snippet. The original version had 0 parameters, and that's what's causing the error
  10. kahleen

    Find route in a system

    The same principle applies. 1st step - a list of one element would be something like this: [ [Path, Length] ] ... the minimum of such a list is [Path, Length] In Prolog: minimum([[Path, Length]], [Path, Length]). 2nd step - a list with more than one element would be something like this: [...
  11. kahleen

    member predicate

    Ok, I didn't try on the large 'leuven.pl' file, so maybe it goes on forever because there are many results. Do the following modification to the code, so that Prolog will stop after each solution and print it to you: init :- consult('leuven.pl'), % get the nodes and ways...
  12. kahleen

    member predicate

    Ok, try adding this code in the upper part of the file where you have 'start', 'create_db' and 'process': :- dynamic(edge/3). This way you tell Prolog that it should expect to have some 'edge' clauses asserted dynamically, even though there are none defined explicitly, so it should stop...
  13. kahleen

    member predicate

    You don't need the cut. Those are only due to duplicated edges. Go back to where you have defined the 'process' predicate and modify it like below: process([]). process([_]). process([A, B | Rest]) :- distance(A, B, Dab), % compute distance A - B \+edge(A, B, _), %...
  14. kahleen

    Find route in a system

    Well, if there are 5 solutions to the 'route' predicate, your findall will gather in List their lengths ... so you will get 5 integer in List, you can compute the minimum or do whatever you want with them, but you will not have paths in there. You need to modify your findall to generate not a...
  15. kahleen

    member predicate

    What nodes did you try? Because as I told you, your current algorithm does not take into account that edge(A, B, X) also means edge(B, A, X), so maybe some possibilities are not considered. Make sure that you don't choose nodes that are not connected in your graph, or are connected but only if...
  16. kahleen

    member predicate

    Well, if you look at the code, it's 'do_something' that you need to call, not 'start_algorithm' 'do_something' calls 'init' and then 'start_algorithm' If you just call 'start_algorithm' directly, you won't be calling 'init', so your code won't find any 'edge' facts. 'init' does just that...
  17. kahleen

    Find route in a system

    Well, the result of findall is a list of L's. You need to use L in the goal of findall. It's something like this: findall(L, some_goal(..., L, ...), List) "findall values of L that satisfy some_goal(..., L, ...) and put them all in List" Your second parameter of findall has nothing to do...
  18. kahleen

    member predicate

    It will work, just make get_path take 3 parameters (add Path also as the 3rd). Also make sure you take into account that edge(A, B, X) also means edge(B, A, X). So when you implement the algorithm and your current node is Z, find a neighbor either by calling edge(Z, Neighbor, D) or by calling...
  19. kahleen

    member predicate

    You don't need to generate so many in 'graph.pl'. In fact, it's a mistake that we generated nodes in 'graph.pl' because now you have nodes duplicated both in 'leuven.pl' and in 'graph.pl'. So take out the 'listing(node)' line from the above code. This way you will only generate edges in...
  20. kahleen

    Find route in a system

    That's more difficult. You either have to gather all results in a single list using findall (if they are not too many) or use the assert mechanism of Prolog to always store in your knowledge base the shortest path. When you discover a shorter one, you erase the old shortest one and reassert the...

Part and Inventory Search

Back
Top