How to use the quadprog.results.quadprogResults 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
# dual_lb = np.zeros(n)

            # RCx = m.solution.get_reduced_costs()  # Get reduced costs
            # for i in range(n):
            #     if RCx[i] >= 1e-07:
            #         dual_lb[i] = RCx[i]
            #     else:
            #         dual_ub[i] = -RCx[i]

            # Get computation time
            cputime = end-start

            # Get total number of iterations
            total_iter = int(model.solution.progress.get_num_barrier_iterations())

            return quadprogResults(status, objval, sol, dual,
                                   cputime, total_iter)
        else:
            return quadprogResults(status, None, None, None,
                                   cputime, None)
github oxfordcontrol / osqp / tests / python / quadprog / solvers / cplex_qpif.py View on Github external
if value == 0:
                    model.set_results_stream(None)
                    model.set_log_stream(None)
                    model.set_error_stream(None)
                    model.set_warning_stream(None)
            else:
                exec("model.parameters.%s.set(%d)" % (param, value))

        # Solve problem
        try:
            start = model.get_time()
            model.solve()
            end = model.get_time()
        except:  # Error in the solution
            print "Error in CPLEX solution\n"
            return quadprogResults(qp.SOLVER_ERROR, None, None, None,
                                   np.inf, None)

        # Return results

        # Get status
        status = self.STATUS_MAP.get(model.solution.get_status(),
                                     qp.SOLVER_ERROR)

        # Get computation time
        cputime = end-start

        if (status != qp.SOLVER_ERROR) & (status != qp.INFEASIBLE):
            # Get objective value
            objval = model.solution.get_objective_value()

            # Get solution
github oxfordcontrol / osqp / tests / python / quadprog / solvers / cplex_qpif.py View on Github external
# for i in range(n):
            #     if RCx[i] >= 1e-07:
            #         dual_lb[i] = RCx[i]
            #     else:
            #         dual_ub[i] = -RCx[i]

            # Get computation time
            cputime = end-start

            # Get total number of iterations
            total_iter = int(model.solution.progress.get_num_barrier_iterations())

            return quadprogResults(status, objval, sol, dual,
                                   cputime, total_iter)
        else:
            return quadprogResults(status, None, None, None,
                                   cputime, None)
github oxfordcontrol / osqp / quadprog / solvers / gurobi_qpif.py View on Github external
sol_dual_lb = np.zeros(nx)

            RCx = [x[i].RC for i in range(nx)]  # Get reduced costs
            for i in range(nx):
                if RCx[i] >= 1e-07:
                    sol_dual_lb[i] = RCx[i]
                else:
                    sol_dual_ub[i] = -RCx[i]

            # Get computation time
            cputime = m.Runtime

            # Total Number of iterations
            total_iter = m.BarIterCount

            return quadprogResults(status, objval, sol, sol_dual_eq,
                                   sol_dual_ineq, sol_dual_lb, sol_dual_ub,
                                   cputime, total_iter)
        else:  # Error
            # Get computation time
            cputime = m.Runtime

            return quadprogResults(status, None, None, None,
                                   None, None, None,
                                   cputime, None)
github oxfordcontrol / osqp / quadprog / solvers / gurobi_qpif.py View on Github external
if param == "verbose":
                if value == 0:
                    m.setParam("OutputFlag", 0)
            else:
                m.setParam(param, value)

        # Update model
        m.update()

        # Solve problem
        try:
            # Solve
            m.optimize()
        except:  # Error in the solution
            print "Error in Gurobi solution\n"
            return quadprogResults(qp.SOLVER_ERROR, None, None, None,
                                   None, None, None,
                                   np.inf, None)

        # Return results
        # Get status
        status = self.STATUS_MAP.get(m.Status, qp.SOLVER_ERROR)

        if (status != qp.SOLVER_ERROR) & (status != qp.INFEASIBLE):
            # Get objective value
            objval = m.objVal

            # Get solution
            sol = np.array([x[i].X for i in range(nx)])

            # Get dual variables  (Gurobi uses swapped signs (-1))
            constrs = m.getConstrs()
github oxfordcontrol / osqp / quadprog / solvers / gurobi_qpif.py View on Github external
sol_dual_ub[i] = -RCx[i]

            # Get computation time
            cputime = m.Runtime

            # Total Number of iterations
            total_iter = m.BarIterCount

            return quadprogResults(status, objval, sol, sol_dual_eq,
                                   sol_dual_ineq, sol_dual_lb, sol_dual_ub,
                                   cputime, total_iter)
        else:  # Error
            # Get computation time
            cputime = m.Runtime

            return quadprogResults(status, None, None, None,
                                   None, None, None,
                                   cputime, None)