编写Prolog规则以查找两个站点之间的任何路由。
route(Station1, Station2, Route)
其中Station1
和Station2
是电台名称,Route
是按顺序连接Station1和Station2的电台列表,包括Station1和Station2。
写一个Prolog规则,找出在两个站点之间的路线上行驶的时间,假设相邻站点之间的行程时间是4分钟。忽略与换乘线路相关的任何时间。
route_time(Station1, Station2, Route, Minutes)
其中Station1和Station2是站名,Route是按顺序连接Station1和Station2的站列表,包括Station1和Station2,Minutes是时间。
station(al,[metropolitan]).
station(ls,[metropolitan,central]).
station(kx,[metropolitan,victoria]).
station(bs,[metropolitan]).
station(fr,[metropolitan]).
station(ke,[northern]).
station(em,[northern,bakerloo]).
station(tc,[northern,central]).
station(ws,[northern,victoria]).
station(eu,[northern]).
station(wa,[bakerloo]).
station(pa,[bakerloo]).
station(oc,[bakerloo,central,victoria]).
station(ec,[bakerloo]).
station(nh,[central]).
station(lg,[central]).
station(cl,[central]).
station(bg,[central]).
station(br,[victoria]).
station(vi,[victoria]).
station(fp,[victoria]).
/* Facts about the direct connection between two stations.
The adjacent rule shows the connections between two stations */
adjacent1(X,Y):- adjacent(X,Y);adjacent(Y,X).
/* The first rule is X is adjacent Y IF and only IF
X is adjacent to Y and Y is adjacent to X */
/* Bakerloo Line adjacents*/
adjacent(em,ec).
adjacent(em,ke).
adjacent(em,tc).
adjacent(em,oc).
adjacent(oc,vi).
adjacent(oc,ws).
adjacent(oc,pa).
adjacent(oc,lg).
adjacent(oc,tc).
adjacent(pa,wa).
/* Central Line Adjacents*/
adjacent(bg,ls).
adjacent(ls,al).
adjacent(ls,kx).
adjacent(ls,cl).
adjacent(cl,tc).
adjacent(lg,nh).
/*Metro adjacents*/
adjacent(kx,fp).
adjacent(kx,ws).
adjacent(kx,bs).
adjacent(bs,fr).
/* Northern Line*/
adjacent(tc,ws).
adjacent(ws,eu).
/*Victoria line */
adjacent(br,vi).