Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=0)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=1)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
n = 10*k
# Set options of the OSQP solver
options = {'eps_abs': 1e-5,
'eps_rel': 1e-5,
'alpha': 1.6,
'scale_problem': True,
'scale_steps': 20,
'polish': False}
# Create a lasso object
portfolio_obj = portfolio(k, n, dens_lvl=0.3, version='sparse',
osqp_opts=options)
# Solve with different solvers
resultsCPLEX = portfolio_obj.solve(solver=CPLEX)
resultsGUROBI = portfolio_obj.solve(solver=GUROBI)
resultsOSQP = portfolio_obj.solve(solver=OSQP)
# Print objective values
print "CPLEX Objective Value: %.3f" % resultsCPLEX.objval
print "GUROBI Objective Value: %.3f" % resultsGUROBI.objval
print "OSQP Objective Value: %.3f" % resultsOSQP.objval
print "\n"
# Print timings
print "CPLEX CPU time: %.3f" % resultsCPLEX.cputime
print "GUROBI CPU time: %.3f" % resultsGUROBI.cputime
print "OSQP CPU time: %.3f" % resultsOSQP.cputime
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=0)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=0)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=1)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=0)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=0)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=0)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results
def solve(self, solver=OSQP):
"""
Solve the problem with a specificed solver.
"""
if solver == OSQP:
results = self._osqp.solve()
elif solver == CPLEX:
results = self._prob.solve(solver=CPLEX, verbose=0)
elif solver == GUROBI:
results = self._prob.solve(solver=GUROBI, OutputFlag=0)
else:
assert False, "Unhandled solver"
return results