, . , G = (v, 7, I - V . G = (V, '), £ ' - , , :
1. ;
2. .
9.
, . , . 9.11, , , :
Treel - [a-b, b-c, c-d] 2 = [a-b, b-d, d-c] = [a-b, b-d, b-c]
X-Y X Y. . , , , .
: stree [ G, )
G. , G . : G , , , , , , . . : , , . , , 9.10. : spread: Treel, Tree, G]
9.10. : "" ; ,
% '
" ix . * , Graph = [-, -, b-d, c-d]
I stree{ Graph, Tree): Tree - Graph
street Graph, Tree;:-member! Edge, Graph), spread! [Edge], Tree, Graph).
% spread!" Treel, Tree, Graph): Treel ""
% Tree Graph
spread' Treel, Tree, Graph):-addedge(Treel, Tree2, Graph), spread! Tree2, Tree, Graph).
spread! Tree, Tree, Graph):-
not addedge! Tree, _, Graph). - , %addedge(Tree, HewTree, Graph):
Graph Tree,
addedge(Tree, [A-B | Tree], Graph):-
adjacent! A, , Graph),: "> Graph
node! A, Tree), % Tree
not node! , Tree). % - Tree
adjacent Node!, Node2, Graph):-member £ Hodel-Node2, Graph)
|
|
member{ Hode2-Model, Graph).
212 I. Prolog
node! Mode, Graph]:- % Node - Graph,
... adjacent f Mode,, Graph]. % Graph
. G , Treel Tree - G, , . Tree G, G Treel ( ). , " Treel Tree" ( spread).
, , , . , , , 9.IQ. .
1. -, :
G,
,
"" G, .. G .
2. ,
:
,
.
path (. ) Prolog, 9.11. , - .
9.11, : "" ; node adjacent 9,10
%
I
¥ street Graph, Tree): Tree - Graph
stree (Graph, Tree):-subset! Graph, Tree), tree(Tree), coverst Tree, Graph).
tree(Tree):-
connected; Tree),
not hasacycle! Tree). % connected(Graph): Graph
connected) Graph):-
not { node! A, Graph), node (3, Graph), not path! ft, B, Graph, _)).
hasacycle! Graph):-
adjacent; Model, Node2p Graph),
path! Model, Node2, Graph, [Model, X, Y | _] ). % 1
% covets! Tree, Graph): Graph Tree
covers) Tree, Graph):-
not (node! Bode, Graph), not node (Node, Tree)).
9.
% subsetf Listl, List2); List2 <50 Llstl
subset ([], []).
subset! [X I Set], Subset):- % X subset) Set, Subset).
subset([X I Set], [X I Subset)):- >6 subset f Set, Subset).