function [w,E,alp]=LinearRankerQPsoft(X,C)
%X is N x d (d is the dimension) and is assumed ordered from top to bottom.
% w are weights that attempt to get the scores Xw in the right order.


warning off

[N,d]=size(X);

H=[eye(d), zeros(d,N-1);zeros(N-1,d+N-1)];
f=[zeros(d,1);C*ones(N-1,1);1];
A=[-[X(1:end-1,:)-X(2:end,:),eye(N-1),zeros(N-1,1)];eye(d),zeros(d,N-1),-ones(d,1);-eye(d),zeros(d,N-1),-ones(d,1)];
b=[-ones(N-1,1);zeros(2*d,1)];
Aeq=[];
beq=[];
LB=[-Inf*ones(d,1);zeros(N-1,1);-Inf];
UB=Inf*ones(d+N,1);
X0=[];
options=optimset('linprog');
options=optimset(options,'Display','off');
wE=linprog(f,A,b,Aeq,beq,LB,UB,X0,options);

w=wE(1:d);
E=wE(d+1:end-1);
alp=wE(end);
