function [ p_u , p_d ] = inner_layer( lamda , gama , noise_var , h_hat, h_u, h_d, h_ud , Pd_init, Pu_init )
% this dunction solves the inner layer problem for a specific m ,n ,k 
%% thresholds
lamda_thresh = (h_hat + h_d)/( (noise_var^2)*log(2) );
gama_thresh = (h_u + h_ud )/ ( (noise_var^2)*log(2) );

 if (lamda > lamda_thresh && gama< gama_thresh)
  p_d = 0;
  p_u = max(0, (1/(gama*log(2)) - (noise_var^2)/h_u) );
 elseif(lamda<lamda_thresh && gama>gama_thresh)
     p_d = max(0, 1/(lamda*log(2)) - noise_var^2/h_d) ; 
     p_u = 0;
 elseif (gama > gama_thresh && lamda >lamda_thresh )
 p_d = 0;
 p_u = 0;
 elseif (lamda < lamda_thresh && gama < gama_thresh )
    MSG = "subproblem 3" ;
    pu = Pu_init; % initial value
    pd = Pd_init; %initial value
    eps = 0.0001; % should be set
    v = 0.2;
    for i = 1:100
    [ p_u, p_d ] = CCCP (lamda , gama , pd , pu , noise_var , h_hat, h_u, h_d, h_ud);
     v = sqrt((pu - p_u)^2 + (pd - p_d)^2);
     pu = p_u;
     pd = p_d;
    L = log2(1 + SINR(pu ,pd , h_hat , h_u , noise_var) ) + log2(1 + SINR(pd ,pu , h_ud , h_d , noise_var) ) - gama*pu - lamda*pd;
    end
 end
