%% Introduction to Artificial Intelligence %% Homework 3 starter program for completion by Oct 18, 2000 %% Look for the pattern %% %% ************************************************** %% YOU COMPLETE THIS %% ************************************************** %% %% to find the places where your definitions should go. :- use_module(library(heaps)). %% This material defines a relation %% %% segment(Start, End, Direction, Distance, Name) %% %% for ways to get around Busch campus by walking. basicSegment(johnson, russell, south, 100, s1). basicSegment(russell, nelson, south, 100, s2). basicSegment(nelson, lsm, south-west, 80, s3). basicSegment(lsm, psych, east, 130, s4). basicSegment(nelson, psych, south, 100, s5). basicSegment(psych, arc, east, 20, s6). basicSegment(arc, physics, east, 100, s7). basicSegment(physics, chemistry, north, 80, s8). basicSegment(nelson,chemistry, east, 120, s9). basicSegment(russell,packaging, east, 110, s10). basicSegment(packaging,doolittle, east, 90, s11). basicSegment(chemistry,doolittle, north-east, 70, s12). basicSegment(chemistry,optics, east, 80, s13). basicSegment(physics, serc, east, 50, s14). basicSegment(serc, hill, east, 40, s15). basicSegment(hill, engineering, north, 50, s16). basicSegment(hill, core, east, 30, s17). basicSegment(core, werblin, south, 120, s18). basicSegment(core, winlab, east, 140, s19). basicSegment(winlab, werblin, south-west, 100, s20). basicSegment(engineering, optics, north, 60, s21). basicSegment(optics, sc, east, 40, s22). basicSegment(optics, robeson, north-east, 50, s23). basicSegment(sc, robeson, north-west, 30, s24). basciSegment(doolittle, robeson, east, 90, s25). basicSegment(doolittle, dorms, north-east, 160, s26). basicSegment(robeson, dorms, north, 120, s27). oppDir(south,north). oppDir(east,west). inverse(A,B) :- oppDir(A,B). inverse(A,B) :- oppDir(B,A). inverse(A-B,C-D) :- inverse(A,C), inverse(B,D). segment(S, E, D, L, N) :- basicSegment(S, E, D, L, N). segment(S, E, D, L, N) :- basicSegment(E, S, OD, L, N), inverse(D, OD). %% ************************************************** %% YOU COMPLETE THIS %% ************************************************** %% %% First part, predicates: %% %% reaches(Node,Endpoint) %% true if the path represented by Node ends at %% location Endpoint. %% %% cost(Node,Amount) %% true if the distance traveled in the path represented %% by Node is Amount. %% %% describe_path(Node) %% always true, but as a side-effect prints out the %% directions corresponding to path Node. %% ************************************************** %% YOU COMPLETE THIS %% ************************************************** %% %% Second part, predicate: %% %% neighbor(Node,Neighbor) %% true if node Neighbor can be reached in one step from Node. %% Given: predicate %% %% neighbors(Node,Neighbors) %% %% This uses a Prolog builtin findall %% to go from the neighbor relation you write to %% the neighbors relation that the CI-style search %% function needs. neighbors(Node, Nodes) :- findall(Neighbor, neighbor(Node,Neighbor), Nodes). %% ************************************************** %% YOU COMPLETE THIS %% ************************************************** %% %% Third part, predicates: %% %% select(N,F1,F2) %% add_to_frontier(Neighbors,F1,F2) %% with interpretation as in Computational Intelligence %% (and in class), using heaps to implement %% lowest-cost-first search. %% Given: predicate %% %% find(F, G, P) %% true if node P is path that reaches location G and %% which is accessible from frontier F. find(F, G, P) :- select(P, F, _), reaches(P, G). find(F, G, P) :- select(N, F, F2), neighbors(N, NN), add_to_frontier(NN, F2, F3), find(F3, G, P). %% ************************************************** %% YOU COMPLETE THIS %% ************************************************** %% %% Fourth and final part, predicate: %% %% go(S,E) %% use lowest-cost-first search to compute whether %% there is a path between S and E and which, as %% a side effect of proof, describes this path %% to the user.