Problem Classes

Problem

class disropt.problems.Problem(objective_function=None, constraints=None, force_general_problem=False, **kwargs)[source]

Bases: object

A generic optimization problem.

\[ \begin{align}\begin{aligned}\text{minimize } & f(x)\\\text{subject to } & g(x) \leq 0\\ & h(x) = 0\end{aligned}\end{align} \]
Parameters
  • objective_function (AbstractFunction, optional) – objective function. Defaults to None.

  • constraints (list, optional) – constraints. Defaults to None.

objective_function

Objective function to be minimized

Type

Function

constraints

constraints

Type

list

input_shape

dimension of optimization variable

Type

tuple

output_shape

output shape

Type

tuple

add_constraint(fn)[source]

Add a new constraint

Parameters

fn (Union[AbstractSet, Constraint]) – new constraint

Raises

TypeError – constraints must be AbstractSet or Constraint

project_on_constraint_set(x)[source]

Compute the projection of a point onto the constraint set of the problem

Parameters

x (ndarray) – point to project

Returns

projected point

Return type

numpy.ndarray

set_objective_function(fn)[source]

Set the objective function

Parameters

fn (AbstractFunction) – objective function

Raises

TypeError – input must be a AbstractFunction object

solve(solver='cvxpy', return_only_solution=True)[source]

Solve the problem

Returns

solution

Return type

numpy.ndarray

LinearProblem

class disropt.problems.LinearProblem(objective_function, constraints=None, **kwargs)[source]

Bases: disropt.problems.problem.Problem

Solve a Linear programming problem defined as:

\[ \begin{align}\begin{aligned}\text{minimize } & c^\top x\\\text{subject to } & G x \leq h\\ & A x = b\end{aligned}\end{align} \]
set_objective_function(objective_function)[source]

set the objective function

Parameters

objective_function (AffineForm) – objective function

Raises

TypeError – Objective function must be a AffineForm with output_shape=(1,1)

solve(initial_value=None, solver='glpk', return_only_solution=True)[source]

Solve the problem

Parameters
  • initial_value (numpy.ndarray), optional) – Initial value for warm start. Defaults to None.

  • solver (str, optional) – Solver to use [‘glpk’, ‘cvxopt’]. Defaults to ‘glpk’.

Raises

ValueError – Unsupported solver

Returns

solution

Return type

numpy.ndarray

MixedIntegerLinearProblem

class disropt.problems.MixedIntegerLinearProblem(objective_function, constraints=None, integer_vars=None, binary_vars=None, **kwargs)[source]

Bases: disropt.problems.linear_problem.LinearProblem

Solve a Mixed-Integer Linear programming problem defined as:

\[ \begin{align}\begin{aligned}\text{minimize } & c^\top x\\\text{subject to } & G x \leq h\\ & A x = b\\ & x_k \in \mathbb{Z}, \forall k \in I\\ & x_k \in \{0,1\}, \forall k \in B\end{aligned}\end{align} \]

where \(I\) is the set of integer variable indexes and \(B\) is the set of binary variable indexes.

solve(initial_value=None, solver='glpk', return_only_solution=True)[source]

Solve the problem

Parameters
  • initial_value (numpy.ndarray), optional) – Initial value for warm start. Defaults to None. Not available in GLPK

  • solver (str, optional) – Solver to use [‘glpk’, ‘gurobi’]. Defaults to ‘glpk’.

Raises

ValueError – Unsupported solver

Returns

solution

Return type

numpy.ndarray

ConvexifiedMILP

class disropt.problems.ConvexifiedMILP(objective_function, y, A, constraints=None, integer_vars=None, binary_vars=None, **kwargs)[source]

Bases: disropt.problems.milp.MixedIntegerLinearProblem

Solve a convexified Mixed-Integer Linear Problem of the form:

\[ \begin{align}\begin{aligned}\text{minimize } & c^\top x + M \rho\\\text{subject to } & x \in \mathrm{conv}(X), \:\rho \geq 0\\ & Ax \leq y + \rho \mathbf{1}\end{aligned}\end{align} \]

where the set \(X\) is a compact mixed-integer polyhedral set defined by equality and inequality constraints. Moreover, \(\rho\) is a scalar, \(y \in \mathbb{R}^{m}\) is a vector and \(A \in \mathbb{R}^{m \times n}\) is a constraint matrix.

solve(M, milp_solver=None, initial_dual_solution=None, return_only_solution=True, y=None, max_cutting_planes=None, cutting_planes=None, threshold_convergence=1e-08, max_iterations=1000)[source]

