%{
*********************************************************** 
(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 = basic_func(T, C, w)


k = max(C(:));

[n, t] = size(T);

%% construct A \in R^{n \times kt}
A = zeros(n, k * t);
for i = 1 : n
    start_idx = t * (C(i) - 1) + 1;
    A(i, start_idx : start_idx + t - 1) = T(i, :);
end

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

A = [-A ; B];

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

f = ones(k * t, 1);

intcon = (1 : k * t);

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

x = uint8(x);
