Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- use_module(library(clpfd)).
- % ---------------------------------------------------------------------- %
- % %
- % PREDICAT PRINCIPAL %
- % %
- % ---------------------------------------------------------------------- %
- go :- Lconvives = [manon,alice,juliette,lucie,charlotte,olivia,margaux,jules,hugo,tom,louis,paul,jean,antoine],
- length([anne,martin|Lconvives],Nb),
- placer_table(Lconvives,Nb).
- placer_table(Lconvives,Nb) :-
- length([anne,martin|Lconvives],Nb), % Renvoie dans Nb la taille de la liste
- produire_lassoc([anne,martin|Lconvives],Nb,Lassoc), %lst, nb et tape tout dans Lassoc
- alternance_cercles(Lassoc,Nb),
- meme_hobby(Lassoc,Nb),
- en_couple_pas_cote_a_cote(Lassoc,Nb),
- pas_incompatibilite(Lassoc,Nb),
- places_differentes(Lassoc),
- label_places(Lassoc),
- sort(2,@<,Lassoc,Lassoc_trie),
- impression_table(Lassoc_trie).
- % ---------------------------------------------------------------------- %
- % %
- % LISTE ASSOCIATIVE %
- % %
- % ---------------------------------------------------------------------- %
- % produire_lassoc(L, Nb, Lassoc) : Renvoie la liste L reçu en entrée
- % ajouté du numéro Nb. La liste de sortie Lassoc.
- produire_lassoc(LPers, Nb, Lassoc) :-
- numlist(1,Nb,LNb), %LNb = Nbr de 1 à 14 (sans les chefs!)
- zip(LPers,LNb,Lassoc). % On zip les ppl avec leur num
- zip([], [], []).
- zip([X|Xs], [Y|Ys], [(X,Y)|Zs]) :- zip(Xs,Ys,Zs).
- getPers([], _, _).
- getPers(L, Nom, Place) :- member((Nom, Place), L).
- % ---------------------------------------------------------------------- %
- % %
- % CONTRAINTES %
- % %
- % ---------------------------------------------------------------------- %
- %alternance_cercle(Lassoc, Nb) : Reçoit Lassoc en entrée, qui représente la liste
- %des étudiants avec leur numéro et va analyser chaque élève afin de choisir un
- %placement de type PHILO-INFO-PHILO ou INFO-PHILO-INFO, mais pas INFO-INFO...
- % Deux membres d'un même cercle ne doivent pas être assis l'un à coté de l'autre !
- alternance_cercles(Lassoc, Nb) :-
- getPers(Lassoc, N1, V1), %N = Nom de l'étudiant, V = Numéro de la place
- getPers(Lassoc, N2, V2),
- N1 \= N2, % Si les noms sont les mêmes, problème, on backtrack !
- V1 \= V2, % Si les numéros sont les mêmes, problème, on backtrack !
- cercle(N1, C1),
- cercle(N2, C2),
- (C1 = C2 -> mod(V2, Nb) #\= mod(V1, Nb) + 1; true),
- (C1 = C2 -> mod(V2, Nb) #\= mod(V1, Nb) - 1; true).
- % meme_hobby([L], Nb) : Recherche les personnes ayant un hobby commun
- % et renvoie true si c'est le cas !
- meme_hobby(Lassoc, Nb) :-
- getPers(Lassoc, N1, V1),
- getPers(Lassoc, N2, V2),
- N1 \= N2,
- V1 \= V2,
- hobby(N1, Lhobby1),
- hobby(N2, Lhobby2),
- member(Hobby, Lhobby1),
- member(Hobby2, Lhobby2),
- (Hobby \= Hobby2 -> mod(V2, Nb) #\= mod(V1, Nb) - 1 ; true), %Si les hobbys sont communs, alors, cela est bon !
- (Hobby \= Hobby2 -> mod(V2, Nb) #\= mod(V1, Nb) + 1 ; true).
- %en_couple_pas_cote_a_cote/2 : Recherche les personnes en couple et permet
- %de les séparer
- en_couple_pas_cote_a_cote(Lassoc, Nb) :-
- getPers(Lassoc, N1, V1),
- getPers(Lassoc, N2, V2),
- en_couple(N1, N2),
- mod(V1, Nb) #\= mod(V2, Nb) - 1,
- mod(V1, Nb) #\= mod(V1, Nb) + 1.
- % pas_incompatibilite/2 : Recherche les personnes ayant des incompatibilités !
- % (s'ils ne s'aiment pas par exemple...)
- pas_incompatibilite(Lassoc, Nb) :-
- getPers(Lassoc, N1, V1),
- getPers(Lassoc, N2, V2),
- incompatible(N1, N2),
- mod(V1, Nb) #\= mod(V2, Nb) - 1,
- mod(V1, Nb) #\= mod(V2, Nb) + 1.
- % places_differentes/1
- places_differentes(Lassoc) :-
- findall((N1, N2), (getPers(Lassoc, N1, _), getPers(Lassoc, N2, _), N1 \= N2), R),
- getPers(R, N3, V3),
- getPers(R, N4, V4),
- N3 #\= N4,
- V3 #\= V4.
- %label_places
- label_places(Lassoc) :- labeling([ff], Lassoc).
- % impression_table :
- impression_table([]) :- !, nl.
- impression_table([(P,V)|T]) :-
- nl, format('~w ~d ~w ~a',['Place ',V, ' :', P]),
- impression_table(T).
- % ---------------------------------------------------------------------- %
- % %
- % BASE DE DONNEES %
- % %
- % ---------------------------------------------------------------------- %
- incompatible(manon,louis).
- incompatible(charlotte,antoine).
- incompatible(margaux,hugo).
- en_couple(anne,martin).
- en_couple(manon,jules).
- en_couple(juliette,tom).
- en_couple(charlotte,paul).
- cercle(martin,info).
- cercle(jules,info).
- cercle(hugo,info).
- cercle(tom,info).
- cercle(louis,info).
- cercle(paul,info).
- cercle(jean,info).
- cercle(antoine,info).
- cercle(anne,philo).
- cercle(manon,philo).
- cercle(alice,philo).
- cercle(juliette,philo).
- cercle(lucie,philo).
- cercle(charlotte,philo).
- cercle(olivia,philo).
- cercle(margaux,philo).
- hobby(anne,[sport,lecture,voyages]).
- hobby(manon,[lecture,voyages]).
- hobby(alice,[lecture,voyages]).
- hobby(juliette,[sport,voyages]).
- hobby(lucie,[lecture]).
- hobby(charlotte,[lecture]).
- hobby(olivia,[sport,lecture]).
- hobby(margaux,[sport]).
- hobby(martin,[sport,lecture,voyages]).
- hobby(jules,[sport,lecture]).
- hobby(hugo,[sport,lecture]).
- hobby(tom,[sport,voyages]).
- hobby(louis,[sport,lecture]).
- hobby(paul,[sport]).
- hobby(jean,[sport,lecture]).
- hobby(antoine,[sport,lecture]).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement