Quadratic Programming Search
GurobiSearch
Solver name is “Gurobi”.
- class flopt.solvers.gurobi_search.GurobiSearch[source]
API for Gurobi
- Parameters:
gurobi_params (dict) – key is name, value is parameter value
Examples
import flopt # Variables a = flopt.Variable("a", lowBound=0, upBound=1, cat="Integer") b = flopt.Variable("b", lowBound=1, upBound=2, cat="Continuous") c = flopt.Variable("c", lowBound=-1, upBound=3, cat="Continuous") # Problem prob = flopt.Problem() prob += a + b + c * c + 2 prob += a + b >= 2 prob += b - c >= 3 prob.solve(solver="gurobi", msg=True)
To set parameter for Gurobi, you use gurobi_params argument.
solver = flopt.Solver("gurobi") solver.setParams(gurobi_params={"LogToConsole": 0}) # set LogToConsole to 0 prob.solve(solver=solver)
CvxoptSearch
Solver name is “Cvxopt”.
- class flopt.solvers.cvxopt_search.CvxoptSearch[source]
API of CVXOPT.qp Solver https://cvxopt.org/userguide/coneprog.html#quadratic-programming
- Parameters:
n_trial (int) – max iteration
Examples
import flopt x = flopt.Variable("x", lowBound=-1, upBound=1, cat="Continuous") y = flopt.Variable("y", lowBound=-1, upBound=1, cat="Continuous") prob = flopt.Problem() prob += 2*x*x + x*y + y*y + x + y prob += x >= 0 prob += y >= 0 prob += x + y == 1 status, log = prob.solve(solver="CvxoptQp", msg=True) print("obj =", flopt.Value(prob.obj)) print("x =", flopt.Value(x)) print("y =", flopt.Value(y)) >>> obj = 1.8750000000000002 >>> x = 0.2500000152449024 >>> y = 0.7499999847550975