function U = DAT_smart(T)
Mods = Modules(T);
for v = Mods
    T2 = Subtree(T,v);
    if IsStatic(T2) | IsShrubbery(T2)
        d = BUDAT(T2);
    else
        d = DAT_milp(T2);
    end
    if isnan(d)
        disp("this one")
        disp(T2)
    end
    T = Prune(T,v,d);
end
U = T{1,"Duration"};
end

    function B = IsStatic(T)
        [n dump] = size(T);
        B = 1;
        i = 1;
        while i < n+1 && B == 1
            if T{i,"Type"} == "SAND"
                B = 0;
            end
            i = i+1;
        end
    end

    function B = IsShrubbery(T)
        [n dump] = size(T);
        B = (sum(T{:,"Type"}=="BAS") == n-1);   
    end