1 = {matching(G,S) : schedule(S)} :- group(G, _). count(Sum,S) :- Sum = #sum{ A : group(G,A), matching(G,S)}, schedule(S). :- count(Sum, _), Sum > {max}. %penalty(P) :- P = #sum{ R : rank(G,S,R), matching(G,S)}. penalty(G,S,R) :- matching(G,S), rank(G,S,R). sum_pen(S) :- S = #sum{ R : penalty(_,_,R)}. #minimize{ S : sum_pen(S)}. #show matching/2. #show count/2. %#show penalty/3. %#show sum_pen/1.