Solve the problem using a custom dual cutting-plane algorithm

Parameters
  • M (float) – value of the parameter \(M\)

  • milp_solver (str, optional) – MILP solver to use. Defaults to None (use default solver).

  • initial_dual_solution (numpy.ndarray, optional) – Initial dual value for warm start. Defaults to None.

  • return_only_solution (bool, optional) – if True, returns only solution, otherwise returns more information. Defaults to True.

  • y (np.ndarray, optional) – value to override the current y. Defaults to None (keep current value).

  • max_cutting_planes (int, optional) – maximum number of stored cutting planes. Defaults to None (disabled).

  • cutting_planes (numpy.ndarray, optional) – cutting planes for warm start previously returned by this function. Defaults to None.

  • threshold_convergence (float, optional) – threshold for convergence detection. Defaults to 1e-8.

  • max_iterations (int, optional) – maximum number of iterations performed by algorithm. Defaults to 1e3.

Returns

primal solution tuple (x, rho) if return_only_solution = True, otherwise (primal solution tuple, optimal cost, dual solution, cutting planes, number of iterations)

Return type

tuple

QuadraticProblem

class disropt.problems.QuadraticProblem(objective_function, constraints=None, is_pos_def=True, **kwargs)[source]

Bases: disropt.problems.problem.Problem

Solve a Quadratic programming problem defined as:

\[ \begin{align}\begin{aligned}\text{minimize } & x^\top P x + q^\top x + r\\\text{subject to } & G x \leq h\\ & A x = b\end{aligned}\end{align} \]

Quadratic problems are currently solved by using CVXOPT or OSQP https://osqp.org.

Parameters
  • objective_function (QuadraticForm) – objective function

  • constraints (list, optional) – list of constraints. Defaults to None.

  • is_pos_def (bool) – True if P is (semi)positive definite. Defaults to True.

set_constraints(constraints)[source]

Set the constraints

Parameters

constraints (list) – list of constraints

Raises

TypeError – a list of affine Constraints must be provided

set_objective_function(objective_function)[source]

set the objective function

Parameters

objective_function (QuadraticForm) – objective function

Raises

TypeError – Objective function must be a QuadraticForm

solve(initial_value=None, solver='osqp', return_only_solution=True)[source]

Solve the problem

Parameters
  • initial_value (numpy.ndarray), optional) – Initial value for warm start. Defaults to None.

  • solver (str, optional) – Solver to use (‘osqp’ or ‘cvxopt’). Defaults to ‘osqp’.

Raises

ValueError – Unsupported solver, only ‘osqp’ and ‘cvxopt’ are currently supported

Returns

solution

Return type

numpy.ndarray

ProjectionProblem

class disropt.problems.ProjectionProblem(*args, **kwargs)[source]

Bases: disropt.problems.problem.Problem

Computes the projection of a point onto some constraints, i.e., it solves

\[ \begin{align}\begin{aligned}\text{minimize } & \frac{1}{2}\| x - p \|^2\\\text{subject to } & f_k(x)\leq 0, \, k=1,...\end{aligned}\end{align} \]
Parameters
  • constraints_list (list) – list of constraints

  • point (numpy.ndarray) – point \(p\) to project

solve()[source]

solve the problem

Returns

solution

Return type

numpy.ndarray

ConstraintCoupledProblem

class disropt.problems.ConstraintCoupledProblem(objective_function=None, constraints=None, coupling_function=None, **kwargs)[source]

Bases: disropt.problems.problem.Problem

A local part of a constraint-coupled problem.

Parameters
  • objective_function (AbstractFunction, optional) – Local objective function. Defaults to None.

  • constraints (list, optional) – Local constraints. Defaults to None.

  • coupling_function (AbstractFunction, optional) – Local function contributing to coupling constraints. Defaults to None.

objective_function

Objective function to be minimized

Type

Function

constraints

Local constraints

Type

AbstractSet or Constraint

coupling_function

Local function contributing to coupling constraints

Type

Function

set_coupling_function(fn)[source]

Set the coupling constraint function

Parameters

fn (AbstractFunction) – coupling constraint function

Raises

TypeError – input must be a AbstractFunction

ConstraintCoupledMILP

class disropt.problems.ConstraintCoupledMILP(objective_function, coupling_function, constraints=None, integer_vars=None, binary_vars=None, **kwargs)[source]

Bases: disropt.problems.constraint_coupled_problem.ConstraintCoupledProblem, disropt.problems.milp.MixedIntegerLinearProblem