|
/* ---------------------------- */
getMember(Result, Gender) :-
person(Result, Gender).
getRelation(Result1, Result2, Result3) :-
person(M, _),
giveMeHierarchy(M, Result1, Result2, Result3).
giveMeHierarchy(X, Result1, Result2, Result3) :-
father(person(X, _), person(Y, _)),
Result1 = X,
Result2 = '>_',
Result3 = Y.
giveMeHierarchy(X, Result1, Result2, Result3) :-
mother(person(X, _), person(Y, _)),
Result1 = X,
Result2 = '>_',
Result3 = Y.
giveMeHierarchy(X, Result1, Result2, Result3) :-
husband(person(Y, _), person(X, _)),
Result1 = X,
Result2 = '=_',
Result3 = Y.
giveMeHierarchy(X, Result1, Result2, Result3) :-
husband(person(X, _), person(Y, _)),
Result1 = X,
Result2 = '=_',
Result3 = Y.
giveMeHierarchy(X, Result1, Result2, Result3) :-
father(person(Y, _), person(X, _)),
Result1 = X,
Result2 = '<_',
Result3 = Y.
giveMeHierarchy(X, Result1, Result2, Result3) :-
mother(person(Y, _), person(X, _)),
Result1 = X,
Result2 = '<_',
Result3 = Y.
/* ------------------------------ */
edge(X, Y) :- father(person(X, _), person(Y, _)).
edge(X, Y) :- mother(person(X, _), person(Y, _)).
edge(X, Y) :- husband(person(X, _), person(Y, _)).
edge(X, Y) :- father(person(Y, _), person(X, _)).
edge(X, Y) :- mother(person(Y, _), person(X, _)).
edge(X, Y) :- husband(person(Y, _), person(X, _)).
track(X, X, [X], _).
track(X, Y, [X, Y], _) :- edge(X, Y).
track(X, Y, [X|Path], V) :- edge(X, Z), not(member(Z, V)), track(Z, Y, Path, [X|V]).
bestTrack(X, Y, L, V) :-
findall(A, track(X, Y, A, V), L1),
scorriLista(L1, L, _).
scorriLista([M], L, C) :-
L = M,
length(M, C).
scorriLista([M1|T], L, C) :-
length(M1, C1),
scorriLista(T, M2, C2),
newShortest(M1, C1, M2, C2, L, C).
newShortest(_, N1, M, N, L, C) :-
N1>N,
L = M,
C = N.
newShortest(L1, N1, _, N, L, C) :-
N >= N1,
L = L1,
C = N1.
/* ------------------------------ */
edge2(X, Y, L) :- father(person(X, _), person(Y, _)), L = [['father(person('], X, [', -), person('], Y, [', -))']].
edge2(X, Y, L) :- mother(person(X, _), person(Y, _)), L = [['mother(person('], X, [', -), person('], Y, [', -))']].
edge2(X, Y, L) :- husband(person(X, _), person(Y, _)), L = [['husband(person('], X, [', -), person('], Y, [', -))']].
edge2(X, Y, L) :- father(person(Y, _), person(X, _)), L = [['father(person('], Y, [', -), person('], X, [', -))']].
edge2(X, Y, L) :- mother(person(Y, _), person(X, _)), L = [['mother(person('], Y, [', -), person('], X, [', -))']].
edge2(X, Y, L) :- husband(person(Y, _), person(X, _)), L = [['husband(person('], Y, [', -), person('], X, [', -))']].
makeRelation([X, Y], L1) :- edge2(X, Y, L1).
makeRelation([X, Y|T], L1) :- edge2(X, Y, L2), makeRelation([Y|T], L3), append(L2, L3, L1).
/* ------------------------------ */
relation('father', 'X, Y', 'funzione base').
relation('mother', 'X, Y', 'funzione base').
relation('husband', 'X, Y', 'funzione base').
sendMeAllRelation(A, B, C) :- relation(A, B, C).
/* ------------------------------ */
diseguali([_]).
diseguali([H|T]) :- not(member(H, T)), diseguali(T).
|
|