function [c,ceq]=constraints_for_MATLAB(x,Qr,dmin,Smax,M,N,K,w)
%% inequality constraints
% should be written as c <= 0
Q = x(:,1:2,:) ; % the trajectory variable
S = x(:,3:end,:) ; % the slack variable.
% 28c
for n = 1:N
    for k = 1:K 
        c0(n,k,1) = S(n,k,1) - norm(Qr(n,:,1)-w(k,:),2)^2 -2*(Qr(n,:,1)-w(k,:))*(Q(n,:,1)-w(k,:))' ;
        c0(n,k,2) = S(n,k,2) - norm(Qr(n,:,2)-w(k,:),2)^2 -2*(Qr(n,:,2)-w(k,:))*(Q(n,:,2)-w(k,:))' ;
    end
end
c0 = c0(:)'; 
% 28d
for n = 1:N-1
    % maximum distance per step for UAV #1
    c1(n) =   norm(Q(n+1,:,1)-Q(n,:,1),2) -Smax ;
    % maximum distance per step for UAV #2
    c2(n) =   norm(Q(n+1,:,1)-Q(n,:,1),2) -Smax ;
end

% 28f

for n = 1:N
    c3(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
c = [c0 c1 c2 c3]' ;
%% equality constraints
% should be written as ceq == 0
% the initial point is the same as the terminal point for each UAV (M=2)
% 28 e
ceq(1,:) = Q(1,:,1) - Q(N,:,1);

ceq(2,:) = Q(1,:,2) - Q(N,:,2);
ceq =ceq(:) ; 
end


