From 328010b6aaccd483d35f0b70d58b4a5ef1e516cd Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Thu, 4 Jan 2024 09:41:55 +0100 Subject: [PATCH] internalize a potentially useful variables_for --- src/constraint_tree.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/constraint_tree.jl b/src/constraint_tree.jl index 3106538..dc3e8fa 100644 --- a/src/constraint_tree.jl +++ b/src/constraint_tree.jl @@ -216,6 +216,22 @@ function variables(; keys::AbstractVector{Symbol}, bounds = nothing) ) end +""" +$(TYPEDSIGNATURES) + +Allocate a variable for each item in a constraint tree (or any other kind of +tree) and return a [`ConstraintTree`](@ref) with variables bounded by the +`makebound` function, which converts a given tree element's value into a bound +for the corresponding variable. +""" +function variables_for(makebound, ts::Tree) + var_idx = 0 + map(ts, Constraint) do x + var_idx += 1 + variable(idx = var_idx, bound = makebound(x)) + end +end + # # Transforming the constraint trees #