Example for the C interface

This example is the direct counterpart to the miniature C example for a convex quadratic in two variables.

julia> using ConicBundle
julia> function eval_fun(function_key, x, relprec, max_new_subg, objective_threshold, subgval, subgradient, primal) # compute objective objective_value = .5*(5x[1]*x[1] + 2x[1]*x[2] + 4x[2]*x[2]) - 12x[1] - 10x[2] + 3; new_subg = 1 subgval[1] = objective_value subgradient[1] = (5x[1] + x[2]) - 12; subgradient[2] = (x[1]+4*x[2]) - 10; return objective_value, new_subg endeval_fun (generic function with 1 method)
julia> p = CBProblem{Int}() # the type parameter specified the type that our function_key will have - irrelevant hereConicBundle problem (using C interface) of dimension 0
julia> cb_init_problem!(p, 2) # 2 variables, no bounds
julia> cb_add_function!(p, 0, eval_fun) # the second parameter is our function_key; no extensions, no primal
julia> cb_set_print_level!(p, 1)
julia> cb_set_term_relprec!(p, 1e-8) # set relative precision
julia> cb_solve!(p) # minimize the function up to termination00:00:00.25 enditd 1 1 1 15.6 3.95 -12.62049935 -9.833614106 00:00:00.25 enditd 2 2 2 15.6 2.59 -16.65671640 -15.23315085 00:00:00.25 enditd 3 3 3 6.52 2.72 -22.88917253 -18.92748249 00:00:00.25 enditd 4 4 4 6.52 0.326 -19.11365106 -18.98728437 00:00:00.25 enditd 5 5 5 6.52 0.119 -19.00386031 -18.99730927 00:00:00.25 enditd 6 6 6 5.15 0.0624 -19.00152765 -18.99974036 00:00:00.25 enditd 7 7 7 4.37 0.0207 -19.00019414 -18.99998940 00:00:00.25 enditd 8 8 8 3.94 0.00438 -19.00001034 -18.99999985 00:00:00.25 enditd 9 9 9 3.94 0.000506 -19.00000011 -19.00000000 00:00:00.25 endit_ 9 10 10 3.46 7.79e-05 -19.00000000 -19.00000000
julia> cb_print_termination_code(p)termination status: 1, relative precision criterion satisfied
julia> x = cb_get_center(p) # retrieve the computed solution2-element Vector{Float64}: 2.000023724434169 1.9999658320827043
julia> print("x = ", x, ", objval = ", cb_get_objval(p))x = [2.000023724434169, 1.9999658320827043], objval = -18.9999999970686