function check = check_lp_opt(A,b,c,x)

% Check lp optimality conditions

eps = 1.e-5;

r = A'*x-c;
check(1) = min(r); % should be >= 0

active = (abs(r) < eps); 
W = find(active>0);
lambda = A(:,W) \ b;

rd = A(:,W)*lambda - b;

lmin = min(lambda);
lmax = max(lambda);

check(2) = b'*x - c(W)'*lambda; % should be 0

check(3) = (sign(lmin*lmax)<=0); % should be 0

check(4) = norm(rd) > eps; % should be 0

check(5) = max(lambda); % should be <= 0

correct = (check(1) >= -eps) & (abs(check(2)) < eps) ...
        & (check(4) == 0) & (check(5) < eps);

if correct
   check(6) = 0;
else
   check(6) = -111;
end


