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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create one predicate from fact base

Status
Not open for further replies.

misoijnr

Programmer
Nov 17, 2010
32
0
0
BE
hi guys,
the following are facts from my database for prolog,
node represent points with ID n lat and long
node_tag has similar ID with nodes n more description all the way to way_tag, how do i create a predicate(s) to help me generate one one list with one node and link it to all the rest, please help

node(46315543, 52.35548, 4.84315).
node(46315968, 52.35558, 4.84068).

node_tag(46315543, 'AND_nodes', 221526).

node_tag(46315543, 'source', 'AND').
node_tag(46315968, 'AND_nodes', 221460).

node_tag(46315968, 'source', 'AND').



way(7382895, [46315543, 46315628, 46315973]).

way(7382896, [46315968, 46315971]).


way_tag(7382895, 'name', 'Hodenpijlkade').

way_tag(7382895, 'AND_nosr_r', 15207959).

way_tag(7382895, 'highway', 'unclassified').

way_tag(7382895, 'oneway', 1).


way_tag(7382896, 'name', 'Schipluidenpad').

way_tag(7382896, 'AND_nosr_r', 15207958).

way_tag(7382896, 'highway', 'unclassified').
 
You are not making yourself clear. What does it mean: "one one list with one node and link it to all the rest"? How about an example?
 
thanks for your quick response kathleen,
you see, i imported this data from open streetmap,
nodes represent points on the map, like a junction with an id
way has an id and has several nodes on it,
way_tag has an id and also the name of the road e.g highway

so, my problem was to create a program that give routes, but before that, how do i merge the given nodes to specific ways and way tags using one predicate? in other words, how do i merge lists with a unique key as the first element, i.e the id?

i dont know if i am asking correctly?
 
Since this doesn't look like a school project, I wrote this just for fun. See if you can use anything. Call 'menu' at the Prolog prompt to start the whole thing, and whenever you get prompted to enter a value, append a dot after it, like this:

enter ID: 46315543.


Code:
:-dynamic(node/3).
:-dynamic(way/2).

% some nodes
node(46315543, 52.35548, 4.84315).
node(46315968, 52.35558, 4.84068).
node(46315971, 52.35531, 4.84986).

% predicate to add a node to a way
add_node_to_way(WayID, NodeID) :-
	way(WayID, NodeList),
	node(NodeID, _, _),
	not(member(NodeID, NodeList)),
	retract(way(WayID, NodeList)),
	append(NodeList, [NodeID], NewNodeList),
	assert(way(WayID, NewNodeList)).

% main menu
menu :-
	write('1. list nodes\n'),
	write('2. list ways\n'),
	write('3. create node\n'),
	write('4. create way\n'),
	write('5. add node to way\n'),
	write('6. exit\n'),
	nl,
	write('your option: '),
	read(Option),
	process(Option).
menu :-
	menu.

process(1) :-
	node(ID, Lat, Long),
	writef('node with ID = %d, lat = %d and long = %d\n', [ID, Lat, Long]),
	fail.

process(2) :-
	way(ID, NodeList),
	writef('way with ID = %d and nodelist = ', [ID, NodeList]),
	write(NodeList),
	nl,
	fail.

process(3) :-
	write('enter node ID: '),
	read(ID),
	not(node(ID, _, _)),
	write('enter lat: '),
	read(Lat),
	write('enter long: '),
	read(Long),
	assert(node(ID, Lat, Long)),
	fail.

process(4) :-
	write('enter way ID: '),
	read(ID),
	not(way(ID, _)),
	assert(way(ID, [])),
	fail.

process(5) :-
	write('enter ID of node to add: '),
	read(NodeID),
	node(NodeID, _, _),
	write('enter ID of way to add to: '),
	read(WayID),
	way(WayID, _),
	add_node_to_way(WayID, NodeID),
	fail.

process(6) :-
	% exit point
	write('bye').
 
thanx,
let me try to play with this, will get back to you in-case of any problem,
do you think its possible to create itenerary list and a classification list of roads e.g highway etc?
i will give u a code i was using to list routes by using findall predicate
thanx again
 
From your code, some things just poped up in my mind for possible extensions, maybe u can play with it, thanx for your feedback, let me know what u come up with:
.Tell prolog what kind of user i am (e.g. pedestrian, cyclist,car driver, ...). then prolog take this information into account when constructing an appropriate route. For example, a cyclist cannot use a highway.
· Make it possible to ask for an itinerary between a departure and an arrival address which explicitly visits a number of user-specified places (i.e. the user can specify that he wants to go from A to C via B).
· Make it possible to ask the prolog for information such as "At what time do I have to leave Point A,to get to Point B,Amsterdam at 10:00AM?".
· Use human language interface like the one u just made such that the user can interact with the shell using
input like:
o how do I get from "NameA", Amsterdam to "NameB", Amsterdam

i wish i was in your level, but am working hard to also be responding to questions online
 
I didn't know such knowledge bases are available. You have to think why they exist, I'm sure the problem you are struggling to solve is already solved just from the existence of amsterdam.pl. Anyway, all your questions are not trivial at all, except for the first with pedestrian/cyclist/driver. What you need to do here in my opinion is to pass a user value as parameter. Instead of calling a predicate like compute_path(Start, End, PathNodes), you will call it like this: compute_path(User, Start, End, PathNodes) where User will be consistent with the user values from amsterdam.pl, so it will take values like pedestrian, cyclist, etc. Then this user value will be used in the backtracking algorithm of Prolog to disregard paths that are not suitable for that user value.

As for your other questions, it would be a lot of work for me, I think it's better that you search for answers yourself and start other topics here when you are in trouble.

You should consider studying graph algorithms, and graph algorithms in Prolog in particular. I'm sure you will need Dijkstra's algorithm somewhere in your code because navigation systems always return shortest paths of some kind, either shortest by length or by time. Prior to using Dijkstra, you need a way to compute distances from latitude/longitude coordinates. All in all, it's not something trivial and I'm pretty sure that you are reinventing the wheel here, but hey ... it's challenging to do such a navigation system in Prolog, I for one would do myself such a task if I had much free time, which I don't have :)
 
thanx though,
will be posting back anything i get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top