%% clique.lp -- ASP solution to additional exercise for Chapter 6, finding %% cliques in a graph. %% Last Modified: 3/26/14 %% A clique is a subset of a graph such that each of its vertices %% is connected by an edge to all the other vertices in the clique. %% Note that each node of a graph is a clique of size 1 and that the empty %% set is also a clique. %% Write an ASP program which finds all cliques in a given undirected graph; %% i.e., each answer set will correspond to one clique in the graph. %% Bonus: Look up the #count aggregate in the manual for your %% solver of choice and use it to modify your program to only find %% cliques of size >= 3. in_clique(N) | -in_clique(N) :- node(N). :- in_clique(N1), in_clique(N2), N1 != N2, not edge(N1,N2). %% Bonus: %% :- #count{N : in_clique(N)} < 3. %% Graph description (change at will): node(1..5). edge(1,2). edge(2,3). edge(3,4). edge(3,5). edge(4,5). %% The graph is undirected: edge(N1,N2) :- edge(N2,N1). %% Output formating of clingo: %#show in_clique/1. %% or use -pfilter=in_clique as an inline option with dlv