开发者

creating predicates from facts from a database in prolog from the open street map project

i downloaded some facts from open streetmap project, you can download it here http://www.mediafire.com/?15pttpp847ld71x This program am trying to come up with will help a user get itinerary from one place to another giving shortest routes possible, someone can tell me how to implement Dijkstra's algorithm to search paths, also i had this predicate in mind -compute_path(User, Start, End, PathNodes) where User will be consistent with the user values from amsterdam.pl Am trying to add extensions, maybe u can play with it, e.g the following: .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 kindly get back to me if u were able to implement this, i will appreciate so much, am new in Prolog and trying to be a fast learner.

this is the code i have tried to come up with

:-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'). 


Some years ago I was doing something similar with the so called A* search. This search is better suited for planar non-maze like problems than Dijkstra's algorithm. A* search adds to Dijkstra's algorithm a current node to goal node distance estimator and combines it with the already archived minimal distance.

A very good result can be obtained when main roads are differently weighted compared to smaller roads. So that the algorithm first search the main roads, and only diverts into smaller roads when close to the goal or start. A very nice book which develops the A* algorithm is the following:

Nilsson, N. J. (1980). Principles of Artificial Intelligence. Palo Alto, California: Tioga Publishing Company.

Best Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