File tree 3 files changed +35
-1
lines changed 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,6 @@ function number_of_variables(map::Map)
174
174
num += length_of_vector_of_variables (map, MOI. VariableIndex (- i))
175
175
end
176
176
end
177
- count (bridge -> bridge != = nothing , map. bridges)
178
177
end
179
178
return num
180
179
end
Original file line number Diff line number Diff line change @@ -760,6 +760,11 @@ function _get_all_including_bridged(
760
760
ret = MOI. VariableIndex[]
761
761
for inner_variable in MOI. get (b. model, attr)
762
762
outer_variable = get (inner_to_outer, inner_variable, missing )
763
+ # If there is a chain of variable bridges, the `outer_variable` may need
764
+ # to be mapped.
765
+ while haskey (inner_to_outer, outer_variable)
766
+ outer_variable = inner_to_outer[outer_variable]
767
+ end
763
768
if ismissing (outer_variable)
764
769
# inner_variable does not exist in inner_to_outer, which means that
765
770
# it is not bridged. Pass through unchanged.
Original file line number Diff line number Diff line change @@ -1422,6 +1422,36 @@ function test_fallback_delete_objective_bridge()
1422
1422
return
1423
1423
end
1424
1424
1425
+ struct Model2714 <: MOI.ModelLike
1426
+ dimensions:: Vector{Int}
1427
+ Model2714 () = new (Int[])
1428
+ end
1429
+
1430
+ MOI. is_empty (model:: Model2714 ) = isempty (model. dimensions)
1431
+
1432
+ function MOI. supports_add_constrained_variables (
1433
+ :: Model2714 ,
1434
+ :: Type{MOI.Nonnegatives} ,
1435
+ )
1436
+ return true
1437
+ end
1438
+
1439
+ function MOI. add_constrained_variables (model:: Model2714 , set:: MOI.Nonnegatives )
1440
+ n = MOI. dimension (set)
1441
+ x = MOI. VariableIndex (sum (model. dimensions) .+ (1 : n))
1442
+ push! (model. dimensions, n)
1443
+ F, S = MOI. VectorOfVariables, MOI. Nonnegatives
1444
+ return x, MOI. ConstraintIndex {F,S} (length (model. dimensions))
1445
+ end
1446
+
1447
+ function test_issue_2714 ()
1448
+ model = MOI. instantiate (Model2714; with_bridge_type = Float64)
1449
+ t, _ = MOI. add_constrained_variable (model, MOI. LessThan (10.0 ))
1450
+ @test MOI. get (model, MOI. NumberOfVariables ()) == 1
1451
+ @test MOI. get (model, MOI. ListOfVariableIndices ()) == [t]
1452
+ return
1453
+ end
1454
+
1425
1455
end # module
1426
1456
1427
1457
TestBridgeOptimizer. runtests ()
You can’t perform that action at this time.
0 commit comments