How to use the qpsolvers.dense_solvers function in qpsolvers

To help you get started, we’ve selected a few qpsolvers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stephane-caron / qpsolvers / examples / dense_problem.py View on Github external
if __name__ == "__main__":
    if get_ipython() is None:
        print("Usage: ipython -i %s" % basename(__file__))
        exit()

    dense_instr = {
        solver: "u = solve_qp(P, q, G, h, solver='%s')" % solver
        for solver in dense_solvers}
    sparse_instr = {
        solver: "u = solve_qp(P_csc, q, G_csc, h, solver='%s')" % solver
        for solver in sparse_solvers}

    print("\nTesting all QP solvers on a dense quadratic program...")

    sol0 = solve_qp(P, q, G, h, solver=dense_solvers[0])
    for solver in dense_solvers:
        sol = solve_qp(P, q, G, h, solver=solver)
        delta = norm(sol - sol0)
        assert delta < 1e-4, "%s's solution offset by %.1e" % (solver, delta)
    for solver in sparse_solvers:
        sol = solve_qp(P_csc, q, G_csc, h, solver=solver)
        delta = norm(sol - sol0)
        assert delta < 1e-4, "%s's solution offset by %.1e" % (solver, delta)

    print("\nDense solvers\n-------------")
    for solver, instr in dense_instr.items():
        print("%s: " % solver, end='')
        get_ipython().magic('timeit %s' % instr)

    print("\nSparse solvers\n--------------")
    for solver, instr in sparse_instr.items():
github stephane-caron / qpsolvers / examples / dense_problem.py View on Github external
[1., 2., 1.],
    [2., 0., 1.],
    [-1., 2., -1.]])
h = array([3., 2., -2.]).reshape((3,))
P_csc = csc_matrix(P)
G_csc = csc_matrix(G)


if __name__ == "__main__":
    if get_ipython() is None:
        print("Usage: ipython -i %s" % basename(__file__))
        exit()

    dense_instr = {
        solver: "u = solve_qp(P, q, G, h, solver='%s')" % solver
        for solver in dense_solvers}
    sparse_instr = {
        solver: "u = solve_qp(P_csc, q, G_csc, h, solver='%s')" % solver
        for solver in sparse_solvers}

    print("\nTesting all QP solvers on a dense quadratic program...")

    sol0 = solve_qp(P, q, G, h, solver=dense_solvers[0])
    for solver in dense_solvers:
        sol = solve_qp(P, q, G, h, solver=solver)
        delta = norm(sol - sol0)
        assert delta < 1e-4, "%s's solution offset by %.1e" % (solver, delta)
    for solver in sparse_solvers:
        sol = solve_qp(P_csc, q, G_csc, h, solver=solver)
        delta = norm(sol - sol0)
        assert delta < 1e-4, "%s's solution offset by %.1e" % (solver, delta)
github stephane-caron / qpsolvers / examples / sparse_problem.py View on Github external
def check_same_solutions(tol=0.05):
    sol0 = solve_qp(P, q, G, h, solver=sparse_solvers[0])
    for solver in sparse_solvers:
        sol = solve_qp(P, q, G, h, solver=solver)
        relvar = norm(sol - sol0) / norm(sol0)
        assert relvar < tol, "%s's solution offset by %.1f%%" % (
            solver, 100. * relvar)
    for solver in dense_solvers:
        sol = solve_qp(P_array, q, G_array, h, solver=solver)
        relvar = norm(sol - sol0) / norm(sol0)
        assert relvar < tol, "%s's solution offset by %.1f%%" % (
            solver, 100. * relvar)

qpsolvers

Quadratic programming solvers in Python with a unified API.

LGPL-3.0
Latest version published 2 months ago

Package Health Score

79 / 100
Full package analysis

Similar packages