function [KBo,vals] = CS_compact_KB(KB)
%

KBc = KB;
num_clauses = length(KBc);
n = max(BR_vals(KB,[]));
vals = -ones(n,1);
change = 1;

while change==1
    change = 0;
    for c = 1:num_clauses
        clause = KBc(c).clauses;
        ind1 = isnan(clause);
        ind2 = clause <= -Inf;
        ind3 = clause >= Inf;
        index = find(ind1+ind2+ind3==0);
        if length(index)==1
            change = 1;
            lit = clause(index);
            atom = abs(lit);
            if clause(index)<0
                values(atom) = 0;
            else
                values(atom) = 1;
            end
            for c2 = 1:num_clauses
                clause2 = KBc(c2).clauses;
                index = find(lit==clause2);
                index2 = find(-lit==clause2);
                if ~isempty(index)
                    if lit<0
                        KBc(c2).clauses(index) = -Inf;
                    else
                        KBc(c2).clauses(index) = Inf;
                    end
                    indexes = find(clause2>-Inf&clause2<Inf&~isnan(clause2));
                    if ~isempty(indexes)
                        KBc(c2).clauses(indexes) = NaN;
                    end
                elseif ~isempty(index2)
                    if lit<0
                        KBc(c2).clauses(index2) = Inf;
                    else
                        KBc(c2).clauses(index2) = -Inf;
                    end
                end
            end
        end
    end
end
tch = 0;
