function [ step_size ] = line_search_primal_dual( x, lambda, direction, c, A, b, t )
%LINE_SEARCH_PRIMAL_DUAL Summary of this function goes here
%   Detailed explanation goes here

primal_size = size(x, 1);
dx = direction(1:primal_size);
dlambda = direction(primal_size+1:end);

r0 = evaluate_residual(x, lambda, c, A, b, t);
nr0 = norm(r0);

step_size = 1;
flag = 0;

for i = 1:20
    x_plus_tdx = x + dx*step_size;
    lambda_plus_tdlambda = lambda + dlambda*step_size;
    r1 = evaluate_residual(x_plus_tdx, lambda_plus_tdlambda, c, A, b, t);
    nr1 = norm(r1);
    within_domain = 1;
    if (min(A'*x_plus_tdx-b) < 0 || min(lambda_plus_tdlambda) < 0)
        within_domain = 0;
    end
    if (nr1 < nr0 && within_domain ~= 0)
        flag = 1;
        break;
    end
    step_size = step_size / 2;
end

if flag == 0
    fprintf('Warning, line-search terminated because of ascent direction.\n');
    step_size = 0;
end

end

