function [res_near,res_far] = BR_run_study_gen_NM(test_KB_gen)
%

ALPHA = 0.001;
TOL = 0.01;
MAX_SEARCH = 10;

num_KB = length(test_KB_gen);

for k = 1:num_KB
    k
    clear BR_outfun
    KB = test_KB_gen(k).KB;
    ap = test_KB_gen(k).ap;
    % near initial point
    x0 = ap + min(1,max(0,0.1*(0.5-rand(length(ap),1))));
    done = 0;
    count = 0;
    OK = 0;
    while done==0
        count = count + 1;
        BAD = 0;
        try
            [xt,et] = BR_sym_Newton(KB,x0);
        catch ME
           xt = 0;
           BAD = 1;
        end
        x_star = xt(end,:)';
        if (min(x_star)>=0&max(x_star)<=1)&(et(end)<TOL)&BAD==0
            OK = 1;
            done = 1;
        elseif (count>=MAX_SEARCH)
            done = 1;
        else
            x0 = rand(length(ap),1);
        end
    end
    if OK==1
        res_near(k).xt = xt;
        res_near(k).et = et;
        [c,ct] = BR_res_convergence(xt);
        res_near(k).c = c;
        res_near(k).ct = ct;
        res_near(k).iters = count;
    else
        res_near(k).xt = [];
        res_near(k).et = [];
        res_near(k).c = [];
        res_near(k).ct = [];
        res_near(k).iters = count;
    end
    % far initial point
    x0 = min(1,max(0,1-ap));
    done = 0;
    count = 0;
    OK = 0;
    while done==0
        count = count + 1;
        BAD = 0;
        try
            [xt,et] = BR_sym_Newton(KB,x0);
        catch ME
            xt = 0;
            BAD = 1;
        end
        x_star = xt(end,:)';
        if (min(x_star)>=0&max(x_star)<=1)&(et(end)<TOL)&BAD==0
            OK = 1;
            done = 1;
        elseif (count>=MAX_SEARCH)
            done = 1;
        else
            x0 = rand(length(ap),1);
        end
    end
    if OK==1
        res_far(k).xt = xt;
        res_far(k).et = et;
        [c,ct] = BR_res_convergence(xt);
        res_far(k).c = c;
        res_far(k).ct = ct;
        res_far(k).iters = count;
    else
        res_far(k).xt = [];
        res_far(k).et = [];
        res_far(k).c = [];
        res_far(k).ct = [];
        res_far(k).iters = count;
    end
end
