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...
'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.
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.
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...
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...
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 :)
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...
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
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: [...
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...
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...
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, _), %...
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...
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...
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...
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...
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...
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...
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...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.