/* How similar are people in Picat. Let's assume that each person has M important traits/interests/life choices/etc (here called "choices"), and that each such choice has K[Choice] different alternative. Now, pick N people with random sets of choices. - How similar are they to each other? This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. import util. main => go. /* */ go ?=> reset_store, run_model(100,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 4, % Number of people NumChoices = 3, % Number of choices (traits/interests/life choices/etc) K = 10, % number of different alternative for each choice % NumAlternative = random_integer_n(MaxK,NumChoices), % number of alternatives per choice Choices = [ random_integer1_n(K,NumChoices) : _ in 1..N], Diffs = [ [ abs(Choices[P1,C]- Choices[P2,C]) : P1 in 1..N, P2 in 1..N, P1 != P2] : C in 1..NumChoices], Ss = Diffs.flatten, S = Ss.sum, Same = [cond(Ss[I] == 0,1,0) : I in 1..Ss.len].sum, println([choices=Choices,diffs=Diffs,ss=Ss,s=S,same=Same]), add("p same",check(Same == 0)), add("s",S), add("same",Same).