Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generalize the value getter #27

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ConstraintTrees"
uuid = "5515826b-29c3-47a5-8849-8513ac836620"
authors = ["The developers of ConstraintTrees.jl"]
version = "0.9.2"
version = "0.9.3"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
9 changes: 9 additions & 0 deletions src/value.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ $(TYPEDEF)
Abstract type of all values usable in constraints, including [`LinearValue`](@ref) and [`QuadraticValue`](@ref).
"""
abstract type Value end
stelmo marked this conversation as resolved.
Show resolved Hide resolved

"""
$(TYPEDSIGNATURES)

Returns any `Real`- or [`Value`](@ref)-typed `x`. This is a convenience
overload; typically one enjoys this more when extracting values from
[`Constraint`](@ref)s.
"""
value(x::T) where {T<:Union{Real,Value}} = x
1 change: 1 addition & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ end
s = :a^C.Constraint(x, 5.0) + :b^C.Constraint(x * x - x, (4.0, 6.0))
@test C.value(s.a).idxs == [1]
@test C.value(s.b).idxs == [(0, 2), (2, 2)]
@test C.value(s.a.value) === C.value(s.a)
vars = [C.LinearValue([1], [1.0]), C.LinearValue([2], [1.0])]
@test C.substitute(s.a, vars).bound == s.a.bound
@test C.substitute(s.a, vars).value.idxs == s.a.value.idxs
Expand Down