flopt
latest

Contents:

  • Installation
  • Tutorial
  • Case Studies
  • Solvers
    • Solver Selector
    • Iterative Search
    • Swarm Intelligence Search
    • Baysian Search
    • Evolution Search
    • Quadratic Programming Search
      • GurobiSearch
        • GurobiSearch
      • CvxoptSearch
        • CvxoptSearch
    • Linear Programming Search
    • non-Linear Programming Search
    • Quantum Annealing Search
  • API Reference
  • Internal Reference
  • Recipes
flopt
  • Solvers
  • Quadratic Programming Search
  • Edit on GitHub

Quadratic Programming Search

GurobiSearch

Solver name is “Gurobi”.

https://img.shields.io/badge/Variable-Number-blue.svghttps://img.shields.io/badge/Objective-Quadratic-orange.svghttps://img.shields.io/badge/Constraints-Quadratic-green.svg
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”.

https://img.shields.io/badge/Variable-Continuous-blue.svghttps://img.shields.io/badge/Objective-Quadratic-orange.svghttps://img.shields.io/badge/Constraints-Linear-green.svg
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
Previous Next

© Copyright 2021, Nariaki Tateiwa. Revision ff418914.

Built with Sphinx using a theme provided by Read the Docs.