/* Matchup PuzzlOR problem in Picat. http://puzzlor.com/2006-08_Matchup.html """ Matchup As the owner of a new dating website, you’re working on the logic on how to best match men and women together. Providing people with good dating candidates is important to keep them interested in using the website and for relationship success. So far, your first clients are 10 women and 10 men. The table below shows the personality characteristics for each person. The goal is to match pairs (one man to one woman) so that the most number of characteristics match. For each characteristic that matches, you earn one point. For example, matching Man 1 and Woman 1, would be worth two points (because the Living Preference and Social characteristics match). Person Politics Hobby Living Preference Social ---------------------------------------------------------- Man 1 Liberal Running Rural Introverted Man 2 Liberal Chess Rural Outgoing Man 3 Conservative Running Urban Introverted Man 4 Liberal Running Rural Introverted Man 5 Conservative Running Rural Introverted Man 6 Conservative Chess Rural Introverted Man 7 Conservative Chess Urban Introverted Man 8 Liberal Chess Urban Introverted Man 9 Liberal Running Urban Introverted Man 10 Liberal Running Urban Outgoing Woman 1 Conservative Chess Rural Introverted Woman 2 Liberal Running Rural Introverted Woman 3 Conservative Chess Rural Outgoing Woman 4 Conservative Running Urban Outgoing Woman 5 Conservative Chess Urban Outgoing Woman 6 Liberal Running Urban Introverted Woman 7 Conservative Chess Urban Outgoing Woman 8 Conservative Running Urban Outgoing Woman 9 Liberal Chess Urban Introverted Woman 10 Liberal Running Rural Introverted Question: What is the maximum number of points you can achieve? Send your answer to puzzlor@gmail.com by October 15th, 2016. The winner, chosen randomly from correct answers, will receive a $25 Amazon Gift Card. Past questions and answers can be found at puzzlor.com. """ There are 48 optimal solutions with a score of 33. Here is one solution: z = 33 x = [12,17,14,20,13,11,15,19,16,18] y = [4,2,3,4,2,4,3,4,4,3] Man 1 is matched with Woman 2 with score 4 Man 2 is matched with Woman 7 with score 2 Man 3 is matched with Woman 4 with score 3 Man 4 is matched with Woman 10 with score 4 Man 5 is matched with Woman 3 with score 2 Man 6 is matched with Woman 1 with score 4 Man 7 is matched with Woman 5 with score 3 Man 8 is matched with Woman 9 with score 4 Man 9 is matched with Woman 6 with score 4 Man 10 is matched with Woman 8 with score 3 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 => Liberal = 1, Conservative = 2, Running = 3, Chess = 4, Rural = 5, Urban = 6, Introverted = 7, Outgoing = 8, Attributes = [ [Liberal, Running,Rural,Introverted], % Man 1 [Liberal, Chess, Rural,Outgoing], [Conservative,Running,Urban,Introverted], [Liberal, Running,Rural,Introverted], [Conservative,Running,Rural,Introverted], [Conservative,Chess, Rural,Introverted], [Conservative,Chess, Urban,Introverted], [Liberal, Chess, Urban,Introverted], [Liberal, Running,Urban,Introverted], [Liberal, Running,Urban,Outgoing], % Man 10 [Conservative,Chess, Rural,Introverted], % Woman 1 [Liberal, Running,Rural,Introverted], [Conservative,Chess, Rural,Outgoing], [Conservative,Running,Urban,Outgoing], [Conservative,Chess, Urban,Outgoing], [Liberal, Running,Urban,Introverted], [Conservative,Chess, Urban,Outgoing], [Conservative,Running,Urban,Outgoing], [Liberal, Chess, Urban,Introverted], [Liberal, Running,Rural,Introverted] % Woman 10 ], N = Attributes.len, P = N div 2, M = Attributes[1].len, % decision variables X = new_list(P), X :: P+1..P+10, Y = new_list(P), Y :: 0..M, Z #= sum(Y), % constraints all_different(X), foreach(I in 1..P) Y[I] #= sum([ Attributes[I,K] #= AJK : K in 1..M, matrix_element(Attributes,X[I],K,AJK)]) end, % Z #= 33, % checking the number of optimal solutions Vars = X.vars() ++ Y, solve($[ff,split,max(Z)], Vars), % solve($[ff,split], Vars), println(z=Z), println(x=X), println(y=Y), foreach(I in 1..P) printf("Man %2d is matched with Woman %2d with score %d\n", I,X[I]-10, Y[I]) end, % fail, nl.