How to use the quadprog.problem.OPTIMAL function in quadprog

To help you get started, we’ve selected a few quadprog 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 oxfordcontrol / osqp / tests / python / quadprog / solvers / cplex_qpif.py View on Github external
# CPLEX interface to solve QP problems
import numpy as np
import quadprog.problem as qp
from quadprog.results import quadprogResults
import cplex as cpx
import ipdb


class CPLEX(object):
    """
    An interface for the CPLEX QP solver.
    """

    # Map of CPLEX status to CVXPY status. #TODO: add more!
    STATUS_MAP = {1: qp.OPTIMAL,
                  3: qp.INFEASIBLE,
                  2: qp.UNBOUNDED,
                  6: qp.OPTIMAL_INACCURATE}

    def __init__(self, **kwargs):
        self.options = kwargs

    def solve(self, p):

        # Convert Matrices in CSR format
        p.A = p.A.tocsr()
        p.P = p.P.tocsr()

        # Get problem dimensions
        n = p.P.shape[0]
        m = p.A.shape[0]
github oxfordcontrol / osqp / tests / python / performance_profile_maros.py View on Github external
rM = 100

    # Preallocate min times
    mint = np.zeros(nprob)

    # Solve all Maroz Meszaros problems for all solvers
    for f in lst_probs:
        #  if p in range(nprob):  # Solve only first problems
        m = load_maros_meszaros_problem(prob_dir + "/" + f)  # Load problem
        print "Problem %i: %s \n" % (p, f[:-4])

        #  if isPSD(m.Q):
        # Solve with all solvers
        for s in xrange(nsolvers):
            res = m.solve(solver=solvers[s], verbose=0)  # No verbosity
            if res.status == qp.OPTIMAL:  # If optimal solution found
                t[p, s] = res.cputime
            else:
                t[p, s] = np.inf

        # Get minimum time
        mint[p] = np.amin(t[p, :])

        # compute r values
        for s in xrange(nsolvers):
            if t[p, s] != np.inf:
                r[p, s] = t[p, s]/mint[p]
            else:
                r[p, s] = rM
        p += 1  # Increment p problem index
    #  else:
        #  nprob -= 1  # One problem is not "usable" (Non convex)
github oxfordcontrol / osqp / quadprog / solvers / gurobi_qpif.py View on Github external
# GUROBI interface to solve QP problems
import numpy as np
from quadprog.results import quadprogResults
import gurobipy as grb
import quadprog.problem as qp
import ipdb


class GUROBI(object):
    """
    An interface for the Gurobi QP solver.
    """

    # Map of Gurobi status to CVXPY status.
    STATUS_MAP = {2: qp.OPTIMAL,
                  3: qp.INFEASIBLE,
                  5: qp.UNBOUNDED,
                  4: qp.SOLVER_ERROR,
                  6: qp.SOLVER_ERROR,
                  7: qp.SOLVER_ERROR,
                  8: qp.SOLVER_ERROR,
                  # TODO could be anything.
                  # means time expired.
                  9: qp.OPTIMAL_INACCURATE,
                  10: qp.SOLVER_ERROR,
                  11: qp.SOLVER_ERROR,
                  12: qp.SOLVER_ERROR,
                  13: qp.SOLVER_ERROR}

    def __init__(self, **kwargs):
        self.options = kwargs