@@ -389,32 +389,17 @@ end
389389MOI. dimension (s:: MOIEpiPower ) = s. dim
390390JuMP. moi_set (s:: EpiPower , dim:: Int ) = MOIEpiPower (s. p, dim)
391391
392- # region-restricted constraint: wrap the underlying constraint. Carries the On
393- # unresolved because a Bool mask needs the geometry (V) to become pairs, and
394- # build_constraint has no model access; add_constraint resolves it.
392+ # region-restricted constraint: wrap the underlying constraint. On is already
393+ # resolved to (vertex, element) pairs (masks convert eagerly in On(geom, mask)).
395394struct RegionConstraint{C} <: JuMP.AbstractConstraint
396395 con:: C
397- region :: On
396+ pairs :: Vector{Tuple{Int,Int}}
398397end
399398JuMP. jump_function (rc:: RegionConstraint ) = JuMP. jump_function (rc. con)
400399JuMP. moi_set (rc:: RegionConstraint ) = JuMP. moi_set (rc. con)
401400
402- # resolve an On region to (vertex, element) pairs — the package's canonical
403- # node-set format (find_boundary, dirichlet_nodes). A Bool mask is grid-level
404- # sugar for it: mask entry i = v + (e-1)V selects vertex v of element e.
405- function _region_pairs (m:: MGBModel , on:: On )
406- r = on. region
407- r isa Vector{Bool} || return r
408- length (r) == m. nnodes || _argerror (
409- " region mask has length $(length (r)) but the geometry has $(m. nnodes) " *
410- " broken nodes; entry i is vertex v of element e with i = v + (e-1)V, " *
411- " V = $(size (m. geometry. x, 1 )) " )
412- V = size (m. geometry. x, 1 )
413- Tuple{Int,Int}[(mod1 (i, V), cld (i, V)) for i in findall (r)]
414- end
415-
416401JuMP. build_constraint (err:: Function , f, set, on:: On ) =
417- RegionConstraint (JuMP. build_constraint (err, f, set), on)
402+ RegionConstraint (JuMP. build_constraint (err, f, set), on. pairs )
418403
419404# JuMP's macro maps generic scalar comparisons (non-Number rhs) to its
420405# Zeros/Nonnegatives/Nonpositives shortcut sets through VARIADIC
@@ -424,19 +409,19 @@ function JuMP.build_constraint(err::Function, f, set::JuMP.Zeros, on::On)
424409 inner = f isa AbstractVector ?
425410 JuMP. build_constraint (err, f, MOI. Zeros (length (f))) :
426411 JuMP. build_constraint (err, f, MOI. EqualTo (0.0 ))
427- RegionConstraint (inner, on)
412+ RegionConstraint (inner, on. pairs )
428413end
429414function JuMP. build_constraint (err:: Function , f, set:: JuMP.Nonnegatives , on:: On )
430415 inner = f isa AbstractVector ?
431416 JuMP. build_constraint (err, f, MOI. Nonnegatives (length (f))) :
432417 JuMP. build_constraint (err, f, MOI. GreaterThan (0.0 ))
433- RegionConstraint (inner, on)
418+ RegionConstraint (inner, on. pairs )
434419end
435420function JuMP. build_constraint (err:: Function , f, set:: JuMP.Nonpositives , on:: On )
436421 inner = f isa AbstractVector ?
437422 JuMP. build_constraint (err, f, MOI. Nonpositives (length (f))) :
438423 JuMP. build_constraint (err, f, MOI. LessThan (0.0 ))
439- RegionConstraint (inner, on)
424+ RegionConstraint (inner, on. pairs )
440425end
441426# Newer JuMP versions route scalar comparisons with non-Number sides through
442427# internal *Zero marker sets, again variadically; cover them when they exist.
@@ -446,7 +431,7 @@ for (marker, moiset) in ((:GreaterThanZero, :(MOI.GreaterThan(0.0))),
446431 if isdefined (JuMP, marker)
447432 @eval function JuMP. build_constraint (err:: Function , f,
448433 set:: JuMP. $ marker, on:: On )
449- RegionConstraint (JuMP. build_constraint (err, f, $ moiset), on)
434+ RegionConstraint (JuMP. build_constraint (err, f, $ moiset), on. pairs )
450435 end
451436 end
452437end
@@ -553,11 +538,10 @@ function JuMP.add_constraint(m::MGBModel, c::JuMP.VectorConstraint,
553538end
554539function JuMP. add_constraint (m:: MGBModel , rc:: RegionConstraint , name:: String = " " )
555540 c = rc. con
556- pairs = _region_pairs (m, rc. region)
557541 if c isa JuMP. ScalarConstraint
558- _add_scalar (m, JuMP. jump_function (c), JuMP. moi_set (c), pairs, name)
542+ _add_scalar (m, JuMP. jump_function (c), JuMP. moi_set (c), rc . pairs, name)
559543 elseif c isa JuMP. VectorConstraint
560- _add_vector (m, JuMP. jump_function (c), JuMP. moi_set (c), pairs, name)
544+ _add_vector (m, JuMP. jump_function (c), JuMP. moi_set (c), rc . pairs, name)
561545 else
562546 _argerror (" unsupported constraint type $(typeof (c)) with On(...)" )
563547 end
0 commit comments