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 ],
- table(Lconvives).
- table(Lconvives) :-
- length([anne,martin|Lconvives],Nb),
- produire_lassoc([anne,martin|Lconvives],Lv,Nb,Lassoc),
- alternance_cercles(Lassoc,Nb),
- meme_hobby(Lassoc,Nb),
- en_couple_pas_cote_a_cote(Lassoc,Nb),
- pas_incompatibilite(Lassoc,Nb),
- places_differentes(Lv),
- label_places(Lv),
- sort(2,@<,Lassoc,Lassoc_trie),
- impression_table(Lassoc_trie).
- % ---------------------------------------------------------------------- %
- % %
- % LISTE ASSOCIATIVE %
- % %
- % ---------------------------------------------------------------------- %
- produire_lassoc([] , [] , _ , [] ).
- produire_lassoc([anne |T],[Var|Lv],Nb,[pers_var(anne ,Var)|Sol]) :-
- Var #= 1 ,
- produire_lassoc(T,Lv,Nb,Sol),!.
- produire_lassoc([martin|T],[Var|Lv],Nb,[pers_var(martin,Var)|Sol]) :-
- Check is Nb mod 4 ,
- Check == 0 ,
- Q is div(Nb,2),
- Var #= Q ,
- produire_lassoc(T,Lv,Nb,Sol),!.
- produire_lassoc([martin|T],[Var|Lv],Nb,[pers_var(martin,Var)|Sol]) :-
- Q is div(Nb,2),
- Var #= Q+1,
- produire_lassoc(T,Lv,Nb,Sol),!.
- produire_lassoc([H |T],[Var|Lv],Nb,[pers_var(H,Var) |Sol]) :-
- Var in 2..Nb ,
- produire_lassoc(T,Lv,Nb,Sol).
- % ---------------------------------------------------------------------- %
- % %
- % CONTRAINTES %
- % %
- % ---------------------------------------------------------------------- %
- addconstraint(Nb,pers_var(_,Var1)-pers_var(_,Var2)):-
- Var1 #\= (Var2 mod Nb) + 1 ,
- Var2 #\= (Var1 mod Nb) + 1.
- %var can't be Odd
- notOddConstraint(_,0).
- notOddConstraint(Var,NB):- Var #\= NB-1,NB2 is NB - 2 , notOddConstraint(Var,NB2).
- notEvenConstraint(_,0).
- notEvenConstraint(Var,NB):- Var #\= NB, NB2 is NB - 2 , notEvenConstraint(Var,NB2).
- % Alternance cercles
- % ------------------
- alternance_cercles([],_).
- alternance_cercles([pers_var(Nom,Var)|T],Nb):- cercle(Nom,info ) , notOddConstraint(Var,Nb) ,alternance_cercles(T,Nb).
- alternance_cercles([pers_var(Nom,Var)|T],Nb):- cercle(Nom,philo) , notEvenConstraint(Var,Nb),alternance_cercles(T,Nb).
- % Meme hobby
- % ----------
- meme_hobby( Lassoc,Nb) :- bagof(pers_var(P1,Var1)-pers_var(P2,Var2) ,
- C1^C2^(member(pers_var(P1,Var1),Lassoc),
- member(pers_var(P2,Var2),Lassoc), P1\=P2,
- hobby(P1,C1) , hobby(P2,C2) ,
- intersection(C1,C2,[])
- ),L),
- maplist(addconstraint(Nb),L).
- % En couple pas cote a cote
- % -------------------------
- en_couple_pas_cote_a_cote( Lassoc,Nb ) :- bagof(pers_var(P1,Var1)-pers_var(P2,Var2) ,
- (member(pers_var(P1,Var1),Lassoc),
- member(pers_var(P2,Var2),Lassoc), P1\=P2,
- en_couple(P1,P2)
- ),L),
- maplist(addconstraint(Nb),L).
- % Pas d incompatibilite
- % ---------------------
- pas_incompatibilite( Lassoc,Nb) :- bagof(pers_var(P1,Var1)-pers_var(P2,Var2) ,
- (member(pers_var(P1,Var1),Lassoc),
- member(pers_var(P2,Var2),Lassoc), P1\=P2,
- incompatible(P1,P2)
- ),L),
- maplist(addconstraint(Nb),L).
- % Personnes a des places differentes
- % ----------------------------------
- places_differentes( Vs ):- all_distinct(Vs).
- % ---------------------------------------------------------------------- %
- % %
- % LABELING %
- % %
- % ---------------------------------------------------------------------- %
- label_places(Lv ) :- label(Lv).
- % ---------------------------------------------------------------------- %
- % %
- % IMPRESSION %
- % %
- % ---------------------------------------------------------------------- %
- impression_table([]) :- !, nl.
- impression_table([pers_var(P,V)|T]) :-
- nl, format('~w ~d ~w ~a',['Place ',V, ' :', P]),
- impression_table(T).
- % ---------------------------------------------------------------------- %
- % %
- % BASE DE DONNEES %
- % %
- % ---------------------------------------------------------------------- %
- en_couple(anne,martin).
- en_couple(manon,jules).
- en_couple(juliette,tom).
- en_couple(charlotte,paul).
- cercle(anne,philo).
- cercle(manon,philo).
- cercle(alice,philo).
- cercle(juliette,philo).
- cercle(lucie,philo).
- cercle(charlotte,philo).
- cercle(olivia,philo).
- cercle(margaux,philo).
- cercle(martin,info).
- cercle(jules,info).
- cercle(hugo,info).
- cercle(tom,info).
- cercle(louis,info).
- cercle(paul,info).
- cercle(jean,info).
- cercle(antoine,info).
- 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]).
- incompatible(manon,louis).
- incompatible(charlotte,antoine).
- incompatible(margaux,hugo).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement