function [eta_trj,Q] = optimize_Trajectory_M_2(A,Qr,P,N,K,M,sigma2,rho,H,w,Smax,dmin)
%UNTITLED10 Summary of this function goes here
%   Detailed explanation goes here



cvx_begin quiet

        variable Q(N,2,M)
        variable eta_trj
        variable S(N,K,M)

        maximize eta_trj 

        subject to 
            % S "slack variable constraint"
            for n = 1:N 
                for m = 1:M 
                    for k  = 1:K 
                        S(n,k,m) <=  norm(Qr(n,:,m)-w(k,:),2).^2 + 2*(Qr(n,:,m)-w(k,:))*(Q(n,:,m)-w(k,:))' ; 
                    end
                end
            end
            % dmin constraint
            for n = 1:N
                dmin^2 <= -norm(Qr(n,:,1)-Qr(n,:,2),2)^2 + 2*(Qr(n,:,1)-Qr(n,:,2))*(Q(n,:,1)-Q(n,:,2))' ; 
            end 
            
            rate_convex_trajectory_M_2(Q,A,Qr,P,N,K,M,sigma2,rho,H,w,eta_trj,dmin,S) >= eta_trj;
            Q(1,:,:) == Q(N,:,:) ;
            for n = 1:N-1
                for m = 1:M
                end
            end

                    
cvx_end

end

