%%%%%%%%%%%%%%%%% precon %%%%%%%%%%%%%%%%%%%%
%
%Simple preconditioning procedure for facial reduction:
%turn constraints of the form <A,X>=0 with A >= 0 into
%exposing vectors.

function[V,Anew,bnew,psd] = precon(A,b,n,sMind)

psd = 0;
m = length(b);
W = zeros(n);
wich = (1:m);
for ii=1:m
    if b(ii)==0     %check psd for 0 constraints
        temp = ssMat(A(ii,:),n,sMind);
        temp = (temp+temp')/2;
        if min(eig(temp))>=-1e-14
            W = W + temp;   %if psd add to range
            wich(ii) = 0;  %keep track of psd constraints 
        end
    end
end
W = (W+W')/2;
[Q,D] = eig(W);
inds = diag(D<1e-13);
V = Q(:,inds);

wich = wich(wich>0);
Anew = A(wich,:);     %update A and b
bnew = b(wich);

if length(b)-length(wich)>0     %flag indicating psd constraint
    psd = 1;
end

end