%%%%% MakeProblemTun
%
%Create instance of Tuncel's worst case problem as in,
%Section 2.6 of Tuncel's book (2010)
%reference [30] in our manuscript
%
%Sremac, Woerdeman, and Wolkowicz
%2020

%n := order of matrices
%trbound := positive number indicating a trace bound
%svind := for faster ssvec
%sd := singularity degree
%Rot := orthogonal matrix for isomorphisms of the psd cone

function [A,b,X0] = MakeProblemTun(n,trbound,svind,sd,Rot)

tn = n*(n+1)/2;
In=eye(n);
A = zeros(sd+1,tn);
b = zeros(sd+1,1);
b(end) = trbound;

rowcount = 1;
if sd >= 2
    for ii=(n-sd+1):n-1
        temp = Rot*(In(:,ii)*In(ii,:) - In(:,ii+1)*In(1,:) - In(:,1)*In(ii+1,:))*Rot';
        temp = (temp + temp')/2;
        A(rowcount,:) = ssvec(temp,svind)';
        rowcount = rowcount+1;
    end
end

temp = Rot*In(:,n)*In(n,:)*Rot';             %everpresent constraint
temp = (temp+temp')/2;
A(rowcount,:) = ssvec(temp,svind)';
rowcount = rowcount+1;

A(rowcount,:) = ssvec(In,svind)';    %trace constraint for bounding
temp = [eye(n-sd) zeros(n-sd,sd)
    zeros(sd,n-sd) zeros(sd,sd)];
X0 = (Rot'\temp)/Rot;
X0 = trbound*X0/trace(X0);
X0 = (X0+X0')/2;


end     %end function










