classdef basic_constrained
    %{
        A basic example where the upper and lower level programs are totally unlinked.
    %}
    properties(Constant)
        name = 'basic_constrained';
        category = 'miscellaneous';
        subcategory = '';
        datasets = {};
        x0 = [1.0,  0.0,  3.0, -4.0];
        y0 = [1.0,  0.0,  3.0, -4.0];
    end


    methods(Static)

        % Upper-level objective function
        function val = F(x, ~, ~)
            val = sum(x.^2);
        end
        
        % Upper-level inequality constraints
        function val = G(x, ~, ~)
            val = [x(1)-1; x(2)+2];
        end
        
        % Upper-level equality constraints
        function val = H(x, ~, ~)
            val = [x(3)-3; x(4)+4];
        end
        
        % Lower-level objective function
        function val = f(~, y, ~)
            val = sum(y.^2);
        end
        
        % Lower-level inequality constraints
        function val = g(~, y, ~)
            val = [y(1)-1; y(2)+2];
        end
        
        % Lower-level equality constraints
        function val = h(~, y, ~)
            val = [y(3)-3; y(4)+4];
        end

        % If the bilevel program is parameterized by data, this function should
        %  provide code to read data file and return an appropriate structure.
        function val = read_data(~)
            val = [];
        end

        % Key are the function/variable names
        % Values are their dimention
        function n = dimentions(key, ~)
            n = dictionary( ...
                'x', 4, ...
                'y', 4, ...
                'F', 1, ...
                'G', 2, ...
                'H', 2, ...
                'f', 1, ...
                'g', 2, ...
                'h', 2 ...
            );
            if isKey(n,key)
                n = n(key);
            end
        end
    end
end