function [eta , A, gamma] = optimize_Allocation_M2(Q,P,w,rho,H,sigma2,M,K,N)
%This function implements the first step in the algorithim  suggested in
%the paper for joint trajectory and allocation optimization

[gamma] = SINR_calculation(Q,P,w,rho,H,sigma2,M,K,N) ; 

cvx_begin quiet

variable A(N,K,M)
variable eta

maximize eta 

subject to 
   
     Rate_Calculation(gamma,A,K,M,N) >= eta;

    
     for m = 1:M
        for n = 1:N 
        	sum(A(n,:,m)) <= 1; 
        end
    end

    
    for k = 1:K
        for n = 1:N 
        	sum(A(n,k,:)) <= 1; 
        end
    end
    
    0 <= A <= 1 ; % allowed range  
    

cvx_end



end

