0
가능한 모든 경로는 가능한 모든 경로프롤로그 목록은 밖으로 내가하고 싶은 재귀
country(england,france).
country(france,bulgaria).
country(bulgaria,germany).
country(england,bulgaria).
country(germany,italy).
edit: additional to
country(germany,italy).
country(england,italy).
country(england,greece).
country(greece,france).
connectto(X, Y) :-
country(X, Y).
? -op (150, XFY에)을 밖으로 나열합니다.
X와 Y : -get_waypoints (X, Y, Waypoints), write (Waypoints), 실패.
get_waypoints(Start, End, [Waypoint|Result]) :-
country(Start, End),
!;country(Start, Waypoint),
get_waypoints(Waypoint, End, Result).
그렇지 않으면 원래의 코드에서 시스템은 당신이 언급 코드에서
| ?- england to italy.
[]no
을 줄 것이다. 가능한 모든 경로를 보여주고 있지만
이제 문제는
| ?- england to italy.
[_31242|_31243][france,bulgaria,germany,_31332|_31333]
[bulgaria,germany,_31422|_31423]
[greece,france,bulgaria,germany,_31602|_31603]no
로 제공됩니다.
모든 해결책을 얻을 수 있습니다.
country(bulgaria,germany).
country(england,bulgaria).
country(england,france).
country(england,greece).
country(england,italy).
country(france,bulgaria).
country(greece,france).
country(germany,italy).
:- op(150, xfy, to).
X to Y :-
findall(Waypoint, get_waypoints(X,Y,Waypoint), Waypoints),
write(Waypoints).
get_waypoints(Start, End, []) :-
country(Start, End).
get_waypoints(Start, End, [Waypoint|Result]) :-
country(Start, Waypoint),
get_waypoints(Waypoint, End, Result).
사용은 다음과 같습니다 : 여기
?- england to italy.
, 내가 업데이트 여러분의 기대에 맞게 내 코드는 설명이 필요하면
네,하지만이 말은 오직 1 가지 해결책입니다. 나는 여러 가지 다른 데이터가 필요합니다. 내가 실패한 것을 시도했지만 돌아 오지 만 그것은 –
일만의 해결책을 제공하지 않는다. 두 번째 맨 위에 첫 번째 절을 추가하는 것을 잊어 버렸다. 내 코드를 복사하여 테스트 할 때 하나의 솔루션 만 반환한다는 것을 확인합니까? 그리고 프롤로그의 어떤 구현을 사용하고 있습니까? – m09
메신저를 사용하여 lpa win prolog. 실제로는 단 하나의 솔루션 만 제공했습니다. 또한 여러 경로를 제공하지만 실패 할 경우에는 올바른 경로를 사용하지 마십시오. 미안 나는 그것이 (adam, jim)이어야하고, 매트와 솔직함을 나열해야한다는 것을 잊었다. –