Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

pl:prolog:pllib:acyclic_path [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Acyclic path ======
 +{{tag>​graphs operators}}
 +===== Description =====
 +Finding an acyclic path, Path, from A to Z in Graph.
 +
 +
 +**Source**: ​ PROLOG programming for artificial intelligence,​ 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.
 +
 +===== Download =====
 +Program source code: {{prolog:​pllib:​acyclic_path.pl}}
 +
 +===== Listing =====
 +<code prolog>
 +% Figure 9.20  Finding an acyclic path, Path, from A to Z in Graph.
 +
 +
 +
 +
 +
 +% path( A, Z, Graph, Path): Path is an acyclic path from A to Z in Graph
 +
 +
 +
 +:- op( 900, fy, not).
 +
 +
 +
 +path( A, Z, Graph, Path)  :-
 +
 +  path1( A, [Z], Graph, Path).
 +
 +
 +
 +path1( A, [A | Path1], _, [A | Path1] ).
 +
 +
 +
 +path1( A, [Y | Path1], Graph, Path)  :-
 +
 +  adjacent( X, Y, Graph),
 +
 +  not member( X, Path1), ​                       % No-cycle condition
 +
 +  path1( A, [X, Y | Path1], Graph, Path).
 +
 +  ​
 +
 +not Goal  :-
 +
 +  Goal, !, fail
 +
 +  ; 
 +
 +  true.
 +
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/acyclic_path.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0