diff --git a/docs/src/problems.md b/docs/src/problems.md new file mode 100644 index 0000000..7c4e6c4 --- /dev/null +++ b/docs/src/problems.md @@ -0,0 +1,9 @@ +# Test Problems Algorithms + +Bilevel optimization involves optimizing two interrelated optimization tasks, where one problem (the upper level) depends on optimal solutions of another at the lower level. This part presents test problems for bilevel optimization, including single and multi-objective scenarios. + + +```@docs +TestProblems.get_problem +``` + diff --git a/src/TestProblems/TestProblems.jl b/src/TestProblems/TestProblems.jl index 99c4dd0..006a167 100644 --- a/src/TestProblems/TestProblems.jl +++ b/src/TestProblems/TestProblems.jl @@ -8,6 +8,45 @@ include("DS/DS.jl") include("TP/TP.jl") include("RealWorld/RealWorld.jl") +""" + get_problem(problem) + +Return `F, f, bounds_ul, bounds_ll, Ψ, o` where + +- `F` is the upper-level objective function. +- `f` is the lower-level objective function. +- `bounds_ul` is the upper-level bounds. +- `bounds_ll` is the lower-level bounds. +- `Ψ`-mapping that receives upper-level decision vector and return a Matrix containing lower-level optimal solutions. +- `o` contain a sampled optimal solutions. + +# Example + +```julia +using BilevelHeuristics +using DelimitedFiles + +F, f, bounds_ul, bounds_ll, _ = TestProblems.get_problem("TP1") + +algorithm = SMS_MOBO(; + ul = SMS_EMOA(;N = 100), # upper level optimizer + ll = NSGA2(;N = 50), # lower level optimizer + ul_offsprings = 10, + options_ul = Options(iterations = 100, f_calls_limit=Inf), + options_ll = Options(iterations = 50, f_calls_limit=Inf) + ) + +res = optimize(F, f, bounds_ul, bounds_ll, algorithm) + +final_archive = algorithm.parameters.archive + +final_archive[1][1] # upper level (solution #1) +final_archive[1][2] # lower level (solution #1) + +ul_front = fvals([sol[1] for sol in final_archive]) +writedlm("data.csv", ul_front, ',') +``` +""" function get_problem(problem::AbstractString) if problem[1:2] == "TP" return TP.get_problem(parse(Int, problem[3:end]))