Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %4 uzduotis
- %Apibrėžkite predikatą kurio vienas ar daugiau argumentų - įėjimo argumentai, nusakantys pradinius užduoties duomenis ir vienas argumentas atitinka sprendinį.
- %Sprendinys - Prologo struktūra (sąrašas ar pan.) - turi būti apibrėžtas konstruktyviai. Didžiausias dėmesys turi būti skiriamas ne sprendimo efektyvumui,
- %o deskriptyviajam (Prologo prasme) apibrėžimui.
- %Jokiu būdu nereikia ieškoti deterministinių uždavinio sprendimo algoritmų, nors tokie ir būtų.
- %Taip pat apibrėžkite predikatą, kuris išveda sprendinį į ekraną skaitomu pavidalu (pvz., pseudo-grafiku)
- %Grafo brėžimas.
- %8. Duotas plokštuminis grafas. Raskite kelią, einantį per visas grafo briaunas, kai:
- %1. per tą pačią briauną antrą kartą eiti draudžiama;
- /*edge(a,c).
- edge(a,d).
- edge(b,d).
- edge(b,e).
- edge(c,e).
- edge(a,b).
- edge(a,c).
- edge(a,d).
- edge(b,c).
- edge(b,d).*/
- edge(a,b).
- edge(b,c).
- edge(c,d).
- edge(d,a).
- edge(a,c).
- edge(b,d).
- /*edge(a,c).
- edge(a,d).
- edge(b,c).
- edge(d,c).*/
- addedge(A,B):-
- assert(edge(A,B)).
- connected(A,B) :-
- edge(A,B);
- edge(B,A).
- used([A, B], Path) :-
- member([A, B], Path);
- member([B, A], Path).
- allused([], _) :- true.
- allused([Edge | Edges], Path) :- % have all the edges been visited?
- used(Edge, Path),
- allused(Edges, Path).
- follows([[_, A]|_], [A, B]) :- % follows the rule of [ A-B, B-C, C-... ]
- connected(A, B).
- eulerpath(X) :-
- eulerpath(_,X).
- eulerpath([], Result) :-
- connected(A, B),
- eulerpath([[A, B]], Result). % filling our result as a list of lists ( 2 connected nodes )
- eulerpath(Path, Result) :-
- follows(Path, Edge),
- not(used(Edge, Path)),
- eulerpath([Edge | Path], Result).
- eulerpath(Path, Result) :-
- is_list(Path), % the path cannot be empty, it has to have a list of edges
- findall([A, B], edge(A, B), Edges), % finds all connected edges from our database
- allused(Edges, Path), % check whether we've already went through all of our edges
- reverse(Path, Result),
- !.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement