classdef bard871
    %{
    Reference:
        Jonathan F. Bard
        Practical Bilevel Optimization: Algorithms And Applications
        Chapter 8, example 8.7.1, page 358
    %}
    properties(Constant)
        name = 'bard871';
        category = 'textbook';
        subcategory = 'bard_1998';
        datasets = {};
        x0 = [11.25];
        y0 = [5.0];
    end


    methods(Static)
        % Upper-level objective function (quadratic)
        function val = F(x, y, ~)
            val = 16*x(1)^2 + 9*y(1)^2;
        end
        
        % Upper-level inequality constraints (linear)
        function val = G(x, y, ~)
            val = [x(1); 4*x(1)-y(1)];
        end
        
        % Upper-level equality constraints (none)
        function val = H(~, ~, ~)
            val = [];
        end
        
        % Lower-level objective function (convex)
        function val = f(x, y, ~)
            val = (x(1) + y(1) - 20)^4;
        end
        
        % Lower-level inequality constraints (linear)
        function val = g(x, y, ~)
            val = [y(1); - 4*x(1) - y(1) + 50];
        end
        
        % Lower-level equality constraints (none)
        function val = h(~, ~, ~)
            val = [];
        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', 1, ...
                'y', 1, ...
                'F', 1, ...
                'G', 2, ...
                'H', 0, ...
                'f', 1, ...
                'g', 2, ...
                'h', 0 ...
            );
            if isKey(n,key)
                n = n(key);
            end
        end
    end
end