/* Team building based on individuals preference in Picat. From https://stackoverflow.com/questions/50536360/team-building-based-on-individuals-preference """ Team building based on individuals preference I hope to solve this problem using miniZinc but I was to successful, I think my problem is simple but I was not able to do it, i'm strill a begginer :) So, the problem is : We have 50 individuals to be segregated into two teams, each team having 25 people. Everyone would propose a list of 5 people who he wants to be with in the same team. Individual satisfaction is defined as an integer from 0 to 5 corresponding to how many of and individual wishes (people) are in the same team. Total satisfaction is the sum of all individual satisfaction values. The goal is to maximize the satisfaction of all 50 individuals. Appreciate your help guys :) """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> nolog, M = 20, % Number of people K = 2, % Number of team N = M div K, % Number of people in a team P = 5, % number of people each person should propose if M mod N != 0 then printf("M (%d) must be divisible by K (%d)!\n", M, K), halt end, Preferences = make_random_preferences(M,K,P), % team assigments X = new_list(M), X :: 1..K, foreach(I in 1..K) sum([X[J] #= I : J in 1..M]) #= N % count(I,X,N) end, Z #= sum([sum([X[I] #= X[Preferences[I,J]] : J in 1..P]) : I in 1..M]), println(z=Z), solve($[degree,split,max(Z),report(printf("Z:%d\n",Z))],X), println(X), println(z=Z), fail, nl. go2 => true. make_random_preferences(M,K,P) = Preferences => % _ = random2(), Preferences = [], foreach(I in 1..M) T = new_map(), while (T.keys().len < P) TT = 1 + random() mod M, if TT != I, not T.has_key(TT) then T.put(TT,1) end end, T := T.keys().sort(), println(I=T), Preferences := Preferences ++ [T] end.