33# Use of this source code is governed by an MIT-style license that can be found
44# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
55
6- _is_variable (v:: MOI.VariableIndex ) = ! _is_parameter (v)
6+ """
7+ _is_parameter(v::MOI.VariableIndex)::Bool
78
9+ Return `true` if `v` encodes a parameter (index above `PARAMETER_INDEX_THRESHOLD`).
10+ """
811function _is_parameter (v:: MOI.VariableIndex )
912 return PARAMETER_INDEX_THRESHOLD < v. value <= PARAMETER_INDEX_THRESHOLD_MAX
1013end
1114
15+ """
16+ _is_variable(v::MOI.VariableIndex)::Bool
17+
18+ Return `true` if `v` is a true decision variable (not a parameter).
19+ """
20+ _is_variable (v:: MOI.VariableIndex ) = ! _is_parameter (v)
21+
22+ """
23+ _has_parameters(f)::Bool
24+
25+ Return `true` if any term in `f` contains a parameter index.
26+ """
1227function _has_parameters (f:: MOI.ScalarAffineFunction{T} ) where {T}
1328 for term in f. terms
1429 if _is_parameter (term. variable)
@@ -67,6 +82,13 @@ function _has_parameters(f::MOI.VectorQuadraticFunction)
6782 return false
6883end
6984
85+ """
86+ _cache_multiplicative_params!(model, f)
87+
88+ Record all parameters that appear in `p*v` (or higher) product terms into
89+ `model.multiplicative_parameters_pv`. This is used to reject dual queries for
90+ parameters whose dual is not well-defined.
91+ """
7092function _cache_multiplicative_params! (
7193 model:: Optimizer{T} ,
7294 f:: ParametricQuadraticFunction{T} ,
@@ -265,6 +287,13 @@ function MOI.get(model::Optimizer, tp::Type{MOI.VariableIndex}, attr::String)
265287 return MOI. get (model. optimizer, tp, attr)
266288end
267289
290+ """
291+ _add_variable(model, inner_vi)
292+
293+ Validate that `inner_vi` is not a parameter index and return it unchanged.
294+ Raises an error if the inner solver accidentally created a variable index in
295+ the parameter range.
296+ """
268297function _add_variable (model:: Optimizer , inner_vi)
269298 if _is_parameter (inner_vi)
270299 error (
@@ -307,6 +336,11 @@ function MOI.supports_add_constrained_variables(
307336 return MOI. supports_add_constrained_variables (model. optimizer, S)
308337end
309338
339+ """
340+ _assert_parameter_is_finite(set::MOI.Parameter)
341+
342+ Throw an `AssertionError` if `set.value` is not finite.
343+ """
310344function _assert_parameter_is_finite (set:: MOI.Parameter{T} ) where {T}
311345 if ! isfinite (set. value)
312346 throw (
@@ -356,6 +390,12 @@ function MOI.add_constrained_variables(
356390 return _add_variable .(model, inner_vis), inner_ci
357391end
358392
393+ """
394+ _add_to_constraint_map!(model, ci)
395+
396+ Register `ci` in `model.constraint_outer_to_inner` (mapping outer to inner
397+ index). Specialized methods also increment the affine or quadratic counter.
398+ """
359399function _add_to_constraint_map! (model:: Optimizer , ci)
360400 model. constraint_outer_to_inner[ci] = ci
361401 return
@@ -472,6 +512,13 @@ function MOI.delete(model::Optimizer, v::MOI.VariableIndex)
472512 return
473513end
474514
515+ """
516+ _delete_variable_index_constraint(model, d, F, S, v)
517+
518+ Remove stale entries from constraint dict `d` after variable `v` is deleted.
519+ Specialized for `VectorOfVariables` (prunes invalidated constraints) and
520+ `VariableIndex` (removes the entry keyed by `v`). The default method is a no-op.
521+ """
475522_delete_variable_index_constraint (model, d, F, S, v) = nothing
476523
477524function _delete_variable_index_constraint (
@@ -843,6 +890,12 @@ function MOI.modify(
843890 return
844891end
845892
893+ """
894+ _add_constraint_direct_and_cache_map!(model, f, set)
895+
896+ Add constraint `(f, set)` directly to the inner optimizer and register it in
897+ `model.constraint_outer_to_inner`. Used for constraints with no parameters.
898+ """
846899function _add_constraint_direct_and_cache_map! (model:: Optimizer , f, set)
847900 ci = MOI. add_constraint (model. optimizer, f, set)
848901 _add_to_constraint_map! (model, ci)
@@ -862,6 +915,13 @@ function MOI.add_constraint(
862915 return _add_constraint_direct_and_cache_map! (model, f, set)
863916end
864917
918+ """
919+ _add_constraint_with_parameters_on_function(model, f, set)
920+
921+ Add a constraint whose function `f` contains at least one parameter.
922+ Constructs the appropriate `Parametric*Function`, caches it, and registers the
923+ outer-to-inner constraint index mapping. Dispatches on `f` type.
924+ """
865925function _add_constraint_with_parameters_on_function (
866926 model:: Optimizer ,
867927 f:: MOI.ScalarAffineFunction{T} ,
@@ -913,6 +973,13 @@ function MOI.add_constraint(
913973 return outer_ci
914974end
915975
976+ """
977+ _add_vi_constraint(model, pf, set)
978+
979+ Add a parametric affine constraint as a variable bound in the inner optimizer
980+ (i.e. `VariableIndex`-in-set form). Used when `ConstraintsInterpretation` allows
981+ converting single-variable constraints with a unit coefficient into bounds.
982+ """
916983function _add_vi_constraint (
917984 model:: Optimizer ,
918985 pf:: ParametricAffineFunction{T} ,
@@ -1026,6 +1093,11 @@ function _add_constraint_with_parameters_on_function(
10261093 return outer_ci
10271094end
10281095
1096+ """
1097+ _is_affine(f::MOI.ScalarQuadraticFunction)::Bool
1098+
1099+ Return `true` if `f` has no quadratic terms (i.e., reduces to an affine function).
1100+ """
10291101_is_affine (f:: MOI.ScalarQuadraticFunction ) = isempty (f. quadratic_terms)
10301102
10311103function MOI. add_constraint (
@@ -1062,6 +1134,11 @@ function MOI.add_constraint(
10621134 return _add_constraint_with_parameters_on_function (model, f, set)
10631135end
10641136
1137+ """
1138+ _is_vector_affine(f::MOI.VectorQuadraticFunction)::Bool
1139+
1140+ Return `true` if `f` has no quadratic terms (i.e., reduces to a vector affine function).
1141+ """
10651142_is_vector_affine (f:: MOI.VectorQuadraticFunction ) = isempty (f. quadratic_terms)
10661143
10671144function _add_constraint_with_parameters_on_function (
@@ -1283,6 +1360,12 @@ function MOI.get(model::Optimizer, attr::MOI.ObjectiveFunction)
12831360 return MOI. get (model. original_objective_cache, attr)
12841361end
12851362
1363+ """
1364+ _empty_objective_function_caches!(model::Optimizer)
1365+
1366+ Clear all cached objective function data and reset `original_objective_cache`.
1367+ Called before setting a new objective to avoid stale cached terms.
1368+ """
12861369function _empty_objective_function_caches! (model:: Optimizer{T} ) where {T}
12871370 model. affine_objective_cache = nothing
12881371 model. quadratic_objective_cache = nothing
0 commit comments