Reference
Values
ConstraintTrees.Value — Typeabstract type ValueAbstract type of all values usable in constraints, including LinearValue and QuadraticValue.
All Values are broadcastable as scalars by default.
ConstraintTrees.preduce — Methodpreduce(op, xs; init, stack_type) -> Any
An alternative of Base.reduce which does a "pairwise" reduction in the shape of a binary merge tree, like in mergesort. In general this is a little more complex, but if the reduced value "grows" with more elements added (such as when adding a lot of LinearValues together), this is able to prevent a complexity explosion by postponing "large" reducing operations as much as possible.
In the specific case with adding lots of LinearValues and QuadraticValues together, this effectively squashes the reduction complexity from something around O(n^2) to O(n) (with a little larger constant factor.
ConstraintTrees.substitute_values — Functionsubstitute_values(x::Value, y::AbstractVector) -> Any
substitute_values(x::Value, y::AbstractVector, _) -> Any
Substutite a value into a Value-typed x. This is a convenience overload for the purpose of having substitute_values to run on both Constraints and Values.
ConstraintTrees.sum — Methodsum(xs; init) -> Any
Alias for preduce that uses + as the operation.
Not as versatile as the sum from Base, but much faster for growing values like LinearValues and QuadraticValues.
ConstraintTrees.value — Methodvalue(x::Union{Value, Real}) -> Union{Value, Real}
Returns any Real- or Value-typed x. This is a convenience overload; typically one enjoys this more when extracting values from Constraints.
Linear and affine values
ConstraintTrees.LinearValue — Typestruct LinearValueT{Float64} <: ValueA shortcut for a LinearValueT over Float64s.
ConstraintTrees.LinearValue — MethodLinearValue(x::Real) -> LinearValueT
Construct a constant-valued LinearValue with a single affine element.
ConstraintTrees.LinearValue — MethodLinearValue(
x::SparseArrays.SparseVector{Float64}
) -> LinearValue
Shortcut for making a LinearValue out of a linear combination defined by the SparseVector.
ConstraintTrees.LinearValueT — Typestruct LinearValueT{T} <: ValueA representation of a "value" in a linear constrained optimization problem. The value is an affine linear combination of several variables, weighted by coefficients of the parameter type T.
LinearValueTs can be combined additively and multiplied by real-number constants. Multiplying two LinearValueTs yields a quadratic form (in a QuadraticValueT).
Fields
idxs::Vector{Int64}: Indexes of the variables used by the value. The indexes must always be sorted in strictly increasing order. The affine element has index 0.
weights::Vector: Coefficients of the variables selected byidxs.
ConstraintTrees.LinearValueT — MethodLinearValueT(x::Real) -> LinearValueT{R} where R<:Real
Construct a constant-valued LinearValueT with a single affine element.
ConstraintTrees.LinearValueT — MethodLinearValueT(
x::SparseArrays.SparseVector{T}
) -> LinearValueT
Generalized constructor for LinearValueTs from sparse vectors.
ConstraintTrees.add_sparse_linear_combination — Methodadd_sparse_linear_combination(
a_idxs::Vector{Int64},
a_weights::Array{T, 1},
b_idxs::Vector{Int64},
b_weights::Array{T, 1}
) -> Tuple{Vector{Int64}, Any}
Helper function for implementing LinearValue-like objects. Given "sparse" representations of linear combinations, it computes a "merged" linear combination of 2 values added together.
Zeroes are not filtered out.
ConstraintTrees.substitute — Methodsubstitute(x::LinearValueT, y) -> Any
Substitute anything vector-like as variable values into a LinearValueT and return the result.
Quadratic values
ConstraintTrees.QuadraticValue — Typestruct QuadraticValueT{Float64} <: ValueA shortcut for a QuadraticValueT over Float64s.
ConstraintTrees.QuadraticValue — MethodQuadraticValue(x::LinearValue) -> QuadraticValue
Construct a QuadraticValue that is equivalent to a given LinearValue.
ConstraintTrees.QuadraticValue — MethodQuadraticValue(x::Real) -> QuadraticValueT
Construct a constant-valued QuadraticValue with a single affine element.
ConstraintTrees.QuadraticValue — MethodQuadraticValue(
x::SparseArrays.SparseMatrixCSC{Float64}
) -> QuadraticValue
Shortcut for making a QuadraticValue out of a square sparse matrix.
ConstraintTrees.QuadraticValueT — Typestruct QuadraticValueT{T} <: ValueA representation of a quadratic form in the constrained optimization problem. The QuadraticValue is an affine quadratic combination (i.e., a multinomial of maximum degree 2) over the variables, weighted by coefficients of the parameter type T.
QuadraticValues can be combined additively and multiplied by real-number constants. The cleanest way to construct a QuadraticValue is to multiply two LinearValues.
Fields
idxs::Vector{Tuple{Int64, Int64}}: Indexes of variable pairs used by the value. The indexes must always be sorted in strictly co-lexicographically increasing order, and the first index must always be less than or equal to the second one. (Speaking in matrix terms, the indexing follows the indexes in an upper triangular matrix by columns.)As an outcome, the second index of the last index pair can be used as the upper bound of all variable indexes.
As with
LinearValueT, index0represents the affine element.
weights::Vector: Coefficient of the variable pairs selected byidxs.
ConstraintTrees.QuadraticValueT — MethodQuadraticValueT(x::LinearValueT) -> QuadraticValueT
Construct a QuadraticValueT that is equivalent to a given LinearValueT.
ConstraintTrees.QuadraticValueT — MethodQuadraticValueT(x::Real) -> QuadraticValueT{R} where R<:Real
Construct a constant-valued QuadraticValueT with a single affine element.
ConstraintTrees.QuadraticValueT — MethodQuadraticValueT(
x::SparseArrays.SparseMatrixCSC{T}
) -> QuadraticValue
Generalized constructor for QuadraticValueT from square sparse matrices.
The matrix is force-symmetrized by calculating x' + x.
ConstraintTrees.add_sparse_quadratic_combination — Methodadd_sparse_quadratic_combination(
a_idxs::Vector{Tuple{Int64, Int64}},
a_weights::Array{T, 1},
b_idxs::Vector{Tuple{Int64, Int64}},
b_weights::Array{T, 1}
) -> Tuple{Vector{Tuple{Int64, Int64}}, Any}
Helper function for implementing QuadraticValue-like objects. Given 2 sparse representations of quadratic combinations, it computes a "merged" one with the values of both added together.
Zeroes are not filtered out.
ConstraintTrees.colex_lt — Methodcolex_lt(, ) -> Any
Internal helper for co-lex ordering of indexes.
ConstraintTrees.multiply_sparse_linear_combination — Methodmultiply_sparse_linear_combination(
a_idxs::Vector{Int64},
a_weights::Array{T, 1},
b_idxs::Vector{Int64},
b_weights::Array{T, 1}
) -> Tuple{Vector{Tuple{Int64, Int64}}, Any}
Helper function for multiplying two LinearValue-like objects to make a QuadraticValue-like object. This computes and merges the product.
Zeroes are not filtered out.
ConstraintTrees.squared — Methodsquared(a::LinearValueT) -> QuadraticValueT
Broadcastable shortcut for multiplying a LinearValueT with itself. Produces a QuadraticValueT.
ConstraintTrees.substitute — Methodsubstitute(x::QuadraticValueT, y) -> Any
Substitute anything vector-like as variable values into the QuadraticValueT and return the result.
Constraints
Bounds
ConstraintTrees.MaybeBound — TypeShortcut for all possible Bounds including the "empty" bound that does not constraint anything (represented by nothing).
ConstraintTrees.Between — Typemutable struct BetweenT{Float64} <: BoundShortcut for a Float64-typed interval bound implemented by BetweenT.
ConstraintTrees.Between — MethodBetween(x::Real, y::Real) -> BetweenT
Construct a Between bound. Additionally, this checks the order of the values and puts them into a correct order.
ConstraintTrees.BetweenT — Typemutable struct BetweenT{T} <: BoundRepresentation of an "interval" bound; consisting of lower and upper bound value.
Fields
lower::Any: Lower boundupper::Any: Upper bound
ConstraintTrees.Bound — Typeabstract type BoundAbstract type of all bounds usable in constraints, including Between and EqualTo.
All Bounds are broadcastable as scalars by default.
ConstraintTrees.EqualTo — Typemutable struct EqualToT{Float64} <: BoundShortcut for a Float64-typed equality bound implemented by EqualToT.
ConstraintTrees.EqualTo — MethodEqualTo(x::Real) -> EqualToT
Construct an EqualTo bound.
ConstraintTrees.EqualToT — Typemutable struct EqualToT{T} <: BoundRepresentation of an "equality" bound, which contains the single "equal to this" value.
Fields
equal_to::Any: Equality bound value
Base.length — Methodlength(x::Bound) -> Int64
Deprecation warning: This is kept for backwards compatibility only, and will be removed in a future release.
Constrained values
ConstraintTrees.Constraint — Typemutable struct ConstraintA representation of a single constraint that may limit the given value by a specific Bound.
Constraints without a bound (nothing in the bound field) are possible; these have no impact on the optimization problem but the associated value becomes easily accessible for inspection and building other constraints.
Fields
value::Value: A value (typically aLinearValueor aQuadraticValue) that describes what the constraint constraints.bound::Union{Nothing, Bound}: A bound that thevaluemust satisfy. Should be a subtype ofMaybeBound: Eithernothingif there's no bound, or e.g.EqualToT,BetweenTor similar structs.
ConstraintTrees.bound — Methodbound(x::Constraint) -> Union{Nothing, Bound}
Simple accessor for getting out the bound from the constraint that can be used for broadcasting (as opposed to the dot-field access).
ConstraintTrees.substitute — Methodsubstitute(x::Constraint, y) -> Constraint
Substitute anything vector-like as variables into the constraint's value, producing a constraint with the new value.
ConstraintTrees.substitute_values — Functionsubstitute_values(x::Constraint, y::AbstractVector) -> Any
substitute_values(
x::Constraint,
y::AbstractVector,
_
) -> Any
Overload of substitute_values for a single constraint.
ConstraintTrees.value — Methodvalue(x::Constraint) -> Value
Simple accessor for getting out the value from the constraint that can be used for broadcasting (as opposed to the dot-field access).
Labeled trees
ConstraintTrees.OptionalTree — TypeHelper type for implementation of merge-related functions.
ConstraintTrees.Tree — Typestruct Tree{X}A base "labeled tree" structure. Supports many interesting operations such as merging.
ConstraintTrees.deflate — Methoddeflate(f, x::Tree{T}) -> Any
deflate(f, x::Tree{T}, ::Type{U}) -> Any
Extract all elements of a Tree in order, and return them in a vector as transformed by f. If the order is not changed, one can re-insert a vector of modified elements into the same-shaped tree using reinflate.
ConstraintTrees.elems — Methodelems(
x::Tree
) -> DataStructures.SortedDict{Symbol, Union{Tree{X}, X}} where X
Get the elements dictionary out of the Tree. This is useful for getting an iterable container for working with many items at once.
Also, because of the overload of getproperty for Tree, this serves as a simpler way to get the elements without an explicit use of getfield.
ConstraintTrees.filter — Methodfilter(f, x::Tree{T}) -> Any
Filter all branches and leaves in a tree, leaving only the ones where f returns true.
Note that the branches are passed to f as well. Use filter_leaves to only work with the leaf values.
ConstraintTrees.filter_leaves — Methodfilter_leaves(f, x::Tree{T}) -> Any
Like filter but the filtering predicate function f only receives the leaf values (i.e., no intermediate sub-trees).
In turn, the result will retain the whole subtree structure (even if empty).
ConstraintTrees.ideflate — Methodideflate(f, x::Tree{T}) -> Any
ideflate(f, x::Tree{T}, ::Type{U}) -> Any
Like deflate, but the function f also receives the full tree path in the first argument.
ConstraintTrees.ifilter — Methodifilter(f, x::Tree{T}) -> Any
Like filter but the filtering predicate function also receives the "path" in the tree.
ConstraintTrees.ifilter_leaves — Methodifilter_leaves(f, x::Tree{T}) -> Any
Combination of ifilter and filter_leaves.
ConstraintTrees.imap — Methodimap(f, x) -> Any
imap(f, x, ::Type{T}) -> Any
Like map, but keeping the "index" path and giving it to the function as the first parameter. The "path" in the tree is reported as a tuple of symbols.
ConstraintTrees.imapreduce — Methodimapreduce(f, op, x; init) -> Any
Like mapreduce but reporting the "tree directory path" where the reduced elements occur, like with imap. (Single elements from different directory paths are not reduced together.)
ConstraintTrees.imerge — Methodimerge(f, x, y) -> Any
imerge(f, x, y, ::Type{T}) -> Any
ConstraintTrees.ireduce — Methodireduce(op, x; init) -> Any
Indexed version of reduce (internally uses imapreduce).
ConstraintTrees.itraverse — MethodConstraintTrees.izip — Methodizip(f, x, y) -> Any
izip(f, x, y, ::Type{T}) -> Any
ConstraintTrees.map — Methodmap(f, x) -> Any
map(f, x, ::Type{T}) -> Any
Run a function over everything in the tree. The resulting tree will contain elements of type specified by the 3rd argument. (This needs to be specified explicitly, because the typesystem generally cannot guess the universal type correctly.)
Note this is a specialized function specific for Trees that behaves differently from Base.map.
ConstraintTrees.mapreduce — Methodmapreduce(f, op, x; init) -> Any
Reduce all items in a Tree. As with Base.reduce, the reduction order is not guaranteed, and the initial value may be used any number of times.
Note this is a specialized function specific for Trees that behaves differently from Base.mapreduce.
ConstraintTrees.merge — Methodmerge(f, x, y) -> Any
merge(f, x, y, ::Type{T}) -> Any
Run a function over the values in the merge of all paths in the trees (currently there is support for 2 and 3 trees). This is an "outer join" equivalent of zip. Missing elements are replaced by missing in the function call parameters, and the function may return missing to omit elements.
Note this is a specialized function specific for Trees that behaves differently from Base.merge.
ConstraintTrees.optional_tree_get — Methodoptional_tree_get(_::Missing, _) -> Missing
Get a key from a tree that is possibly missing.
ConstraintTrees.optional_tree_keys — Methodoptional_tree_keys(
_::Missing
) -> DataStructures.SortedSet{Any, Base.Order.ForwardOrdering}
Get a sorted set of keys from a tree that is possibly missing.
ConstraintTrees.reduce — Methodreduce(op, x; init) -> Any
Like mapreduce but the mapped function is identity.
To avoid much type suffering, the operation should ideally preserve the type of its arguments. If you need to change the type, you likely want to use mapreduce.
Note this is a specialized function specific for Trees that behaves differently from Base.reduce.
ConstraintTrees.reinflate — Methodreinflate(x::Tree, elems::Array{T, 1}) -> Any
Insert a vector of elements into the "values" of a Tree. The order of elements in the input vector is given by deflate.
ConstraintTrees.traverse — Methodtraverse(f, x) -> Any
Like map, but discards the results, thus relying only on the side effects of f.
Technically the name should be for, but that's a Julia keyword.
ConstraintTrees.zip — Methodzip(f, x, y) -> Any
zip(f, x, y, ::Type{T}) -> Any
Run a function over the values in the intersection of paths in several trees (currently there is support for 2 and 3 trees). This is an "inner join" – all extra elements are ignored. "Outer join" can be done via merge.
As with map, the inner type of the resulting tree must be specified by the last parameter..
Note this is a specialized function specific for Trees that behaves differently from Base.zip.
Constraint trees
ConstraintTrees.ConstraintTreeElem — TypeA shortcut for the type of the values in ConstraintTree.
ConstraintTrees.ConstraintTree — Typestruct Tree{Constraint}A hierarchical tree of many constraints that together describe a constrained system. The tree may recursively contain other trees in a directory-like structure, which contain Constraints as leaves.
Members of the constraint tree are accessible via the record dot syntax as properties; e.g. a constraint labeled with :abc in a constraint tree t may be accessed as t.abc and as t[:abc], and can be found while iterating through elems(t).
Constructing the constraint trees
Use operator ^ to put a name on a constraint to convert it into a single element ConstraintTree:
x = :my_constraint ^ Constraint(LinearValue(...), 1.0)
dir = :my_constraint_dir ^ x
dir.my_constraint_dir.my_constraint.bound # returns 1.0Use operator * to glue two constraint trees together while sharing the variable indexes specified by the contained LinearValues and QuadraticValues.
my_constraints = :some_constraints ^ Constraint(...) * :more_constraints ^ Constraint(...)Use operator + to glue two constraint trees together without sharing of any variables. The operation will renumber the variables in the trees so that the sets of variable indexes used by either tree are completely disjunct, and then glue the trees together as with *:
two_independent_systems = my_system + other_systemVariable sharing limitations
Because of the renumbering, you can not easily use constraints and values from the values before the addition in the constraint tree that is the result of the addition. There is no check against that – the resulting ConstraintTree will be valid, but will probably describe a different optimization problem than you intended.
As a rule of thumb, avoid necessary parentheses in expressions that work with the constraint trees: While t1 * t2 + t3 might work just as intended, t1 * (t2 + t3) is almost certainly wrong because the variables in t1 that are supposed to connect to variables in either of t2 and t3 will not connect properly because of renumbering of both t2 and t3. If you need to construct a tree like that, do the addition first, and construct the t1 after that, based on the result of the addition.
ConstraintTrees.collect_variables! — Methodcollect_variables!(x::Constraint, out)
Push all variable indexes found in x to the out container.
(The container needs to support the standard push!.)
ConstraintTrees.collect_variables! — Methodcollect_variables!(out::Function, x) -> Any
Overload of collect_variables! that calls a given function with all variable indexes found in x.
ConstraintTrees.drop_zeros — Methoddrop_zeros(x::Tree{T}) -> ConstraintTree
Remove variable references from all Values in the given object (usually a ConstraintTree) where the variable weight is exactly zero.
ConstraintTrees.incr_var_idxs — FunctionOld name for increase_variable_indexes.
Deprecation warning: This will be removed in a future release.
ConstraintTrees.increase_variable_indexes — Methodincrease_variable_indexes(x, incr::Int64) -> Any
Offset all variable indexes in a structure x by the given increment.
Internally, this uses renumber_variables.
Extensibility note
If you extend the functionality of ConstraintTrees by overloading increase_variable_indexes, consider instead providing the overload for renumber_variables which grants more functionality, mainly variable pruning.
ConstraintTrees.prune_variables — Methodprune_variables(x) -> Any
Prune the unused variable indexes from an object x (such as a ConstraintTree).
This first runs collect_variables! to determine the actual used variables, then calls renumber_variables to create a renumbered object.
ConstraintTrees.renumber_variables — Methodrenumber_variables(mapping::Function, x) -> Any
An overload of renumber_variables that allows mapping to be a single-parameter Function.
ConstraintTrees.renumber_variables — Methodrenumber_variables(x::Tree{T}, mapping) -> ConstraintTree
Renumber all variables in an object (such as ConstraintTree). The new variable indexes are taken from the mapping parameter at the index of the old variable's index.
The mapping is assumed to be an array-like object (i.e., it must support getindex, which is used to retrieve the new index for each original variable index).
renumber_variables does not run any consistency checks on the result. The mapping must therefore be monotonically increasing, and the zero index must map to itself, otherwise invalid Values will be produced.
ConstraintTrees.substitute — Methodsubstitute(x::ConstraintTree, y::AbstractVector) -> Any
Substitute variable values from y into the constraint tree's constraint's values, getting a tree with modified constraints.
In a typical application, this can be used together with prune_variables to fix a subset of variables to known values and effectively remove them from the problem.
Cf. substitute_values, which creates a tree of "plain" values with no constraints.
ConstraintTrees.substitute_values — Methodsubstitute_values(x::Tree, y::AbstractVector) -> Any
substitute_values(
x::Tree,
y::AbstractVector,
::Type{T}
) -> Any
Substitute variable values from y into the constraint tree's constraint's values, getting a tree of "solved" constraint values for the given variable assignment.
The third argument forces the output type (it is forwarded to map). The type gets defaulted from eltype(y).
To preserve the constraints in the tree, use substitute.
ConstraintTrees.var_count — FunctionOld name for variable_count.
Deprecation warning: This will be removed in a future release.
ConstraintTrees.variable — Methodvariable(; ...) -> Constraint
variable(weight; bound, idx) -> Constraint
Allocate a single unnamed variable, returning a Constraint with an optionally specified bound.
ConstraintTrees.variable_count — Methodvariable_count(x::ConstraintTree) -> Int64
Find the expected count of variables in a ConstraintTree.
ConstraintTrees.variable_count — Methodvariable_count(x::Constraint) -> Int64
Find the expected count of variables in a Constraint.
ConstraintTrees.variable_count — Methodvariable_count(x::LinearValueT) -> Int64
Find the expected count of variables in a LinearValue. (This is a O(1) operation, relying on the ordering of the indexes.)
ConstraintTrees.variable_count — Methodvariable_count(x::QuadraticValueT) -> Int64
Find the expected count of variables in a QuadraticValue. (This is a O(1) operation, relying on the co-lexicographical ordering of indexes.)
ConstraintTrees.variables — Functionvariables(; ...)
variables(weight; keys, bounds)
Make a trivial constraint system that creates variables with indexes in range 1:length(keys) named in order as given by keys.
The individual bounds should be subtypes of Bound, or nothing (which is the default). The bounds are broadcasted; to pass a single bound for all variables, one can use e.g. bounds = EqualTo(0).
ConstraintTrees.variables_for — Functionvariables_for(makebound, ts::Tree) -> Any
variables_for(makebound, ts::Tree, weight) -> Any
Allocate a variable for each item in a constraint tree (or any other kind of tree) and return a ConstraintTree with variables bounded by the makebound function, which converts a given tree element's value into a bound for the corresponding variable.
ConstraintTrees.variables_ifor — Functionvariables_ifor(makebound, ts::Tree) -> Any
variables_ifor(makebound, ts::Tree, weight) -> Any
Like variables_for but the makebound function also receives a path to the variable, as with imap.
Serialization
ConstraintTrees.SerializationLabel — Typestruct SerializationLabel{L}Helper type for doing overloads for serialization and deserialization.
ConstraintTrees.deserialize — Methoddeserialize(_::Type{Between}, x::Vector) -> BetweenT
Deserialize a vector of 2 values into a Between bound.
ConstraintTrees.deserialize — Methoddeserialize(_::Type{Constraint}, x::Dict) -> Constraint
Reconstruct a Constraint from a dictionary as produced by serialize.
Types of values and bounds in constraints are specified explicitly in the serialized representation; the mapping is specified by overloads of deserialize_bound and deserialize_value.
ConstraintTrees.deserialize — Methoddeserialize(_::Type{EqualTo}, x::Float64) -> EqualTo
Deserialize a single value into an EqualTo bound.
ConstraintTrees.deserialize — Methoddeserialize(_::Type{LinearValue}, x::Dict) -> LinearValue
Deserialize a dictionary with keys idxs and weights into a LinearValue.
ConstraintTrees.deserialize — Methoddeserialize(
_::Type{QuadraticValue},
x::Dict
) -> QuadraticValue
Deserialize a dictionary with keys idxs and weights into a LinearValue. idxs must contain vectors of length 2 with the double indices.
ConstraintTrees.deserialize — Methoddeserialize(_::Type{Tree{T}}, x::Dict) -> Tree
Reconstruct a Tree from a dictionary "description" as produced by serialize.
The trees are labeled with explicit key "tree", which allows the implementation to recognize the subtrees from leaf elements.
ConstraintTrees.deserialize_bound — Methoddeserialize_bound(
_::Type{ConstraintTrees.SerializationLabel{:between}},
x
) -> BetweenT
Deserialize a Bound into a type described by the label.
This should be overloaded for custom bound types that are supposed to get serialized.
ConstraintTrees.deserialize_value — Methoddeserialize_value(
_::Type{ConstraintTrees.SerializationLabel{:linear}},
x
) -> LinearValue
Deserialize a Value into a type described by the label.
This should be overloaded for custom value types that are supposed to get serialized.
ConstraintTrees.serialize — Methodserialize(x::Between) -> Vector{Float64}
Serialize a Between bound into a vector of the two interval endpoints.
ConstraintTrees.serialize — Methodserialize(
x::Constraint
) -> Union{Dict{String, Any}, Dict{String, String}}
Convert a Constraint to basic Julia types.
The types of values and bounds are named explicitly to allow precise deserialization without guessing; the values are found from overloads of serialize_value_label and serialize_bound_label. If the bound is not present, the corresponding data is completely omitted and no label is added.
ConstraintTrees.serialize — Methodserialize(x::EqualTo) -> Float64
Serialize an EqualTo bound into a number.
ConstraintTrees.serialize — Methodserialize(
x::LinearValue
) -> Union{Dict{String, Vector}, Dict{String, Vector{Int64}}}
Serialize a LinearValue into a dictionary with coefficient indices and weights.
ConstraintTrees.serialize — Methodserialize(
x::QuadraticValue
) -> Union{Dict{String, Vector}, Dict{String, Vector{Vector{Int64}}}}
Serialize a QuadraticValue into a dictionary with coefficient index tuples and weights.
ConstraintTrees.serialize — Methodserialize(
x::Tree
) -> Dict{String, V} where V<:(Dict{K, V} where {V, K})
Convert a Tree into a "simple" representation that only consists of basic Julia types.
In particular, all trees labeled as dictionaries with a single key tree that indexes a dictionary of all keyed entries.
ConstraintTrees.serialize_bound_label — Methodserialize_bound_label(_::Type{Between}) -> Symbol
Produce a type label for serializing the given bound type.
Overloads should correspond to deserialize_bound.
ConstraintTrees.serialize_value_label — Methodserialize_value_label(_::Type{LinearValue}) -> Symbol
Produce a type label for serializing the given value type.
Overloads should correspond to deserialize_value.
Pretty-printing
ConstraintTrees.default_pretty_var — Methoddefault_pretty_var(i::Int64) -> String
Internal helper for prettyprinting variable contributions; default value of format_variable keyword argument in pretty.
If there should be multiplication operators, the implementation format_variable is supposed to prefix the variable contribution. This should not print anything for the zero "affine" variable.
ConstraintTrees.pretty — Methodpretty(x; kwargs...) -> Any
Pretty-print a given object via other overloads of pretty, defaulting the output stream to standard output.
ConstraintTrees.pretty — Methodpretty(io::IO, x; kwargs...) -> Union{Nothing, Bool}
Default implementation of pretty defaults to Base.show.
ConstraintTrees.pretty — Methodpretty(
io::IO,
x::BetweenT;
in_interval_sign,
format_bound_value,
kwargs...
)
Pretty-print an interval bound into the io.
ConstraintTrees.pretty — Methodpretty(io::IO, x::Bound; default_bound_separator, kwargs...)
Default pretty-printing of a Bound. Overloads that print bounds should expect that they are ran right after printing of the Values, on the same line.
ConstraintTrees.pretty — Methodpretty(
io::IO,
x::Constraint;
kwargs...
) -> Union{Nothing, Bool}
Pretty-print a constraint into the io.
ConstraintTrees.pretty — Methodpretty(
io::IO,
x::EqualToT;
equal_to_sign,
format_bound_value,
kwargs...
)
Pretty-print an equality bound into the io.
ConstraintTrees.pretty — Methodpretty(
io::IO,
x::LinearValueT;
format_coefficient,
format_variable,
plus_sign,
zero_value,
kwargs...
)
Pretty-print a linear value into the io.
ConstraintTrees.pretty — Methodpretty(
io::IO,
x::QuadraticValueT;
format_coefficient,
format_variable,
plus_sign,
zero_value,
kwargs...
)
Pretty-print a quadratic value into the io.
ConstraintTrees.pretty — Methodpretty(io::IO, x::Tree; kwargs...)
Pretty-print a nested tree into the io. This is the only overload of pretty that is allowed to break lines.
The printing assumes a Unicode-capable stdout by default; the formatting can be customized via keyword arguments (see other overloads of pretty and pretty_tree).
ConstraintTrees.pretty_tree — Methodpretty_tree(
io::IO,
x,
ctxt0::Tuple,
pfx0::String,
pfx::String;
leaf_separator,
kwargs...
)
Overload of pretty_tree for anything except Trees – this utilizes pretty to finish a line with the "contents" of the tree leaf.
ConstraintTrees.pretty_tree — Methodpretty_tree(
io::IO,
x::Tree,
ctxt0::Tuple,
pfx0::String,
pfx::String;
format_label,
singleton_branch,
first_branch,
middle_branch,
last_branch,
child_first_indent,
child_indent,
lastchild_first_indent,
lastchild_indent,
kwargs...
)
Internal helper for recursive prettyprinting of tree structures. Adds a relatively legible Unicode scaffolding to highlight the tree structure. The scaffolding can be customized via keyword arguments (which are passed here from pretty).
Specifically, format_label argument can be used convert a tuple with the "path" in the tree (as with e.g. imap) into a suitable tree branch label.