私が Prolog で書いているプログラムの一部は、開始位置から終了位置までのすべての可能なパス オプションを見つけることに関係しています。
これが私がこれまでに持っているものです:
findAllRoutes(Start, End, Path) :-
findAllRoutes(Start, _, End, Path),
print('Successful route: '), print(Route).
findAllRoutes(End, _, End, [End]). %route was successfully finished
findAllRoutes(Start, Temp, End, [Start|Rest_of_List]) :-
path(Start, Temp),
findAllRoutes(Temp, _, End, Rest).
読み込むデータは次のとおりです。
%path(Start, End).
path(1, 4). %find all the possible paths from location 1 to location 4.
%paths_in_place[[Start, End, Distance]].
paths_in_place[[1, 2, 250], [2, 4, 250], [1, 3, 400], [3, 4, 300]].
私の質問は、これはpaths_in_place
開始場所から終了場所までの途中で到達したポイントの順序を保存しながら、循環する正確な方法ですか?
また、フィールドについて言及せずに が呼び出されDistance
た場合はどうなりますか? フィールドにあるにもかかわらず、Prologでパラメーターを渡すことは合法ですか?findAllRoutes
Distance
Start, End, Route
paths_in_place
Start, End, Distance
どんな助けでも大歓迎です。何か明確にする必要がある場合はお知らせください。