# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .jl
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Julia 1.5.3
#     language: julia
#     name: julia-1.5
# ---

include("../load.jl")
include("../tools/plots.jl")

gm = gear(true)
uniform_sample_and_eval!(gm)
bbrs = [bbl for bbl in gm.bbls if bbl isa BlackBoxRegressor]
bbr = bbrs[1]
bbr.constraint

surveysolve(gm);

gm.solution_history

println("Approximate objective: $(bbr.optima)")
println("Actual objective: $(bbr.actuals)")

# How to narrow the gap? 
learn_constraint!(bbr, "upper" => minimum(bbr.actuals))
update_tree_constraints!(gm, bbr)
upper_bound_sample(bbr)
learn_constraint!(bbr, "reg" => minimum(bbr.actuals), regression_sparsity = 0, max_depth = 5)
update_tree_constraints!(gm, bbr)
optimize!(gm)

df = copy(gm.solution_history)
insertcols!(df, :actual => bbr.actuals)

# Showing upper bounding classifier
bbr.learners[end-1]

# Showing regressor
bbr.learners[end-2]

m = gear(false);
optimize!(m);
println("Solution: $(solution(m)) with objective $(getobjectivevalue(m))")

print(gm.model)

StarcoderdataJupyterScriptsDedupFiltered