---
# System prepended metadata

title: CLP - TP 7

---

# CLP - TP 7
```prolog
:-lib(ic).
:-lib(ic_symbolic).
:-local domain(genre(femme, homme)).

% Tests effectués:
% solve(P1, P2, Enfant).
% Réponse : 
%     P1 = homme
%     P2 = femme
%     E = homme
%     Yes (0.00s cpu)


solve(Parent1, Parent2, Enfant):-
    poser_variables(Parent1, Parent2, Enfant),
    poser_affirmations(AffE, AffESelonP1, AffP1,Aff1P2, Aff2P2),
    contraindre(AffE, AffESelonP1, AffP1, Aff1P2, Aff2P2, Parent1, Parent2, Enfant),
    getVarList(Parent1, Parent2, Enfant, AffE, AffESelonP1, AffP1,Aff1P2, Aff2P2, Lsymb, Lnum),
    labeling_symbolic(Lsymb),
    labeling(Lnum).

getVarList(Parent1, Parent2, Enfant, AffE, AffESelonP1, AffP1,Aff1P2, Aff2P2, Lsymb, Lnum):-
    
    Lsymb = [Parent1, Parent2, Enfant],
    Lnum = [AffE, AffESelonP1, AffP1, Aff1P2, Aff2P2].

poser_variables(Parent1, Parent2, Enfant):-
    Parent1 &:: genre,
    Parent2 &:: genre,
    Enfant &:: genre.
    
poser_affirmations(AffE, AffESelonP1, AffP1,Aff1P2, Aff2P2):-
    AffE #:: 0..1,
    AffESelonP1 #:: 0..1,
    AffP1 #:: 0..1,
    Aff1P2 #:: 0..1,
    Aff2P2 #:: 0..1.
    
contraindre(AffE, AffESelonP1, AffP1, Aff1P2, Aff2P2, Parent1, Parent2, Enfant):-
    Parent1 &\= Parent2,
    (Enfant &= femme) #= (AffESelonP1 #= 1),
    (AffP1 #= 1) #= (AffESelonP1 #= AffE),
    (Aff1P2 #= 1) #= (Enfant &= homme),
    (Aff2P2 #= 1) #= (AffE #= 0),
    affirme(Parent1, AffESelonP1),
    affirme(Parent2,Aff1P2,Aff2P2),
    affirme(Parent2, Aff1P2),
    affirme(Parent2, Aff2P2),
    affirme(Enfant, AffE).
    
affirme(S, A):-
    (S&=femme) => (A#=1).
    
affirme(S, A1, A2):-
    (S&=homme) => ((A1 + A2) #=1).
    
    
labeling_symbolic([]).
labeling_symbolic([Var|Liste]):-
	ic_symbolic:indomain(Var),
	labeling_symbolic(Liste).
```