Reference
The AbstractVariable
interface:
Convex.AbstractVariable
— Typeabstract type AbstractVariable <: AbstractExpr end
An AbstractVariable
should have head
field, an id_hash
field and a size
field to conform to the AbstractExpr
interface, and implement methods (or use the field-access fallbacks) for
_value
,set_value!
: get or set the numeric value of the variable._value
should returnnothing
when no numeric value is set. Note:evaluate
is the user-facing method to access the value ofx
.vexity
,vexity!
: get or set thevexity
of the variable. Thevexity
should beAffineVexity()
unless the variable has beenfix!
'd, in which case it isConstVexity()
.sign
,vartype
, andconstraints
: get theSign
,VarType
, numeric type, and a (possibly empty) vector of constraints which are to be applied to any problem in which the variable is used.
Optionally, also implement sign!
, vartype!
, and add_constraint!
to allow users to modify those values or add a constraint.
Convex._value
— Function_value(x::AbstractVariable)
Raw access to the current value of x
; used internally by Convex.jl.
Convex.set_value!
— Functionset_value!(x::AbstractVariable, v)
Sets the current value of x
to v
.
Convex.constraints
— Functionconstraints(x::AbstractVariable)
Returns the current constraints carried by x
.
Convex.add_constraint!
— Functionadd_constraint!(x::AbstractVariable, C::Constraint)
Adds an constraint to those carried by x
.
Convex.vexity
— Functionvexity(x::AbstractVariable)
Returns the current vexity of x
.
Convex.vexity!
— Functionvexity!(x::AbstractVariable, v::Vexity)
Sets the current vexity of x
to v
. Should only be called by fix!
and free!
.
Base.sign
— Functionsign(x)
Return zero if x==0
and $x/|x|$ otherwise (i.e., ±1 for real x
).
sign(x::AbstractVariable)
Returns the current sign of x
.
Convex.sign!
— Functionsign!(x::AbstractVariable, s::Sign)
Sets the current sign of x
to s
.
Convex.VarType
— TypeVarType
Describe the type of a AbstractVariable
: either continuous (ContVar
), integer-valued (IntVar
), or binary (BinVar
).
Convex.vartype
— Functionvartype(x::AbstractVariable)
Returns the current VarType
of x
.
Convex.vartype!
— Functionvartype!(x::AbstractVariable, vt::VarType)
Sets the current VarType
of x
to vt
.
Functions:
Convex.fix!
— Functionfix!(x::AbstractVariable, v = value(x))
Fixes x
to v
. It is subsequently treated as a constant in future optimization problems. See also free!
.
Convex.free!
— Functionfree!(x::AbstractVariable)
Frees a previously fix!
'd variable x
, to treat it once again as a variable to optimize over.
Convex.evaluate
— Functionevaluate(x::AbstractExpr)
Returns the current value of x
if assigned; errors otherwise.
Convex.solve!
— Functionsolve!(problem::Problem{T}, optimizer::MOI.ModelLike;
check_vexity::Bool = true,
verbose::Bool = true,
warmstart::Bool = false,
silent_solver::Bool = false) where {T}
Solves the problem, populating problem.optval
with the optimal value, as well as the values of the variables (accessed by evaluate
) and constraint duals (accessed by cons.dual
), where applicable.
Optional keyword arguments:
check_vexity
(default:true
): emits a warning if the problem is not DCPverbose
(default:true
): emits a warning if the problem was not solved optimally orwarmstart=true
but is not supported by the solver.warmstart
(default:false
): whether the solver should start the optimization from a previous optimal value (according to the current value of the variables in the problem, which can be set byset_value!
and accessed byevaluate
).silent_solver
: whether the solver should be silent (and not emit output or logs) during the solution process.
Convex.emit_dcp_warnings
— Functionemit_dcp_warnings
Controls whether or not warnings are emitted for when an expression fails to be of disciplined convex form. To turn warnings off, override the method via
Convex.emit_dcp_warnings() = false
This will cause Julia's method invalidation to recompile any functions emitting DCP warnings and remove them. This should be run from top-level (not within a function).