function [x violation] = BoolLP_cvxccv(x_0,A,b, varargin)
%% uses the convex concave procedure to solve the boolean LP:
% find x \in {0,1} such that Ax <= b.
% x_0 is the initial x,
% varargin is an optional length 2 array consisting of:
% tol,  the stopping tolerance criterion
% iterations, the maximum number of iterations

numvarargs = length(varargin);
optargs = {1e-3 100};
optargs(1:numvarargs) = varargin;
[tol iterations] = optargs{:};

[m n] = size(A);
cvx_prev = inf;
x_c = x_0;

% perform the convex_concave procedure
for iter = 1:iterations
    cvx_begin quiet
    variables x(n) slack(n);
    minimize sum(slack);
    for i = 1:n
        square(x(i))-x(i) <= 0;
        x(i)-x_c(i)^2 - 2*x_c(i)*(x(i)-x_c(i)) <= slack(i);
    end
    slack >= 0;
    A*x <= b;
    cvx_end
    
    x_c = x;
    
    if(norm(cvx_prev-sum(slack)) < tol)
        break;
    end
    cvx_prev = sum(slack);
end
% calculate the number of violated constraints
violation = sum(A*round(x) > b);
end

