clc;
clear;

n=676*2;
m=1250*4;
k=1e4;
nF = m/4;

% c=load('c');
% indices=load('indices');
% G=load('G');
load('sdpConst2.mat');
G = sparse(G(:,1), G(:,2), G(:,3), m, n);

YalmipPath = 'C:/Users/lifeng/zCollects/yalmip/'; % <-------- update with your YALMIP path
MosekPapth = 'C:/Program Files (x86)/Mosek/7/toolbox/r2012aom'; % <-------- update with your MOSEK path

addpath(genpath(YalmipPath));
addpath(genpath(MosekPapth));

exR = -c(n+1:n+m,1)/2;
exV = -c(1:n,1)/1e4;

Options = sdpsettings('verbose',1,'solver','mosek');

tic;
v=sdpvar(n,1); 
%t=sdpvar(m,1); 
F = G*v;

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



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

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


for i=1:nF
    curR = [exR(4*i-3) exR(4*i-1);exR(4*i-2) exR(4*i)];
    curF = [F(4*i-3) F(4*i-1);F(4*i-2) F(4*i)];
    c = [c, (curR'*curF+curF'*curR>=0)];
end


res = solvesdp(c,objective,Options);
toc;

v_value=value(v);

checkSolution(v_value, exR, exV, indices, G, k);
optiV = x2vt(v_value);


