oxfordcontrol / Clarabel.cpp

Clarabel.cpp: C/C++ interface to the Clarabel Interior-point solver for convex conic optimisation problems.
Apache License 2.0
33 stars 11 forks source link

solution.obj_val is not set #22

Closed hongkai-dai closed 1 year ago

hongkai-dai commented 1 year ago

At the termination, should I expect that solution.obj_val is the objective value? I ran https://github.com/oxfordcontrol/Clarabel.cpp/blob/main/examples/cpp/example_lp.cpp and also print out solution.obj_val, the log shows that the objective value is -2, but std::cout << "obj_val: " << solution.obj_val << "\n" prints 5e-5. Here is my print out

-------------------------------------------------------------
           Clarabel.rs v0.0.0  -  Clever Acronym

                   (c) Paul Goulart
                University of Oxford, 2022
-------------------------------------------------------------

problem:
  variables     = 2
  constraints   = 4
  nnz(P)        = 0
  nnz(A)        = 4
  cones (total) = 1
    : Nonnegative = 1,  numel = 4

settings:
  linear algebra: direct / qdldl, precision: 64 bit
  max iter = 200, time limit = Inf,  max step = 0.990
  tol_feas = 1.0e-8, tol_gap_abs = 1.0e-8, tol_gap_rel = 1.0e-8,
  static reg : on, ϵ1 = 1.0e-8, ϵ2 = 4.9e-32
  dynamic reg: on, ϵ = 1.0e-13, δ = 2.0e-7
  iter refine: on, reltol = 1.0e-13, abstol = 1.0e-12,
               max iter = 10, stop ratio = 5.0
  equilibrate: on, min_scale = 1.0e-4, max_scale = 1.0e4
               max iter = 50

iter    pcost        dcost       gap       pres      dres      k/t        μ       step
---------------------------------------------------------------------------------------------
  0  +0.0000e+00  -6.0000e+00  6.00e+00  0.00e+00  0.00e+00  1.00e+00  1.40e+00   ------
  1  -9.1640e-01  -2.0400e+00  1.12e+00  8.16e-17  1.02e-16  1.93e-01  2.63e-01  8.25e-01
  2  -1.9880e+00  -2.0193e+00  1.58e-02  3.00e-17  4.10e-17  6.96e-03  7.66e-03  9.90e-01
  3  -1.9999e+00  -2.0002e+00  1.57e-04  1.20e-16  0.00e+00  6.97e-05  7.67e-05  9.90e-01
  4  -2.0000e+00  -2.0000e+00  1.57e-06  1.83e-13  2.20e-13  6.97e-07  7.67e-07  9.90e-01
  5  -2.0000e+00  -2.0000e+00  1.57e-08  3.66e-15  4.39e-15  6.97e-09  7.67e-09  9.90e-01
  6  -2.0000e+00  -2.0000e+00  1.57e-10  8.47e-17  8.20e-17  6.97e-11  7.67e-11  9.90e-01
---------------------------------------------------------------------------------------------
Terminated with status = Solved
solve time = 57.906µs
Solution (x)     = [-0.9999999999, 0.9999999999]
Multipliers (z)  = [0.0000000000, 1.0000000000, 1.0000000000, 0.0000000000]
Slacks (s)       = [1.9999999999, 0.0000000001, 0.0000000001, 1.9999999999]
obj_val: 5e-05
goulart-paul commented 1 year ago

Fixed in #23 and merged to main.

Unrelated, but I don't understand why your solver version number is reporting as v0.0.0 in the first line of the example output. I can't seem to reproduce it either.

jwnimmer-tri commented 11 months ago

Unrelated, but I don't understand why your solver version number is reporting as v0.0.0 in the first line of the example output. I can't seem to reproduce it either.

My guess is that Hongkai was using my initial prototype for integrating Clarabel into Drake, which had various build system bugs.

With the version of the integration that merged (#20246), I'm seeing the correct output:

...
-------------------------------------------------------------
           Clarabel.rs v0.6.0  -  Clever Acronym              
...
hongkai-dai commented 11 months ago

Thanks Jeremy! Yes I was using your initial prototype.