%
% simplifying a cone
%     U : span vectors (column vectors) of original cone
%     Usimplified : span vectors (column vectors) of simplified cone
%
function Usimplified = PCC_simplify ( U )
    options = optimoptions('linprog');
    options.Display = 'none';

    n = size(U,2);
    if n <= 1
        Usimplified = U;
        return;
    end

    found = 1;
    while found == 1
        found = 0;
        for k=n:(-1):1
            Aineq = -eye(n-1);
            bineq = zeros(n-1,1);
            Aeq = U(:,[1:k-1,k+1:n]);
            beq = U(:,k);
            f = ones(n-1,1);
            x = linprog(f,Aineq,bineq,Aeq,beq,[],[],options);
            if size(x,1) ~= 0
                U = U(:,[1:k-1,k+1:n]);
                n = size(U,2);
                if n <= 1
                   Usimplified = U;
                   return;
                end
                found = 1;
                break;
            end
        end
    end
    
    Usimplified = U;
end
