Search code examples
roptimizationquadratic-programmingquadprogr-optimization

ROI package doesn't give a solution (qpoases solver) for an unconstrained QP


I'm setting up a simple QP to test the ROI R package. However, the package isn't able to give a wrong solution to a simple toy problem when it is unconstrained.

Example,

# Maximize -1/2 x^2 + x, no constraints
> x <- OP(Q_objective(as.matrix(-1), 1), maximum = TRUE, bounds = V_bound(lb = -Inf, ub = Inf, nobj = 1))
> x
> ROI Optimization Problem:

  Maximize a quadratic objective function of length 1 with
  - 1 continuous objective variable,

  subject to
  - 0 constraints
  - 1 lower and 0 upper non-standard variable bounds.

Looks good. But when I solve the problem I get,

> sol <- ROI_solve(x, solver = 'qpoases')
> sol
  No optimal solution found.
  The solver message was: Initialisation failed! QP could not be solved!
  The objective value is: 0.000000e+00
> sol$solution
  [1] 0
> sol$objval
  [1] 0
> sol$status
  $code
  [1] 1

  $msg
   solver qpoases
    code 36
   symbol RET_INIT_FAILED_HOTSTART
   message Initialisation failed! QP could not be solved!
   roi_code 1

Thats odd. On a related note, when I use the quadprog solver, I'm able to get the unconstrained solution (= 1), however I've had to switch from using quadprog to qpoases for other reasons.

Any help is much appreciated.

EDIT:

Oddly enough this works,

> ROI_solve(OP(Q_objective(as.matrix(-1), 1), maximum = TRUE), solver = 'qpoases')
  No optimal solution found.
  The solver message was: Initialisation failed! QP could not be solved!
  The objective value is: 0.000000e+00
> ROI_solve(OP(Q_objective(as.matrix(1), -1), maximum = FALSE), solver = 'qpoases')
  Optimal solution found.
  The objective value is: -5.000000e-01

Solution

  • This different results result from a different value set in the parameter hessian_type if the argument hessian_type is not provided by the user ROI.plugin.qpoases chooses the hessian_type. And due to a bug in the choosing of the hessian type for the first example it choose for the first example the hessian_type = 6 (unknown) and for the second the correct hessian_type = 1 identity.

    x1 <- OP(Q_objective(as.matrix(-1), 1), maximum = TRUE, bounds = NULL)
    s1 <- ROI_solve(x1, solver = 'qpoases', hessian_type = 1L)
    solution(s1)
    
    x1 <- OP(Q_objective(as.matrix(-1), 1), maximum = TRUE, bounds = NULL)
    s1 <- ROI_solve(x1, solver = 'qpoases', hessian_type = 6L)
    solution(s1)
    

    This is fixed in the new version and the new version is on the way to CRAN.