Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Logic Familiar Hierarchy - base.pl

base.pl

Caricato da: Nophiq
Scarica il programma completo

  1. /* ---------------------------- */
  2.  
  3. getMember(Result, Gender) :-
  4.         person(Result, Gender).
  5. getRelation(Result1, Result2, Result3) :-
  6.         person(M, _),
  7.         giveMeHierarchy(M, Result1, Result2, Result3).
  8.  
  9. giveMeHierarchy(X, Result1, Result2, Result3) :-
  10.         father(person(X, _), person(Y, _)),
  11.         Result1 = X,
  12.         Result2 = '>_',
  13.         Result3 = Y.
  14. giveMeHierarchy(X, Result1, Result2, Result3) :-
  15.         mother(person(X, _), person(Y, _)),
  16.         Result1 = X,
  17.         Result2 = '>_',
  18.         Result3 = Y.
  19. giveMeHierarchy(X, Result1, Result2, Result3) :-
  20.         husband(person(Y, _), person(X, _)),
  21.         Result1 = X,
  22.         Result2 = '=_',
  23.         Result3 = Y.
  24. giveMeHierarchy(X, Result1, Result2, Result3) :-
  25.         husband(person(X, _), person(Y, _)),
  26.         Result1 = X,
  27.         Result2 = '=_',
  28.         Result3 = Y.
  29. giveMeHierarchy(X, Result1, Result2, Result3) :-
  30.         father(person(Y, _), person(X, _)),
  31.         Result1 = X,
  32.         Result2 = '<_',
  33.         Result3 = Y.
  34. giveMeHierarchy(X, Result1, Result2, Result3) :-
  35.         mother(person(Y, _), person(X, _)),
  36.         Result1 = X,
  37.         Result2 = '<_',
  38.         Result3 = Y.
  39.        
  40. /* ------------------------------ */
  41.  
  42. edge(X, Y) :- father(person(X, _), person(Y, _)).
  43. edge(X, Y) :- mother(person(X, _), person(Y, _)).
  44. edge(X, Y) :- husband(person(X, _), person(Y, _)).
  45. edge(X, Y) :- father(person(Y, _), person(X, _)).
  46. edge(X, Y) :- mother(person(Y, _), person(X, _)).
  47. edge(X, Y) :- husband(person(Y, _), person(X, _)).
  48.  
  49. track(X, X, [X], _).
  50. track(X, Y, [X, Y], _) :- edge(X, Y).
  51. track(X, Y, [X|Path], V) :- edge(X, Z), not(member(Z, V)), track(Z, Y, Path, [X|V]).
  52.  
  53. bestTrack(X, Y, L, V) :-
  54.         findall(A, track(X, Y, A, V), L1),
  55.         scorriLista(L1, L, _).
  56.  
  57. scorriLista([M], L, C) :-
  58.         L = M,
  59.         length(M, C).
  60.        
  61. scorriLista([M1|T], L, C) :-
  62.         length(M1, C1),
  63.         scorriLista(T, M2, C2),
  64.         newShortest(M1, C1, M2, C2, L, C).
  65. newShortest(_, N1, M, N, L, C) :-
  66.         N1>N,
  67.         L = M,
  68.         C = N.
  69. newShortest(L1, N1, _, N, L, C) :-
  70.         N >= N1,
  71.         L = L1,
  72.         C = N1.
  73.        
  74. /* ------------------------------ */
  75.  
  76. edge2(X, Y, L) :- father(person(X, _), person(Y, _)), L = [['father(person('], X, [', -), person('], Y, [', -))']].
  77. edge2(X, Y, L) :- mother(person(X, _), person(Y, _)), L = [['mother(person('], X, [', -), person('], Y, [', -))']].
  78. edge2(X, Y, L) :- husband(person(X, _), person(Y, _)), L = [['husband(person('], X, [', -), person('], Y, [', -))']].
  79. edge2(X, Y, L) :- father(person(Y, _), person(X, _)), L = [['father(person('], Y, [', -), person('], X, [', -))']].
  80. edge2(X, Y, L) :- mother(person(Y, _), person(X, _)), L = [['mother(person('], Y, [', -), person('], X, [', -))']].
  81. edge2(X, Y, L) :- husband(person(Y, _), person(X, _)), L = [['husband(person('], Y, [', -), person('], X, [', -))']].
  82.  
  83. makeRelation([X, Y], L1) :- edge2(X, Y, L1).
  84. makeRelation([X, Y|T], L1) :- edge2(X, Y, L2), makeRelation([Y|T], L3), append(L2, L3, L1).
  85.  
  86. /* ------------------------------ */
  87.  
  88. relation('father', 'X, Y', 'funzione base').
  89. relation('mother', 'X, Y', 'funzione base').
  90. relation('husband', 'X, Y', 'funzione base').
  91. sendMeAllRelation(A, B, C) :- relation(A, B, C).
  92.  
  93. /* ------------------------------ */
  94.        
  95. diseguali([_]).
  96. diseguali([H|T]) :- not(member(H, T)), diseguali(T).