%{
*********************************************************** 
(c) Ian Davidson and Davidson Lab. Please cite 

The Cluster Description Problem-Complexity Results, Formulations and Approximati
ons, I Davidson, A Gourru and SS. Ravi
Advances in Neural Information Processing Systems, 2018, 6191-6201
***********************************************************
%}


function x = cover_or_forget_func(T, C, w, n_nodes_to_forget)

k = max(C(:));

[n, t] = size(T);

A = zeros(n, k * t + n);
for i = 1 : n
    start_idx = t * (C(i) - 1) + 1;
    A(i, start_idx : start_idx + t - 1) = T(i, :);
    z = zeros(1, n);
    z(1, i) = 1;
    A(i, k * t + 1 : k * t + n) = z;
end

%% construct B \in R^{t \times kt}
B = zeros(t + 1, k * t + n);
for i = 1 : t
    b = zeros(1, t);
    b(1, i) = 1;
    B(i, :) = [repmat(b, 1, k), zeros(1, n)];
end
b = ones(1, n);
B(t + 1, :) = [zeros(1, k * t), b];

A = [-A ; B];

b = ones(n, 1);
b = [-b ; w ; n_nodes_to_forget];

f = ones(k * t + n, 1);

intcon = (1 : k * t + n);

x = intlinprog(f, intcon, A, b, [], [], zeros(k * t + n, 1), ones(k * t + n, 1));

x = uint8(x);
