.


:




:

































 

 

 

 





, G - , Z - G. : path (A, Z, G, }

- Z G. . - - , . 9.11, , :

path(a, d, G, [a,b,d] } path (a, d, G, [a,b,c,d])

, . .

Z G, :

1. = Z, = [];

2. PI Y Z, Y, , 1.

, , ( ?1). : pathl (A, Pathl, G, Path)

. 9.12, .

.

G - .

Pathl - G.

Path - G, Pathl Pathl .

path pathl :

path( A, Z, G, Path):- pathl! ft, [Z], G, Path),


9,



Pith I



 


Path

. 9.12. pa thl, Path - , Z; Path Pathl

, . 9.12, , pathl . , Pathl ( Y . 9.12) Path ( ). , X, , :

1. Y X;

2. X Pathl;

3. fat.-, pathl (, [X | Pathl], G, Path).

9.8. member . adjacent* X Y, G)

, G X Y. . G ( ) : G = graph (Nodes, Edges) :

adjacent [ , Y, gracb(Nodes, Edges)):-member! (), Edges)

member (e(Y,X), Edges). 9.8. P a t h Z Graph

" path ("A,"".... Graph, Path^

path(, , Graph, Path):-pathl [ A, [Z], Graph, Path].

pathl! A, [A | Pathl], _, [A | Pathl]).

pathl (A, [Y | Pathl], Graph, Path):-adjacent (X, Y, Graph),

not member {X, Pathl)r % ,

pathl A, [X, Y ] Pathl], Graph, Path).

; , . path, ;

bamiitor.ian_ Graph, Path):-path!,, Graph, path), covers_ Path, Graph).

covers; Path, Graph):-

not { node! , Graph), not member! , Path)). node (N, Graph) , N - Graph.



I. Prolog


. . , , , , , 1, path pat hi , , , , :

path A, Z, , , ) pathl[ ft, PI, C1, G, p, c)

1 1. adjacent . 9.9 , .

9.9. ; P a t h - Cost z Graph

,path('""^2Grap',""Path,'Cost")':""'

% Path - Cost Z Graph

path( A, Z, Graph, Path, Cost):-pathl (A, [Z], 0, Graph, Path, Cost).

pathlf A, [A! Pathl], Costl, Graph, [A | Pathl], Costl).

pathl r A, v Pathl], Costl, Graph, Path, Cost}:-adjacent< X, Y, CostXY, Graph), not member! X, Pathl), Cost2 is Costl + CostXY, pathl< A, [X, Y | Pathl], Costs, Graph, Path, cost).

. (nodel node2) Graph : path! nodel, node2. Graph, MinPath, MinCest), not (path{ nodel, node2, Graph,, Cost), Cost < Mincost)

, Graph : path! _, _, Graph, MaxPath, MaxCoatb not (path; _, _, Graph, _, Cost!, Cost > MaxCost)

, . , , . . 11 12.





:


: 2015-10-01; !; : 468 |


:

:

, ,
==> ...

1516 - | 1438 -


© 2015-2024 lektsii.org - -

: 0.009 .