function h = CS_KB2hp(KB)
% CS_clause2hp - converts a KB to a hyperplane normal form 
%    set of coefficients
% On input:
%     KB(struct KB): KB info (n atoms)
%      KB(k).clasues (1xk vector): disjunction as integers
%      KN(k).prob (float): clause probability
% On output:
%     h (m+2n by (n+1) vector): hyperplane coefficients for each clause
% Call:
%     h = CS_KB2hp(KB);
% Author:
%     T. Henderson
%     UU
%     Summer 2022
% 

cl = length(KB);
n = max(CS_vars(KB, []));
h = zeros(cl+2*n, n+1);
for c = 1:cl
    hp = CS_clause2hp(KB(c).clauses,n);
    h(c,:) = hp;
end

% constrain to inside hypercube
for k = 1:n
    index = cl + (k-1)*2 + 1;
    h(index,k) = 1;
    index = index + 1;
    h(index,k) = -1;
    h(index,end) = 1;
end
