Skip to content

JuMP.value(f, GeneralVariableRef) dispatch - #445

Closed
dnguyen227 wants to merge 1 commit into
infiniteopt:masterfrom
dnguyen227:value_substitution
Closed

dnguyen227 wants to merge 1 commit into
infiniteopt:masterfrom
dnguyen227:value_substitution

Conversation

@dnguyen227

@dnguyen227 dnguyen227 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Adds the dispatch of JuMP.value(.., ::GeneralVariableRef):

JuMP.value(f::Function, vref::GeneralVariableRef) = f(vref)

JuMP's expression evaluator, value(f, expr). JuMP defines that for method for GenericVariableRef but InfiniteOpt had none for GeneralVariableRef, so evaluating an InfiniteOpt expression at a point failed on the first variable:

model = InfiniteModel()
@infinite_parameter(model, t in [0, 1], num_supports = 5)
@variable(model, x, Infinite(t), start = 2.0)
value(v -> start_value(v), exp(x) - 1)
# MethodError: no method matching value(::var"#1#2", ::GeneralVariableRef)

fyi inside of Hull, we do this.

Hull's perspective term needs f(0) of a nonlinear disjunct constraint, which was computed with JuMP.value(v -> 0.0, con.func).

using DisjunctiveProgramming, InfiniteOpt

model = InfiniteGDPModel()
@infinite_parameter(model, t in [0, 1], num_supports = 5)
@variable(model, 0 <= x <= 10, Infinite(t))
@variable(model, Y[1:2], InfiniteLogical(t))

@constraint(model, exp(x) - 1 <= 2, Disjunct(Y[1]))
@constraint(model, x >= 5, Disjunct(Y[2]))
@disjunction(model, Y)

reformulate_model(model, Hull())
# MethodError: no method matching value(::DisjunctiveProgramming.var"#60#61", ::GeneralVariableRef)

Closes #444

@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 28.14%. Comparing base (467c671) to head (205e6e5).

Files with missing lines Patch % Lines
src/results.jl 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (467c671) and HEAD (205e6e5). Click for more details.

HEAD has 5 uploads less than BASE
Flag BASE (467c671) HEAD (205e6e5)
6 1
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #445       +/-   ##
===========================================
- Coverage   99.72%   28.14%   -71.58%     
===========================================
  Files          39       36        -3     
  Lines        6830     6637      -193     
===========================================
- Hits         6811     1868     -4943     
- Misses         19     4769     +4750     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pulsipher

pulsipher commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

The reason why this hasn't been supported is that value(::GeneralNonlinearVariable) may return a scalar, an n-dimensional array or even something else like an interpolation function. I am not sure the PR robustly addresses this.

@dnguyen227 dnguyen227 closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] JuMP.value(f, GeneralVariableRef) behavior

2 participants