5. conv_opt package

5.2. Submodules

5.3. conv_opt.core module

Module for solving linear and quadratic optimization problems using multiple open-source and commercials solvers.

Author:Jonathan Karr <jonrkarr@gmail.com>
Date:2017-11-14
Copyright:2017, Karr Lab
License:MIT
class conv_opt.core.Constraint(terms=None, name='', lower_bound=None, upper_bound=None)[source]

Bases: object

A constraint

name[source]

name

Type:str
terms[source]

the variables and their coefficients

Type:list
lower_bound[source]

lower bound

Type:float
upper_bound[source]

upper bound

Type:float
dual[source]

dual value

Type:float
exception conv_opt.core.ConvOptError[source]

Bases: Exception

conv_opt exception

class conv_opt.core.ExportFormat[source]

Bases: enum.Enum

Export format

alp = 0[source]
cbf = 1[source]
dpe = 2[source]
dua = 3[source]
jktask = 4[source]
lp = 5[source]
mps = 6[source]
opf = 7[source]
ppe = 8[source]
rew = 9[source]
rlp = 10[source]
sav = 11[source]
task = 12[source]
xml = 13[source]
class conv_opt.core.LinearTerm(variable, coefficient)[source]

Bases: conv_opt.core.Term

Linear term (of an objective or contraint)

variable[source]

variable

Type:Variable
class conv_opt.core.Model(name='', variables=None, objective_direction=<ObjectiveDirection.min: 1>, objective_terms=None, constraints=None)[source]

Bases: object

A mathematical model

name[source]

name

Type:str
variables[source]

the variables, \(x\)

Type:list
objective_direction[source]

objective direction

Type:ObjectiveDirection
objective_terms[source]

the elements of the objective, \(c\) and \(Q\)

Type:list
constraints[source]

the constraints, \(A\) and \(b\)

Type:list
convert(options=None)[source]

Generate a data structure for the model for another package

Parameters:options (SolveOptions, optional) – options
Returns:model in a data structure for another package
Return type:object
Raises:ConvOptError – if the solver is not supported
export(filename, format=None, solver=None)[source]

Export a model to a file in one of these support formats

  • alp: model with generic names in lp format, where the variable names are annotated to indicate the type and bounds of each variable
  • cbf
  • dpe: dual perturbed model
  • dua: dual
  • jtask: Jtask format
  • lp
  • mps
  • opf
  • ppe: perturbed model
  • rew: model with generic names in mps format
  • rlp: model with generic names in lp format
  • sav
  • task: Task format
  • xml: OSiL
Parameters:
  • filename (str) – path to save model
  • format (str, optional) – export format; if the format is not provided, the format is inferred from the filename
  • solver (Solver, optional) – desired solver to do the exporting; if none, a supported solver will be found
Raises:

ConvOptError – if the format is not supported

get_type()[source]

Get the type of the model

Returns:model type
Return type:ModelType
set_solver_options()[source]

Set solver options

solve(options=None)[source]

Solve the model

Parameters:options (SolveOptions, optional) – options
Returns:result
Return type:Result
Raises:ConvOptError – if the solver is not supported
class conv_opt.core.ModelType[source]

Bases: enum.Enum

Model type

fixed_milp = 0[source]
fixed_miqp = 1[source]
lp = 2[source]
milp = 3[source]
miqp = 4[source]
qp = 5[source]
class conv_opt.core.ObjectiveDirection[source]

Bases: enum.Enum

Direction to solve a mathematical model

max = 0[source]
maximize = 0[source]
min = 1[source]
minimize = 1[source]
class conv_opt.core.Presolve[source]

Bases: enum.Enum

Presolve mode

auto = 0[source]
off = 2[source]
on = 1[source]
class conv_opt.core.QuadraticTerm(variable_1, variable_2, coefficient)[source]

Bases: conv_opt.core.Term

Quadtratic term (of an objective or contraint)

variable_1[source]

first variable

Type:Variable
variable_2[source]

second variable

Type:Variable
class conv_opt.core.Result(status_code, status_message, value, primals, reduced_costs, duals)[source]

Bases: object

The result of solving a mathematical model

status_code[source]

status code

Type:StatusCode
status_message[source]

status message

Type:str
value[source]

objective value

Type:float
primals[source]

primal values

Type:numpy.ndarray
reduced_costs[source]

reduced costs

Type:numpy.ndarray
duals[source]

dual values/shadow prices

Type:numpy.ndarray
class conv_opt.core.SolveOptions(solver=<Solver.cplex: 1>, tune=False, presolve=<Presolve.off: 2>, precision=64, round_results_to_bounds=True, verbosity=<Verbosity.off: 0>, solver_options=None)[source]

Bases: object

Options for Model.solve

solver[source]

solver

Type:Solver
tune[source]

tune (used by Gurobi)

Type:bool
presolve[source]

presolve

Type:Presolve
precision[source]

number of bits of numerical precision

Type:int
round_results_to_bounds[source]

if True, round the results to the variable bounds

Type:bool
verbosity[source]

determines how much status, warnings, and errors is printed out

Type:Verbosity
solver_options[source]

solver options

Type:attrdict.AttrDict
class conv_opt.core.Solver[source]

Bases: enum.Enum

cbc = 0[source]
cplex = 1[source]
cvxopt = 2[source]
glpk = 3[source]
gurobi = 4[source]
minos = 9[source]
mosek = 5[source]
quadprog = 6[source]
scipy = 7[source]
soplex = 10[source]
xpress = 8[source]
class conv_opt.core.SolverModel(model, options=None)[source]

Bases: object

A solver

_model[source]

model

Type:Model
options[source]

options

Type:SolveOptions
get_model()[source]

Get the model in the raw format of the solver. This is useful for acessing specific properties and methods of the solver.

Returns:the model in the format of the solver
Return type:object
get_stats()[source]

Get diagnostic information about the model

Returns:diagnostic information about the model
Return type:object
load(conv_opt_model)[source]

Load a model to the data structure of the solver

Parameters:conv_opt_model (Model) – model
Returns:the model in the data structure of the solver
Return type:object
solve()[source]

Solve the model

Returns:result
Return type:Result
class conv_opt.core.StatusCode[source]

Bases: enum.Enum

Status code for the result of solving a mathematical model

infeasible = 1[source]
optimal = 0[source]
other = 2[source]
class conv_opt.core.Term(of an objective or contraint)[source]

Bases: object

coefficient[source]

coefficient

Type:float
class conv_opt.core.Variable(name='', type=<VariableType.continuous: 1>, lower_bound=None, upper_bound=None)[source]

Bases: object

A variable

name[source]

name

Type:str
type[source]

type

Type:VariableType
lower_bound[source]

lower bound

Type:float
upper_bound[source]

upper bound

Type:float
primal[source]

primal value

Type:float
reduced_cost[source]

reduced cost

Type:float
class conv_opt.core.VariableType[source]

Bases: enum.Enum

Variable type

binary = 0[source]
continuous = 1[source]
integer = 2[source]
partially_integer = 5[source]
semi_continuous = 4[source]
semi_integer = 3[source]
class conv_opt.core.Verbosity[source]

Bases: enum.Enum

Verbosity level

error = 1[source]
off = 0[source]
status = 3[source]
warning = 2[source]

5.4. Module contents