%% Constrained least squares problems
% We'll reuse the sports example


teams = {'duke';'miami';'unc';'uva';'vt'};
data = [ % team 1 team 2, team 1 pts, team 2 pts
    1 2  7 52;
    1 3 21 24;
    1 4  7 38;
    1 5  0 45;
    2 3 34 16;
    2 4 25 17;
    2 5 27  7;
    3 4  7  5;
    3 5  3 30;
    4 5 14 52
];

% dimension of the system
ngames = size(data,1);
nteams = length(teams);

% construct the empty variables
G = zeros(ngames, nteams-1);
p = zeros(ngames, 1);
refteam = nteams;

% loop over all games
for g=1:ngames
  i = data(g,1);
  j = data(g,2);
  Si = data(g,3);
  Sj = data(g,4);
  
  if i~=refteam
      G(g,i) = 1;
  end
  if j~=refteam
      G(g,j) = -1;
  end
  p(g) = Si - Sj;
end

%% Let's find scores which sum to one!
n = size(G,2);
s1 = conls(G,p,ones(1,n),1)
[s2,lam] = conls_lag(G,p,ones(1,n),1)
