Added 18/06/2025
Textbook / bard_1998
bard511
Dimension
{
"x": 1,
"y": 1,
"F": 1,
"G": 1,
"H": 0,
"f": 1,
"g": 5,
"h": 0
}
Solution
{
"optimality": "global",
"x": [4],
"y": [4],
"F": -12,
"G": [4],
"H": [],
"f": 4,
"g": [5, 4, 0, 0, 4],
"h": []
}
$title Practical Bilevel Optimization Example 5.1.1 (BARD511,SEQ=4)
$onText
Example from Chapter 5, example 5.1.1, page 197
John F. Bard, Practical Bilevel Optimization: Algorithms and Applications,
Kluwer Academic Publishers, Dordrecht, 1998.
Contributor: Jan-H. Jagla, January 2009
$offText
positive variables x,y; variables objout,objin;
equations defout,defin,e1,e2,e3,e4;
defout.. objout =e= x - 4*y;
defin.. objin =e= y;
e1.. - x - y =l= -3;
e2.. -2*x + y =l= 0;
e3.. 2*x + y =l= 12;
e4.. 3*x - 2*y =l= 4;
model bard / all /;
$echo bilevel x min objin y defin e1 e2 e3 e4 > "%emp.info%"
solve bard us emp min objout;
*Note: The subsolver used by EMP might not find the global solution
parameter solution(*,*);
solution('x','book') = 4; solution('x','model') = x.l;
solution('y','book') = 4; solution('y','model') = y.l;
display solution;
from bolib3 import np
"""
Reference
John F. Bard
Practical Bilevel Optimization: Algorithms and Applications
Chapter 5, example 5.1.1, page 197
"""
# Properties
name: str = 'bard511'
category: str = 'textbook'
subcategory: str = 'bard_1998'
datasets: list = []
# Feasible point
x0 = np.array([4.0])
y0 = np.array([4.0])
# Methods
def F(x, y, data=None):
"""
Upper-level objective function
(linear)
"""
return x[0] - (4*y[0])
def G(x, y, data=None):
"""
Upper-level inequality constraints
(bounds)
"""
return x
def H(x, y, data=None):
"""
Upper-level equality constraints
(none)
"""
return np.empty(0)
def f(x, y, data=None):
"""
Lower-level objective function
(linear)
"""
return y[0]
def g(x, y, data=None):
"""
Lower-level inequality constraints
(linear)
"""
return np.array([
x[0] + y[0] - 3,
2*x[0] - y[0],
-2*x[0] - y[0] + 12,
-3*x[0] + 2*y[0] + 4,
y[0]
])
def h(x, y, data=None):
"""
Lower-level equality constraints
(none)
"""
return np.empty(0)
def read_data(filepath=''):
"""
If the bilevel program is parameterized by data, this function should
provide code to read data file and return an appropriate python structure.
"""
pass
def dimensions(key='', data=None):
"""
If the argument 'key' is not specified, then:
- a dictionary mapping variable/function names (str) to the corresponding dimension (int) is returned.
If the first argument 'key' is specified, then:
- a single integer representing the dimension of the variable/function with the name {key} is returned.
"""
n = {
"x": 1, # Upper-level variables
"y": 1, # Lower-level variables
"F": 1, # Upper-level objective functions
"G": 1, # Upper-level inequality constraints
"H": 0, # Upper-level equality constraints
"f": 1, # Lower-level objective functions
"g": 5, # Lower-level inequality constraints
"h": 0 # Lower-level equality constraints
}
if key in n:
return n[key]
return n
classdef bard511
%{
Reference
John F. Bard
Practical Bilevel Optimization: Algorithms and Applications
Chapter 5, example 5.1.1, page 197
%}
properties
name = 'bard511';
category = 'textbook';
subcategory = 'bard_1998';
datasets = {};
x0 = [4.0];
y0 = [4.0];
end
methods(Static)
% Upper-level objective function (linear)
function val = F(x, y, ~)
val = x - (4*y);
end
% Upper-level inequality constraints (bounds)
function val = G(x, ~, ~)
val = x;
end
% Upper-level equality constraints (none)
function val = H(~, ~, ~)
val = [];
end
% Lower-level objective function (linear)
function val = f(~, y, ~)
val = y;
end
% Lower-level inequality constraints (linear)
function val = g(x, y, ~)
val = [
+ x(1) + y(1) - 3;
+2*x(1) - y(1);
-2*x(1) - y(1) + 12;
-3*x(1) + 2*y(1) + 4;
y(1)
];
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', 1, ...
'H', 0, ...
'f', 1, ...
'g', 5, ...
'h', 0 ...
);
if isKey(n,key)
n = n(key);
end
end
end
end
\subsection{bard511}
\label{subsec:bard511}
% Description: bard511
This is a simple example from~\cite[Chapter 5, example 5.1.1, page 197]{Bard2000} that has only a single upper-level and single lower-level variable.
The global optimal solution occurs at the point $(x,y) = (4,4)$.
% Equation: bard511
\begin{align*}
&\minimise_{x, y} \quad && x-4y \\
&\subjectto && x \geq 0 \\
& && y \in \argmin_{y}
\left\{
\begin{array}{lrr}
y\\
\subjectto\
& -x -y \leq & -3, \\
& -2x +y \leq & 0, \\
& 2x +y \leq & 12, \\
& 3x -2y \leq & 4, \\
& y \geq & 0.
\end{array}
\right.
\end{align*}