import numpy as np
import scipy.sparse as sp
import herculesabqp
def main() -> None:
q = sp.csr_matrix(
np.array(
[
[4.0, 1.0, 0.0],
[1.0, 3.0, 0.0],
[0.0, 0.0, 2.0],
],
dtype=np.float64,
)
)
c = np.array([-1.0, -0.5, -0.25], dtype=np.float64)
lb = np.zeros(3, dtype=np.float64)
ub = np.ones(3, dtype=np.float64)
result = herculesabqp.solve_box_qp(
q,
c,
lb,
ub,
assume_symmetric=True,
scaling="hessian_diag",
)
print(f"objective = {result['objective']:.8f}")
print(f"x = {result['x']}")
if __name__ == "__main__":
main()