cvxpy.reductions.dcp2cone 包

在使用这些API之前,请参阅我们的免责声明( our disclaimer )。

子包

子模块

cvxpy.reductions.dcp2cone.cone_matrix_stuffing 模块

Copyright 2013 Steven Diamond

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class cvxpy.reductions.dcp2cone.cone_matrix_stuffing.ConeDims(constr_map)[source]

Bases: object

Summary of cone dimensions present in constraints.

Constraints must be formatted as dictionary that maps from constraint type to a list of constraints of that type.

zero

The dimension of the zero cone.

Type:

int

nonneg

The dimension of the non-negative cone.

Type:

int

exp

The number of 3-dimensional exponential cones.

Type:

int

soc

A list of the second-order cone dimensions.

Type:

list of int

psd

A list of the positive semidefinite cone dimensions, where the dimension of the PSD cone of k by k matrices is k.

Type:

list of int

EQ_DIM = 'f'
EXP_DIM = 'ep'
LEQ_DIM = 'l'
P3D_DIM = 'p3'
PSD_DIM = 's'
SOC_DIM = 'q'
class cvxpy.reductions.dcp2cone.cone_matrix_stuffing.ConeMatrixStuffing(quad_obj: bool = False, canon_backend: str | None = None)[source]

Bases: MatrixStuffing

Construct matrices for linear cone problems.

Linear cone problems are assumed to have a linear objective and cone constraints which may have zero or more arguments, all of which must be affine.

CONSTRAINTS = 'ordered_constraints'
accepts(problem)[source]

States whether the reduction accepts a problem.

Parameters:

problem (Problem) – The problem to check.

Returns:

True if the reduction can be applied, False otherwise.

Return type:

bool

apply(problem)[source]

Returns a stuffed problem.

The returned problem is a minimization problem in which every constraint in the problem has affine arguments that are expressed in the form A @ x + b.

Parameters:

problem (The problem to stuff; the arguments of every constraint) – must be affine

Returns:

  • Problem – The stuffed problem

  • InverseData – Data for solution retrieval

invert(solution, inverse_data)[source]

Retrieves a solution to the original problem

stuffed_objective(problem, extractor)[source]
class cvxpy.reductions.dcp2cone.cone_matrix_stuffing.ParamConeProg(c, x, A, variables, var_id_to_col, constraints, parameters, param_id_to_col, P=None, formatted: bool = False)[source]

Bases: ParamProb

Represents a parameterized cone program

minimize c’x + d + [(1/2)x’Px] subject to cone_constr1(A_1*x + b_1, …)

… cone_constrK(A_i*x + b_i, …)

The constant offsets d and b are the last column of c and A.

apply_param_jac(delc, delA, delb, active_params=None)[source]

Multiplies by Jacobian of parameter mapping.

Assumes delA is sparse.

Returns:

A dictionary param.id -> dparam

apply_parameters(id_to_param_value=None, zero_offset: bool = False, keep_zeros: bool = False, quad_obj: bool = False)[source]

Returns A, b after applying parameters (and reshaping).

Parameters:
  • id_to_param_value – (optional) dict mapping parameter ids to values.

  • zero_offset – (optional) if True, zero out the constant offset in the parameter vector.

  • keep_zeros – (optional) if True, store explicit zeros in A where parameters are affected.

  • quad_obj – (optional) if True, include quadratic objective term.

is_mixed_integer() bool[source]

Is the problem mixed-integer?

split_adjoint(del_vars=None)[source]

Adjoint of split_solution.

split_solution(sltn, active_vars=None)[source]

Splits the solution into individual variables.

cvxpy.reductions.dcp2cone.dcp2cone 模块

Copyright 2013 Steven Diamond, 2017 Akshay Agrawal, 2017 Robin Verschueren

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class cvxpy.reductions.dcp2cone.dcp2cone.Dcp2Cone(problem=None, quad_obj: bool = False)[source]

Bases: Canonicalization

Reduce DCP problems to a conic form.

This reduction takes as input (minimization) DCP problems and converts them into problems with affine or quadratic objectives and conic constraints whose arguments are affine.

accepts(problem)[source]

A problem is accepted if it is a minimization and is DCP.

apply(problem)[source]

Converts a DCP problem to a conic form.

canonicalize_expr(expr, args, affine_above: bool) Tuple[Expression, list][source]

Canonicalize an expression, w.r.t. canonicalized arguments.

Parameters:
  • expr (The expression tree to canonicalize.) –

  • args (The canonicalized arguments of expr.) –

  • affine_above (The path up to the root node is all affine atoms.) –

Return type:

A tuple of the canonicalized expression and generated constraints.

canonicalize_tree(expr, affine_above: bool) Tuple[Expression, list][source]

Recursively canonicalize an Expression.

Parameters:
  • expr (The expression tree to canonicalize.) –

  • affine_above (The path up to the root node is all affine atoms.) –

Return type:

A tuple of the canonicalized expression and generated constraints.

模块内容

Copyright 2013 Steven Diamond

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.