⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig9_23.pl

📁 超多的prolog源代码 具体内容见压缩包里面的programs.txt
💻 PL
字号:
% Figure 9.23   Finding a spanning tree of a graph: a `declarative' 
% program. Relations node and adjacent are as in Figure 9.22.


% Finding a spanning tree
% Graphs and trees are represented as lists of edges.

% stree( Graph, Tree): Tree is a spanning tree of Graph

stree( Graph, Tree)  :-
  subset( Graph, Tree),
  tree( Tree),
  covers( Tree, Graph).

tree( Tree)  :-
  connected( Tree),
  not hasacycle( Tree).

% connected( Graph): there is a path between any two nodes in Graph

connected( Graph)  :-
  not ( node( A, Graph), node( B, Graph), not path( A, B, Graph, _) ).

hasacycle( Graph)  :-
   adjacent( Node1, Node2, Graph),
   path( Node1, Node2, Graph, [Node1, X, Y | _] ). % Path of length > 1 

% covers( Tree, Graph): every node of Graph is in Tree

covers( Tree, Graph)  :-
  not ( node( Node, Graph), not node( Node, Tree) ).

% subset( List1, List2): List2 represents a subset of List1

subset( [], [] ). 

subset( [X | Set], Subset)  :-            % X not in subset
  subset( Set, Subset).

subset( [X | Set], [X | Subset])  :-      % X included in subset
  subset( Set, Subset).


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -