k=10000;

mosekYMPtime = tic;

yalmip('clear')
%% parameters
prm.debug = true;
prm.visualize = true;

prm.init.method = 'solve_unconstrained';
prm.constraints.C = 1000; 
prm.solve.solver = 'mosek'; %solver of choice
prm.solve.max_iter = 1000;
prm.solve.thresh_obj = 1e-6;
prm.solve.thresh_Y = 1e-6;
prm.solve.yalmip_prm = sdpsettings('solver',prm.solve.solver,'verbose',1);
prm.solve.yalmip_prm.quadprog.Algorithm = 'interior-point-convex';

% prm = setParams;
MAX_ITER = 150;


v = sdpvar(n,1); 
F = G*v;

z = [F - exR; sqrt(k)*(v(indices) - exV(indices))]; % z'*z
t = sdpvar;

%
% Conic programming
%
objective = t;
objectiveConstraints = cone(z,t);
c = [objectiveConstraints];

%c = [c (v(indices) == exV(indices))];

% %
% % Quadratic programming
% %
% objective = z'*z;
% c = [];

if bNoninversion

nF = sizeExR;
for i=1:nF
    curR = [exR(4*i-3) exR(4*i-2);exR(4*i-1) exR(4*i)];
    curF = [F(4*i-3) F(4*i-2);F(4*i-1) F(4*i)];
    
    RtFSym = curR'*curF+curF'*curR;
    a = (RtFSym(1,1)+RtFSym(2,2))/2;
    b = (RtFSym(1,1)-RtFSym(2,2))/2;
    d = RtFSym(1,2);
    c = [c, cone([b,d],a)];
end

end

sdpYalTime  = toc(mosekYMPtime);
fprintf('socp feed to Yalmip time = %f\n',sdpYalTime);

%diary('mosekProgress.txt');
sdpYMPtime = tic;
res = solvesdp(c,objective, prm.solve.yalmip_prm);

sdpYMTime  = toc(sdpYMPtime);
%diary off

fprintf('socp yalmip+mosek time = %f\n',sdpYMTime);


v_value=value(v);

checkSolution(v_value, exR, exV, indices, G, k);

optiV = x2vt(v_value);

write2obj(optiV, FList, 'MosekM.obj');


visualizeDistort( VList, FList, optiV, exR );
axis equal;

fprintf('socp feed to Yalmip time = %f\n',sdpYalTime);
fprintf('socp solving time = %f\n',sdpYMTime);


