Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare
- fun {AbsoluteValue X}
- if X<0 then ~X else X end
- end
- %Renvoie la valeur absolue de la différence entre le nombre de true et de false pour une question dans la base de donnée
- declare
- fun {CountTrueFalse L Q}
- local CountTrueFalseAux in
- fun {CountTrueFalseAux L Q Acc}
- case L of
- nil then {AbsoluteValue Acc}
- []H|T then
- if L.1.Q == true then {CountTrueFalseAux L.2 Q Acc+1}
- else {CountTrueFalseAux L.2 Q Acc-1}
- end
- end
- end
- {CountTrueFalseAux L Q 0}
- end
- end
- %Retourne la question la plus rentable de toutes
- declare
- fun {OptimalQuestion L}
- local OptimalQuestionAux in
- %LQ : list de questions (accumulateur)
- %Acc : rentabilité de la question la plus rentable POUR LE MOMENT
- %Acc2 : question la plus rentable POUR LE MOMENT (c'est ce qu'on renvoie)
- fun {OptimalQuestionAux L Acc Acc2 LQ}
- case LQ of
- nil then Acc2
- [] H|T then if {AbsoluteValue {CountTrueFalse L H}}<Acc then {OptimalQuestionAux L {AbsoluteValue {CountTrueFalse L H}} H T}
- else {OptimalQuestionAux L Acc Acc2 T}
- end
- end
- end
- {OptimalQuestionAux L {Length L} {Arity L.1}.1 {Arity L.1}}
- end
- end
- %{Browse {OptimalQuestion DB}}
- %{Browse {CountTrueFalse DB 'Est-il blanc de peau ?'}}
- %Retire une question Q chez tous les joueurs de la liste L
- declare
- fun {RemoveQuestion L Q}
- local RemoveQuestionAux in
- fun{RemoveQuestionAux L Q L2}
- case L
- of H|T then {RemoveQuestionAux T Q {Append L2 [{Record.subtract H Q}]}}
- else L2
- end
- end
- {RemoveQuestionAux L Q nil}
- end
- end
- % Retire le personnage P de la liste des joueurs L
- declare
- fun {RemovePerson P L}
- local RemovePersonAux in
- fun {RemovePersonAux P L Lnew}
- case L of H|T then
- if H.1==P then {Append Lnew T}
- else {RemovePersonAux P T {Append Lnew [H]}} end
- else Lnew
- end
- end
- {RemovePersonAux P L nil}
- end
- end
- %Crée une liste avec toutes les personnes ayant répondu A à une question Q
- declare
- fun {ListPersonTF L Q A}
- local ListPersonTFAux in
- fun{ListPersonTFAux L Q A Lnew}
- case L of H|T then
- if H.Q==A then {ListPersonTFAux T Q A {Append Lnew [H]}}
- else {ListPersonTFAux T Q A Lnew} end
- else Lnew
- end
- end
- {ListPersonTFAux L Q A nil}
- end
- end
- %Crée une liste avec toutes les personnes de la base de donnée DB
- declare
- fun {Persons DB}
- fun {PersonsAux DB L}
- case DB of nil then L
- []H|T then {PersonsAux T H.1|L}
- end
- end
- in {PersonsAux DB nil}
- end
- % Renvoie la liste de question où on a retiré Q
- declare
- fun {RemoveQ LQ Q}
- fun {RemoveQAux LQ Q LQAux}
- case LQ of nil then LQAux
- []H|T then if H==Q then {Append LQAux T}
- else {RemoveQAux T Q {Append LQAux [H]}}
- end
- end
- end
- in {RemoveQAux LQ Q nil}
- end
- declare
- fun {BuildDecisionTree DB}
- fun {Build DB LQ}
- if DB==nil then leaf(nil)
- elseif LQ==nil then leaf({Persons DB})
- else
- local Q in
- Q = {OptimalQuestion DB}
- question(Q
- true:{Build {RemoveQuestion {ListPersonTF DB Q true} Q} {Arity DB.1}.2}
- false:{Build {RemoveQuestion {ListPersonTF DB Q false} Q} {Arity DB.1}.2})
- end
- end
- end
- in {Build DB {Arity DB.1}.2}
- end
- {Browse {BuildDecisionTree DB}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement