中间-末端的缩减
这里列出的缩减不特定于求解器的类型。 无论您想要目标是二次规划求解器还是锥求解器,都可以应用它们。
在直接在您的代码中使用这些之前,请参阅 我们的免责声明 关于减少API使用。
复数转实数
- class cvxpy.reductions.complex2real.complex2real.Complex2Real(problem=None)[source]
Bases:
Reduction
Lifts complex numbers to a real representation.
- accepts(problem) None [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]
Applies the reduction to a problem and returns an equivalent problem.
- Parameters:
problem (Problem) – The problem to which the reduction will be applied.
- Returns:
Problem or dict – An equivalent problem, encoded either as a Problem or a dict.
InverseData, list or dict – Data needed by the reduction in order to invert this particular application.
CvxAttr转化为约束
- class cvxpy.reductions.cvx_attr2constr.CvxAttr2Constr(problem=None)[source]
Bases:
Reduction
Expand convex variable attributes into constraints.
- accepts(problem) bool [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]
Applies the reduction to a problem and returns an equivalent problem.
- Parameters:
problem (Problem) – The problem to which the reduction will be applied.
- Returns:
Problem or dict – An equivalent problem, encoded either as a Problem or a dict.
InverseData, list or dict – Data needed by the reduction in order to invert this particular application.
Dgp转化为Dcp
- class cvxpy.reductions.dgp2dcp.dgp2dcp.Dgp2Dcp(problem=None)[source]
Bases:
Canonicalization
Reduce DGP problems to DCP problems.
This reduction takes as input a DGP problem and returns an equivalent DCP problem. Because every (generalized) geometric program is a DGP problem, this reduction can be used to convert geometric programs into convex form.
Example
>>> import cvxpy as cp >>> >>> x1 = cp.Variable(pos=True) >>> x2 = cp.Variable(pos=True) >>> x3 = cp.Variable(pos=True) >>> >>> monomial = 3.0 * x_1**0.4 * x_2 ** 0.2 * x_3 ** -1.4 >>> posynomial = monomial + 2.0 * x_1 * x_2 >>> dgp_problem = cp.Problem(cp.Minimize(posynomial), [monomial == 4.0]) >>> >>> dcp2cone = cvxpy.reductions.Dcp2Cone() >>> assert not dcp2cone.accepts(dgp_problem) >>> >>> gp2dcp = cvxpy.reductions.Dgp2Dcp(dgp_problem) >>> dcp_problem = gp2dcp.reduce() >>> >>> assert dcp2cone.accepts(dcp_problem) >>> dcp_problem.solve() >>> >>> dgp_problem.unpack(gp2dcp.retrieve(dcp_problem.solution)) >>> print(dgp_problem.value) >>> print(dgp_problem.variables())
评估参数
- class cvxpy.reductions.eval_params.EvalParams(problem=None)[source]
Bases:
Reduction
Replaces symbolic parameters with their constant values.
- accepts(problem) bool [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
FlipObjective
- class cvxpy.reductions.flip_objective.FlipObjective(problem=None)[source]
Bases:
Reduction
Flip a minimization objective to a maximization and vice versa.
- accepts(problem) bool [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