function [w  b  obj] = RSVMPlus_QCQP(X, Y, componentDistances, C, C_r, lambreg, option)

[numInstances numFeatures] = size(X);
numEq = numInstances*(numInstances-1)/2;

P0 = eye(numFeatures + 2);
P0(numFeatures + 1, numFeatures + 1) = 0; 
P0(numFeatures + 2, numFeatures + 2) = 0; 

P = zeros(numFeatures + 2, numFeatures + 2, numEq);
t = 0;
for i = 1: numInstances
    for j = (i+1) :numInstances
        t = t+1; 
        tmp = [];
        for k  = 1:numFeatures
            tmp = [tmp componentDistances(i, j, k)]; 
        end
        tmp = [diag(tmp) zeros(numFeatures, 1) zeros(numFeatures, 1)]; 
        P(:,:, t) = [tmp' zeros(numFeatures+2, 1) zeros(numFeatures+2, 1) ]; 
    end
end

q0 = zeros(numFeatures + 1,1);
q0(numFeatures + 2) = C_r/2; 

q1 = zeros(numFeatures + 1,1);
q1(numFeatures + 2) = -1;


q = zeros(numInstances, numFeatures + 2); 
for i = 1:numInstances
    q(i,:) = -1 * [Y(i) * X(i,:) Y(i) 0]; 
end

t

cvx_begin
    variable v(numFeatures + 2)
   % dual variables lam1 lam2 
    minimize( 0.5*quad_form(v,P0) + q0' * v)
    for i = 1:numEq
        0.5*quad_form(v,P(:,:,i)) + q1' * v <= 0;
    end
    for i = 1:numInstances
        q(i,:) * v + 1 <= 0;
    end
    
    
cvx_end

