/
lazy_bridge_optimizer.jl
1153 lines (1102 loc) · 71.3 KB
/
lazy_bridge_optimizer.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Test
using MathOptInterface
const MOI = MathOptInterface
const MOIT = MathOptInterface.Test
const MOIU = MathOptInterface.Utilities
const MOIB = MathOptInterface.Bridges
@testset "Add/remove/has bridges" begin
T = Int
model = MOIU.Model{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
for BT in [MOIB.Variable.VectorizeBridge{T},
MOIB.Constraint.VectorizeBridge{T},
MOIB.Objective.FunctionizeBridge{T},
MOIB.Constraint.ScalarFunctionizeBridge{T},
MOIB.Variable.FreeBridge{T}]
@test !MOIB.has_bridge(bridged, BT)
MOIB.add_bridge(bridged, BT)
@test MOIB.has_bridge(bridged, BT)
if BT != MOIB.Variable.FreeBridge{T}
@test length(MOIB._bridge_types(bridged, BT)) == 1
end
MOIB.add_bridge(bridged, BT)
@test MOIB.has_bridge(bridged, BT)
if BT != MOIB.Variable.FreeBridge{T}
@test length(MOIB._bridge_types(bridged, BT)) == 1
end
MOIB.remove_bridge(bridged, BT)
@test !MOIB.has_bridge(bridged, BT)
@test isempty(MOIB._bridge_types(bridged, BT))
err = ErrorException("Cannot remove bridge `$BT` as it was never added or was already removed.")
@test_throws err MOIB.remove_bridge(bridged, BT)
end
end
include("utilities.jl")
_functionize_error(b, bridge_type, func, name) = ErrorException(
"Need to apply a `$bridge_type` to a `$func` $name because the" *
" variable is bridged but $name bridges are not supported by" *
" `$(typeof(b))`."
)
_lazy_functionize_error(bridge_type, func, name) = ErrorException(
"Need to apply a `$bridge_type` to a `$func` $name because the variable is" *
" bridged but no such $name bridge type was added. Add one" *
" with `add_bridge`."
)
MOIU.@model(StandardLPModel,
(), (MOI.EqualTo, MOIT.UnknownScalarSet), (MOI.Nonnegatives,), (),
(), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), ())
MOI.supports_constraint(::StandardLPModel{T}, ::Type{MOI.SingleVariable}, ::Type{MOI.GreaterThan{T}}) where {T} = false
MOI.supports_constraint(::StandardLPModel{T}, ::Type{MOI.SingleVariable}, ::Type{MOI.LessThan{T}}) where {T} = false
MOI.supports_constraint(::StandardLPModel{T}, ::Type{MOI.SingleVariable}, ::Type{MOI.EqualTo{T}}) where {T} = false
MOI.supports_constraint(::StandardLPModel, ::Type{MOI.VectorOfVariables}, ::Type{MOI.Reals}) = false
MOI.supports(::StandardLPModel{T}, ::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}}) where {T} = false
MOI.supports(::StandardLPModel, ::MOI.ObjectiveFunction{MOI.SingleVariable}) = false
@testset "Bridged variable in `SingleVariable` constraint with $S" for T in [Float64, Int], S in [MOIT.UnknownScalarSet{T}]
set = S(one(T))
@testset "No constraint bridge" begin
model = StandardLPModel{T}()
bridged = MOIB.Variable.Vectorize{T}(model)
x, cx = MOI.add_constrained_variable(bridged, MOI.GreaterThan(one(T)))
fx = MOI.SingleVariable(x)
err = _functionize_error(bridged, MOIB.Constraint.ScalarFunctionizeBridge, "SingleVariable", "constraint")
@test_throws err MOI.add_constraint(bridged, fx, set)
@test_throws err MOI.add_constraints(bridged, [fx], [set])
end
@testset "LazyBridgeOptimizer" begin
function _bridged()
model = StandardLPModel{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
x, cx = MOI.add_constrained_variable(bridged, MOI.GreaterThan(one(T)))
fx = MOI.SingleVariable(x)
return model, bridged, fx
end
@testset "without `Constraint.ScalarFunctionizeBridge`" begin
_, bridged, fx = _bridged()
err = _lazy_functionize_error(MOIB.Constraint.ScalarFunctionizeBridge, "SingleVariable", "constraint")
@test_throws err MOI.add_constraint(bridged, fx, set)
@test_throws err MOI.add_constraints(bridged, [fx], [set])
end
@testset "with `Constraint.ScalarFunctionizeBridge`" begin
for i in 1:2
model, bridged, fx = _bridged()
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarFunctionizeBridge{T})
if i == 1
cx = MOI.add_constraint(bridged, fx, set)
else
cx = MOI.add_constraints(bridged, [fx], [set])[1]
end
@test MOI.get(bridged, MOI.ConstraintFunction(), cx) == fx
@test MOI.get(bridged, MOI.ConstraintSet(), cx) == set
a = MOI.get(model, MOI.ListOfVariableIndices())[1]
fa = MOI.SingleVariable(a)
ca = MOI.get(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{T}, S}())[1]
@test MOI.get(model, MOI.ConstraintFunction(), ca) ≈ convert(MOI.ScalarAffineFunction{T}, fa)
@test MOI.get(model, MOI.ConstraintSet(), ca) == MOIU.shift_constant(set, -one(T))
end
end
end
end
@testset "Bridged variable in `VectorOfVariables` constraint with $T" for T in [Float64, Int]
set = MOI.Zeros(1)
@testset "No constraint bridge" begin
model = StandardLPModel{T}()
bridged = MOIB.Variable.Vectorize{T}(model)
x, cx = MOI.add_constrained_variable(bridged, MOI.GreaterThan(one(T)))
fx = MOI.VectorOfVariables([x])
err = _functionize_error(bridged, MOIB.Constraint.VectorFunctionizeBridge, "VectorOfVariables", "constraint")
@test_throws err MOI.add_constraint(bridged, fx, set)
@test_throws err MOI.add_constraints(bridged, [fx], [set])
end
@testset "LazyBridgeOptimizer" begin
function _bridged()
model = StandardLPModel{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarizeBridge{T})
x, cx = MOI.add_constrained_variable(bridged, MOI.GreaterThan(one(T)))
fx = MOI.VectorOfVariables([x])
return model, bridged, fx
end
@testset "without `Constraint.ScalarFunctionizeBridge`" begin
_, bridged, fx = _bridged()
err = _lazy_functionize_error(MOIB.Constraint.VectorFunctionizeBridge, "VectorOfVariables", "constraint")
@test_throws err MOI.add_constraint(bridged, fx, set)
@test_throws err MOI.add_constraints(bridged, [fx], [set])
end
@testset "with `Constraint.ScalarFunctionizeBridge`" begin
for i in 1:2
model, bridged, fx = _bridged()
MOIB.add_bridge(bridged, MOIB.Constraint.VectorFunctionizeBridge{T})
if i == 1
cx = MOI.add_constraint(bridged, fx, set)
else
cx = MOI.add_constraints(bridged, [fx], [set])[1]
end
@test MOI.get(bridged, MOI.ConstraintFunction(), cx) == fx
@test MOI.get(bridged, MOI.ConstraintSet(), cx) == set
a = MOI.get(model, MOI.ListOfVariableIndices())[1]
fa = MOI.SingleVariable(a)
ca = MOI.get(model, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}}())[1]
@test MOI.get(model, MOI.ConstraintFunction(), ca) ≈ convert(MOI.ScalarAffineFunction{T}, fa)
@test MOI.get(model, MOI.ConstraintSet(), ca) == MOI.EqualTo(-one(T))
end
end
end
end
@testset "Bridged variable in `SingleVariable` objective function with $T" for T in [Float64, Int]
@testset "No objective bridge" begin
model = StandardLPModel{T}()
bridged = MOIB.Variable.Vectorize{T}(model)
x, cx = MOI.add_constrained_variable(bridged, MOI.GreaterThan(one(T)))
fx = MOI.SingleVariable(x)
err = _functionize_error(bridged, MOIB.Objective.FunctionizeBridge, "SingleVariable", "objective")
@test_throws err MOI.set(bridged, MOI.ObjectiveFunction{typeof(fx)}(), fx)
end
@testset "LazyBridgeOptimizer" begin
model = StandardLPModel{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
x, cx = MOI.add_constrained_variable(bridged, MOI.GreaterThan(one(T)))
fx = MOI.SingleVariable(x)
@testset "without `Objective.FunctionizeBridge`" begin
err = _lazy_functionize_error(MOIB.Objective.FunctionizeBridge, "SingleVariable", "objective")
@test_throws err MOI.set(bridged, MOI.ObjectiveFunction{typeof(fx)}(), fx)
end
@testset "with `Objective.FunctionizeBridge`" begin
MOIB.add_bridge(bridged, MOIB.Objective.FunctionizeBridge{T})
MOI.set(bridged, MOI.ObjectiveFunction{typeof(fx)}(), fx)
@test MOI.get(bridged, MOI.ObjectiveFunctionType()) == MOI.SingleVariable
@test MOI.get(bridged, MOI.ObjectiveFunction{MOI.SingleVariable}()) ≈ fx
a = MOI.get(model, MOI.ListOfVariableIndices())[1]
fa = MOI.SingleVariable(a)
@test MOI.get(model, MOI.ObjectiveFunctionType()) == MOI.ScalarAffineFunction{T}
@test MOI.get(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}()) ≈ fa + one(T)
end
end
end
MOIU.@model(
LPModel,
(), (MOI.EqualTo, MOI.GreaterThan, MOI.LessThan), (), (),
(), (MOI.ScalarAffineFunction,), (), ()
)
@testset "Name test" begin
model = LPModel{Float64}()
bridged = MOIB.full_bridge_optimizer(model, Float64)
MOIT.nametest(bridged)
end
@testset "Unit" begin
model = LPModel{Float64}()
bridged = MOIB.full_bridge_optimizer(model, Float64)
MOIT.unittest(bridged, MOIT.TestConfig(solve=false), [
# SOC and quadratic constraints not supported
"solve_qcp_edge_cases", "delete_soc_variables"
])
end
# Model similar to SDPA format, it gives a good example because it does not
# support a lot hence need a lot of bridges
MOIU.@model(SDPAModel,
(), (MOI.EqualTo,), (MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), (),
(), (MOI.ScalarAffineFunction,), (MOI.VectorOfVariables,), ())
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.SingleVariable}, ::Type{MOI.GreaterThan{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.SingleVariable}, ::Type{MOI.LessThan{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.SingleVariable}, ::Type{MOI.EqualTo{T}}) where {T} = false
MOI.supports_constraint(::SDPAModel{T}, ::Type{MOI.SingleVariable}, ::Type{MOI.Interval{T}}) where {T} = false
MOI.supports_add_constrained_variables(::SDPAModel, ::Type{MOI.Nonnegatives}) = true
MOI.supports_add_constrained_variables(::SDPAModel, ::Type{MOI.PositiveSemidefiniteConeTriangle}) = true
MOI.supports_add_constrained_variables(::SDPAModel, ::Type{MOI.Reals}) = false
MOI.supports(::SDPAModel{T}, ::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}}) where {T} = false
MOI.supports(::SDPAModel, ::MOI.ObjectiveFunction{MOI.SingleVariable}) = false
@testset "Name test with SDPAModel{Float64}" begin
model = SDPAModel{Float64}()
bridged = MOIB.full_bridge_optimizer(model, Float64)
MOIT.nametest(bridged)
end
@testset "Show SPDA model" begin
model = SDPAModel{Float64}()
bridged = MOIB.full_bridge_optimizer(model, Float64)
# no bridges
@test sprint(show, bridged) === raw"""
MOIB.LazyBridgeOptimizer{SDPAModel{Float64}}
with 0 variable bridges
with 0 constraint bridges
with 0 objective bridges
with inner model SDPAModel{Float64}"""
MOI.add_constrained_variable(bridged, MOI.LessThan(1.0))
# add variable bridges
@test sprint(show, bridged) == raw"""
MOIB.LazyBridgeOptimizer{SDPAModel{Float64}}
with 2 variable bridges
with 0 constraint bridges
with 0 objective bridges
with inner model SDPAModel{Float64}"""
end
@testset "SDPA format with $T" for T in [Float64, Int]
model = SDPAModel{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
@testset "Variable" begin
@testset "Nonpositives" begin
@test !MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.Nonpositives)
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.Nonpositives)
@test !MOI.supports_add_constrained_variables(bridged, MOI.Nonpositives)
MOIB.add_bridge(bridged, MOIB.Variable.NonposToNonnegBridge{T})
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.Nonpositives)
@test MOI.supports_add_constrained_variables(bridged, MOI.Nonpositives)
@test MOIB.bridge_type(bridged, MOI.Nonpositives) == MOIB.Variable.NonposToNonnegBridge{T}
end
@testset "Zeros" begin
@test !MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.Zeros)
@test !MOI.supports_add_constrained_variables(bridged, MOI.Zeros)
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.Zeros)
MOIB.add_bridge(bridged, MOIB.Variable.ZerosBridge{T})
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.Zeros)
@test MOI.supports_add_constrained_variables(bridged, MOI.Zeros)
@test MOIB.bridge_type(bridged, MOI.Zeros) == MOIB.Variable.ZerosBridge{T}
end
@testset "Free" begin
@test !MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.Reals)
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.Reals)
@test !MOI.supports_add_constrained_variables(bridged, MOI.Reals)
@test_throws MOI.UnsupportedConstraint{MOI.VectorOfVariables, MOI.Reals} MOI.add_variable(bridged)
@test_throws MOI.UnsupportedConstraint{MOI.VectorOfVariables, MOI.Reals} MOI.add_variables(bridged, 2)
MOIB.add_bridge(bridged, MOIB.Variable.FreeBridge{T})
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.Reals)
@test MOI.supports_add_constrained_variables(bridged, MOI.Reals)
@test MOIB.bridge_type(bridged, MOI.Reals) == MOIB.Variable.FreeBridge{T}
end
@testset "Vectorize" begin
@test !MOI.supports_constraint(model, MOI.SingleVariable, MOI.GreaterThan{T})
@test !MOI.supports_constraint(bridged, MOI.SingleVariable, MOI.GreaterThan{T})
@test !MOI.supports_add_constrained_variable(bridged, MOI.GreaterThan{T})
@test !MOI.supports_constraint(model, MOI.SingleVariable, MOI.LessThan{T})
@test !MOI.supports_constraint(bridged, MOI.SingleVariable, MOI.LessThan{T})
@test !MOI.supports_add_constrained_variable(bridged, MOI.LessThan{T})
@test !MOI.supports_constraint(model, MOI.SingleVariable, MOI.EqualTo{T})
@test !MOI.supports_constraint(bridged, MOI.SingleVariable, MOI.EqualTo{T})
@test !MOI.supports_add_constrained_variable(bridged, MOI.EqualTo{T})
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
@test !MOI.supports_constraint(bridged, MOI.SingleVariable, MOI.GreaterThan{T})
@test MOI.supports_add_constrained_variable(bridged, MOI.GreaterThan{T})
@test MOIB.bridge_type(bridged, MOI.GreaterThan{T}) == MOIB.Variable.VectorizeBridge{T, MOI.Nonnegatives}
@test !MOI.supports_constraint(bridged, MOI.SingleVariable, MOI.LessThan{T})
@test MOI.supports_add_constrained_variable(bridged, MOI.LessThan{T})
@test MOIB.bridge_type(bridged, MOI.LessThan{T}) == MOIB.Variable.VectorizeBridge{T, MOI.Nonpositives}
@test !MOI.supports_constraint(bridged, MOI.SingleVariable, MOI.EqualTo{T})
@test MOI.supports_add_constrained_variable(bridged, MOI.EqualTo{T})
@test MOIB.bridge_type(bridged, MOI.EqualTo{T}) == MOIB.Variable.VectorizeBridge{T, MOI.Zeros}
end
@testset "RSOCtoPSD" begin
@test !MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.RotatedSecondOrderCone)
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.RotatedSecondOrderCone)
@test !MOI.supports_add_constrained_variables(bridged, MOI.RotatedSecondOrderCone)
MOIB.add_bridge(bridged, MOIB.Variable.RSOCtoPSDBridge{T})
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.RotatedSecondOrderCone)
@test !MOI.supports_add_constrained_variables(bridged, MOI.RotatedSecondOrderCone)
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarFunctionizeBridge{T})
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.RotatedSecondOrderCone)
@test MOI.supports_add_constrained_variables(bridged, MOI.RotatedSecondOrderCone)
@test MOIB.bridge_type(bridged, MOI.RotatedSecondOrderCone) == MOIB.Variable.RSOCtoPSDBridge{T}
end
@testset "Combining two briges" begin
x, cx = MOI.add_constrained_variable(bridged, MOI.LessThan(one(T)))
test_delete_bridged_variable(bridged, x, MOI.LessThan{T}, 1, (
(MOI.VectorOfVariables, MOI.Nonnegatives, 0),
(MOI.VectorOfVariables, MOI.Nonpositives, 0)),
used_bridges = 2)
end
end
@testset "Constraint" begin
@testset "Slack" begin
@test !MOI.supports_constraint(bridged, MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone)
MOIB.add_bridge(bridged, MOIB.Constraint.VectorSlackBridge{T})
@test !MOI.supports_constraint(bridged, MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone)
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarizeBridge{T})
@test MOI.supports_constraint(bridged, MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone)
@test MOIB.bridge_type(bridged, MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone) ==
MOIB.Constraint.VectorSlackBridge{T, MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone}
@test MOI.supports_constraint(bridged, MOI.VectorAffineFunction{T}, MOI.Zeros)
@test MOIB.bridge_type(bridged, MOI.VectorAffineFunction{T}, MOI.Zeros) ==
MOIB.Constraint.ScalarizeBridge{T, MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}}
end
@testset "Square" begin
@test !MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeSquare)
@test !MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeSquare)
MOIB.add_bridge(bridged, MOIB.Constraint.SquareBridge{T})
@test_throws MOI.UnsupportedConstraint{MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeSquare} MOIB.bridge_type(bridged, MOI.PositiveSemidefiniteConeSquare)
@test MOIB._dist(bridged.graph, MOIB.node(bridged, MOI.PositiveSemidefiniteConeSquare)) == MOIB.INFINITY
@test sprint(MOIB.print_graph, bridged) == """
Bridge graph with 1 variable nodes, 0 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.PositiveSemidefiniteConeSquare` are not supported
"""
@test MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeSquare)
@test sprint(MOIB.print_graph, bridged) == MOI.Utilities.replace_acronym("""
Bridge graph with 1 variable nodes, 1 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.PositiveSemidefiniteConeSquare` are not supported
(1) `MOI.VectorOfVariables`-in-`MOI.PositiveSemidefiniteConeSquare` constraints are bridged (distance 1) by $(MOIB.Constraint.SquareBridge{T,MOI.VectorOfVariables,MOI.ScalarAffineFunction{T},MOI.PositiveSemidefiniteConeTriangle,MOI.PositiveSemidefiniteConeSquare}).
""")
MOIB.add_bridge(bridged, MOIB.Constraint.VectorFunctionizeBridge{T})
@test_throws MOI.UnsupportedConstraint{MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeSquare} MOIB.bridge_type(bridged, MOI.PositiveSemidefiniteConeSquare)
@test MOIB._dist(bridged.graph, MOIB.node(bridged, MOI.PositiveSemidefiniteConeSquare)) == 6
@test sprint(MOIB.print_graph, bridged) == MOI.Utilities.replace_acronym("""
Bridge graph with 1 variable nodes, 3 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.PositiveSemidefiniteConeSquare` are supported (distance 6) by adding free variables and then constrain them, see (1).
(1) `MOI.VectorAffineFunction{$T}`-in-`MOI.PositiveSemidefiniteConeSquare` constraints are bridged (distance 3) by $(MOIB.Constraint.SquareBridge{T,MOI.VectorAffineFunction{T},MOI.ScalarAffineFunction{T},MOI.PositiveSemidefiniteConeTriangle,MOI.PositiveSemidefiniteConeSquare}).
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are bridged (distance 1) by $(MOIB.Constraint.ScalarizeBridge{T,MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}).
(3) `MOI.VectorAffineFunction{$T}`-in-`MOI.PositiveSemidefiniteConeTriangle` constraints are bridged (distance 2) by $(MOIB.Constraint.VectorSlackBridge{T,MOI.VectorAffineFunction{T},MOI.PositiveSemidefiniteConeTriangle}).
""")
end
@testset "Vectorize" begin
@test !MOI.supports_constraint(bridged, MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T})
MOIB.add_bridge(bridged, MOIB.Constraint.VectorizeBridge{T})
@test MOI.supports_constraint(bridged, MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T})
@test MOIB.bridge_type(bridged, MOI.ScalarAffineFunction{T},
MOI.GreaterThan{T}) ==
MOIB.Constraint.VectorizeBridge{
T, MOI.VectorAffineFunction{T}, MOI.Nonnegatives,
MOI.ScalarAffineFunction{T}
}
end
@testset "Quadratic" begin
@test !MOI.supports_constraint(bridged, MOI.ScalarQuadraticFunction{T}, MOI.GreaterThan{T})
@test !MOI.supports_constraint(bridged, MOI.ScalarQuadraticFunction{T}, MOI.LessThan{T})
MOIB.add_bridge(bridged, MOIB.Constraint.QuadtoSOCBridge{T})
@test MOI.supports_constraint(bridged, MOI.ScalarQuadraticFunction{T}, MOI.GreaterThan{T})
@test MOIB.bridge_type(bridged, MOI.ScalarQuadraticFunction{T},
MOI.GreaterThan{T}) == MOIB.Constraint.QuadtoSOCBridge{T}
@test MOI.supports_constraint(bridged, MOI.ScalarQuadraticFunction{T}, MOI.LessThan{T})
@test MOIB.bridge_type(bridged, MOI.ScalarQuadraticFunction{T},
MOI.LessThan{T}) == MOIB.Constraint.QuadtoSOCBridge{T}
end
end
@testset "Objective" begin
F = MOI.ScalarQuadraticFunction{T}
attr = MOI.ObjectiveFunction{F}()
@test !MOI.supports(bridged, MOI.ObjectiveFunction{MOI.SingleVariable}())
@test !MOI.supports(bridged, attr)
err = MOI.UnsupportedAttribute(attr)
@test_throws err MOIB.bridge_type(bridged, F)
MOIB.add_bridge(bridged, MOIB.Objective.SlackBridge{T})
@test !MOI.supports(bridged, MOI.ObjectiveFunction{MOI.SingleVariable}())
@test !MOI.supports(bridged, attr)
MOIB.add_bridge(bridged, MOIB.Objective.FunctionizeBridge{T})
@test MOI.supports(bridged, MOI.ObjectiveFunction{MOI.SingleVariable}())
@test MOIB.bridge_type(bridged, MOI.SingleVariable) == MOIB.Objective.FunctionizeBridge{T}
@test MOI.supports(bridged, attr)
@test MOIB.bridge_type(bridged, F) == MOIB.Objective.SlackBridge{T, F, F}
end
end
@testset "SDPA debug with $T" for T in [Float64, Int]
model = SDPAModel{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
function debug_string(f, args...)
s = IOBuffer()
f(bridged, args...; io = s)
return String(resize!(s.data, s.size))
end
@testset "LessThan variables" begin
S = MOI.LessThan{T}
@test debug_string(MOIB.debug_supports_add_constrained_variable, S) == """
Constrained variables in `MOI.LessThan{$T}` are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.LessThan{$T}` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
"""
@test sprint(MOIB.print_graph, bridged) == """
Bridge graph with 1 variable nodes, 0 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.LessThan{$T}` are not supported
"""
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
@test debug_string(MOIB.debug_supports_add_constrained_variable, S) == MOI.Utilities.replace_acronym("""
Constrained variables in `MOI.LessThan{$T}` are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.LessThan{$T}` are not supported because:
Cannot use `$(MOIB.Variable.VectorizeBridge{T,MOI.Nonpositives})` because:
[2] constrained variables in `MOI.Nonpositives` are not supported
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
[2] constrained variables in `MOI.Nonpositives` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
""")
MOIB.add_bridge(bridged, MOIB.Variable.NonposToNonnegBridge{T})
@test debug_string(MOIB.debug_supports_add_constrained_variable, S) == "Constrained variables in `MOI.LessThan{$T}` are supported.\n"
@test sprint(MOIB.print_graph, bridged) == MOI.Utilities.replace_acronym("""
Bridge graph with 2 variable nodes, 0 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.LessThan{$T}` are bridged (distance 2) by $(MOIB.Variable.VectorizeBridge{T,MOI.Nonpositives}).
[2] constrained variables in `MOI.Nonpositives` are bridged (distance 1) by $(MOIB.Variable.NonposToNonnegBridge{T}).
""")
end
bridged = MOIB.LazyBridgeOptimizer(model)
@testset "LessThan variables with ScalarFunctionizeBridge" begin
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarFunctionizeBridge{T})
S = MOI.LessThan{T}
@test debug_string(MOIB.debug_supports_add_constrained_variable, S) == """
Constrained variables in `MOI.LessThan{$T}` are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.LessThan{$T}` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because:
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because no added bridge supports bridging it.
"""
@test sprint(MOIB.print_graph, bridged) == """
Bridge graph with 1 variable nodes, 1 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.LessThan{$T}` are not supported
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
"""
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
@test debug_string(MOIB.debug_supports_add_constrained_variable, S) == MOI.Utilities.replace_acronym("""
Constrained variables in `MOI.LessThan{$T}` are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.LessThan{$T}` are not supported because:
Cannot use `$(MOIB.Variable.VectorizeBridge{T,MOI.Nonpositives})` because:
[2] constrained variables in `MOI.Nonpositives` are not supported
Cannot add free variables and then constrain them because:
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
[2] constrained variables in `MOI.Nonpositives` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because no added bridge supports bridging it.
""")
MOIB.add_bridge(bridged, MOIB.Variable.NonposToNonnegBridge{T})
@test debug_string(MOIB.debug_supports_add_constrained_variable, S) == "Constrained variables in `MOI.LessThan{$T}` are supported.\n"
@test sprint(MOIB.print_graph, bridged) == MOI.Utilities.replace_acronym("""
Bridge graph with 2 variable nodes, 1 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.LessThan{$T}` are bridged (distance 2) by $(MOIB.Variable.VectorizeBridge{T,MOI.Nonpositives}).
[2] constrained variables in `MOI.Nonpositives` are bridged (distance 1) by $(MOIB.Variable.NonposToNonnegBridge{T}).
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
""")
end
bridged = MOIB.LazyBridgeOptimizer(model)
@testset "Interval constraint" begin
F = MOI.ScalarAffineFunction{T}
S = MOI.Interval{T}
@test debug_string(MOIB.debug_supports_constraint, F, S) == """
`MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported because no added bridge supports bridging it.
"""
MOIB.add_bridge(bridged, MOIB.Constraint.SplitIntervalBridge{T})
@test debug_string(MOIB.debug_supports_constraint, F, S) == MOI.Utilities.replace_acronym("""
`MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.SplitIntervalBridge{T,MOI.ScalarAffineFunction{T},MOI.Interval{T},MOI.GreaterThan{T},MOI.LessThan{T}})` because:
(2) `MOI.ScalarAffineFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported
(3) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
(2) `MOI.ScalarAffineFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported because no added bridge supports bridging it.
(3) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because no added bridge supports bridging it.
""")
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarSlackBridge{T})
@test debug_string(MOIB.debug_supports_constraint, F, S) == MOI.Utilities.replace_acronym("""
`MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.GreaterThan{$T}` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
[2] constrained variables in `MOI.LessThan{$T}` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
[3] constrained variables in `MOI.Interval{$T}` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.SplitIntervalBridge{T,MOI.ScalarAffineFunction{T},MOI.Interval{T},MOI.GreaterThan{T},MOI.LessThan{T}})` because:
(2) `MOI.ScalarAffineFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported
(3) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
Cannot use `$(MOIB.Constraint.ScalarSlackBridge{T,MOI.ScalarAffineFunction{T},MOI.Interval{T}})` because:
[3] constrained variables in `MOI.Interval{$T}` are not supported
(2) `MOI.ScalarAffineFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.ScalarSlackBridge{T,MOI.ScalarAffineFunction{T},MOI.GreaterThan{T}})` because:
[1] constrained variables in `MOI.GreaterThan{$T}` are not supported
(3) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.ScalarSlackBridge{T,MOI.ScalarAffineFunction{T},MOI.LessThan{T}})` because:
[2] constrained variables in `MOI.LessThan{$T}` are not supported
""")
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
@test debug_string(MOIB.debug_supports_constraint, F, S) == MOI.Utilities.replace_acronym("""
`MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[2] constrained variables in `MOI.LessThan{$T}` are not supported because:
Cannot use `$(MOIB.Variable.VectorizeBridge{T,MOI.Nonpositives})` because:
[3] constrained variables in `MOI.Nonpositives` are not supported
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
[3] constrained variables in `MOI.Nonpositives` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
[4] constrained variables in `MOI.Interval{$T}` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
(1) `MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.SplitIntervalBridge{T,MOI.ScalarAffineFunction{T},MOI.Interval{T},MOI.GreaterThan{T},MOI.LessThan{T}})` because:
(3) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
Cannot use `$(MOIB.Constraint.ScalarSlackBridge{T,MOI.ScalarAffineFunction{T},MOI.Interval{T}})` because:
[4] constrained variables in `MOI.Interval{$T}` are not supported
(3) `MOI.ScalarAffineFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.ScalarSlackBridge{T,MOI.ScalarAffineFunction{T},MOI.LessThan{T}})` because:
[2] constrained variables in `MOI.LessThan{$T}` are not supported
""")
MOIB.add_bridge(bridged, MOIB.Variable.NonposToNonnegBridge{T})
@test debug_string(MOIB.debug_supports_constraint, F, S) == "`MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are supported.\n"
end
bridged = MOIB.LazyBridgeOptimizer(model)
@testset "Quadratic objective" begin
F = MOI.ScalarQuadraticFunction{T}
attr = MOI.ObjectiveFunction{F}()
@test debug_string(MOIB.debug_supports, attr) == """
Objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported and cannot be bridged into a supported objective function by adding only supported constrained variables and constraints. See details below:
|1| objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported because no added bridge supports bridging it.
"""
MOIB.add_bridge(bridged, MOIB.Objective.SlackBridge{T})
@test debug_string(MOIB.debug_supports, attr) == MOI.Utilities.replace_acronym("""
Objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported and cannot be bridged into a supported objective function by adding only supported constrained variables and constraints. See details below:
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported because no added bridge supports bridging it.
(2) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because no added bridge supports bridging it.
|1| objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported because:
Cannot use `$(MOIB.Objective.SlackBridge{T,MOI.ScalarQuadraticFunction{T},MOI.ScalarQuadraticFunction{T}})` because:
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported
(2) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
|2| objective function of type `MOI.SingleVariable` is not supported
|2| objective function of type `MOI.SingleVariable` is not supported because no added bridge supports bridging it.
""")
MOIB.add_bridge(bridged, MOIB.Objective.FunctionizeBridge{T})
MOIB.add_bridge(bridged, MOIB.Constraint.QuadtoSOCBridge{T})
@test debug_string(MOIB.debug_supports, attr) == MOI.Utilities.replace_acronym("""
Objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported and cannot be bridged into a supported objective function by adding only supported constrained variables and constraints. See details below:
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.QuadtoSOCBridge{T})` because:
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported because no added bridge supports bridging it.
(3) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.QuadtoSOCBridge{T})` because:
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported
|1| objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported because:
Cannot use `$(MOIB.Objective.SlackBridge{T,MOI.ScalarQuadraticFunction{T},MOI.ScalarQuadraticFunction{T}})` because:
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported
(3) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
""")
MOIB.add_bridge(bridged, MOIB.Constraint.VectorSlackBridge{T})
@test debug_string(MOIB.debug_supports, attr) == MOI.Utilities.replace_acronym("""
Objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported and cannot be bridged into a supported objective function by adding only supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.RotatedSecondOrderCone` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.QuadtoSOCBridge{T})` because:
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported because:
Cannot use `$(MOIB.Constraint.VectorSlackBridge{T,MOI.VectorAffineFunction{T},MOI.RotatedSecondOrderCone})` because:
[1] constrained variables in `MOI.RotatedSecondOrderCone` are not supported
(3) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported
(3) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported because no added bridge supports bridging it.
(4) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.QuadtoSOCBridge{T})` because:
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported
|1| objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported because:
Cannot use `$(MOIB.Objective.SlackBridge{T,MOI.ScalarQuadraticFunction{T},MOI.ScalarQuadraticFunction{T}})` because:
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported
(4) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
""")
MOIB.add_bridge(bridged, MOIB.Variable.RSOCtoPSDBridge{T})
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarFunctionizeBridge{T})
@test debug_string(MOIB.debug_supports, attr) == MOI.Utilities.replace_acronym("""
Objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported and cannot be bridged into a supported objective function by adding only supported constrained variables and constraints. See details below:
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.QuadtoSOCBridge{T})` because:
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported because:
Cannot use `$(MOIB.Constraint.VectorSlackBridge{T,MOI.VectorAffineFunction{T},MOI.RotatedSecondOrderCone})` because:
(4) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported
(4) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported because no added bridge supports bridging it.
(5) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported because:
Cannot use `$(MOIB.Constraint.QuadtoSOCBridge{T})` because:
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are not supported
|1| objective function of type `MOI.ScalarQuadraticFunction{$T}` is not supported because:
Cannot use `$(MOIB.Objective.SlackBridge{T,MOI.ScalarQuadraticFunction{T},MOI.ScalarQuadraticFunction{T}})` because:
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are not supported
(5) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are not supported
""")
MOIB.add_bridge(bridged, MOIB.Constraint.ScalarizeBridge{T})
@test debug_string(MOIB.debug_supports, attr) == "Objective function of type `MOI.ScalarQuadraticFunction{$T}` is supported.\n"
@test sprint(MOIB.print_graph, bridged) == MOI.Utilities.replace_acronym("""
Bridge graph with 1 variable nodes, 5 constraint nodes and 2 objective nodes.
[1] constrained variables in `MOI.RotatedSecondOrderCone` are bridged (distance 2) by $(MOIB.Variable.RSOCtoPSDBridge{T}).
(1) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.GreaterThan{$T}` constraints are bridged (distance 5) by $(MOIB.Constraint.QuadtoSOCBridge{T}).
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are bridged (distance 4) by $(MOIB.Constraint.VectorSlackBridge{T,MOI.VectorAffineFunction{T},MOI.RotatedSecondOrderCone}).
(3) `MOI.SingleVariable`-in-`MOI.EqualTo{$T}` constraints are bridged (distance 1) by $(MOIB.Constraint.ScalarFunctionizeBridge{T,MOI.EqualTo{T}}).
(4) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are bridged (distance 1) by $(MOIB.Constraint.ScalarizeBridge{T,MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}).
(5) `MOI.ScalarQuadraticFunction{$T}`-in-`MOI.LessThan{$T}` constraints are bridged (distance 5) by $(MOIB.Constraint.QuadtoSOCBridge{T}).
|1| objective function of type `MOI.ScalarQuadraticFunction{$T}` is bridged (distance 12) by $(MOIB.Objective.SlackBridge{T,MOI.ScalarQuadraticFunction{T},MOI.ScalarQuadraticFunction{T}}).
|2| objective function of type `MOI.SingleVariable` is bridged (distance 1) by $(MOIB.Objective.FunctionizeBridge{T}).
""")
end
bridged = MOIB.LazyBridgeOptimizer(model)
@testset "Exponential constraint" begin
F = MOI.VectorAffineFunction{T}
S = MOI.ExponentialCone
@test debug_string(MOIB.debug_supports_constraint, F, S) ==
"""
`MOI.VectorAffineFunction{$T}`-in-`MOI.ExponentialCone` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
(1) `MOI.VectorAffineFunction{$T}`-in-`MOI.ExponentialCone` constraints are not supported because no added bridge supports bridging it.
"""
MOIB.add_bridge(bridged, MOIB.Constraint.VectorSlackBridge{T})
@test debug_string(MOIB.debug_supports_constraint, F, S) == MOI.Utilities.replace_acronym("""
`MOI.VectorAffineFunction{$T}`-in-`MOI.ExponentialCone` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.ExponentialCone` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because free variables are bridged but no functionize bridge was added.
(1) `MOI.VectorAffineFunction{$T}`-in-`MOI.ExponentialCone` constraints are not supported because:
Cannot use `$(MOIB.Constraint.VectorSlackBridge{T,MOI.VectorAffineFunction{T},MOI.ExponentialCone})` because:
[1] constrained variables in `MOI.ExponentialCone` are not supported
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported because no added bridge supports bridging it.
""")
MOIB.add_bridge(bridged, MOIB.Constraint.VectorFunctionizeBridge{T})
@test debug_string(MOIB.debug_supports_constraint, F, S) ==MOI.Utilities.replace_acronym("""
`MOI.VectorAffineFunction{$T}`-in-`MOI.ExponentialCone` constraints are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `MOI.ExponentialCone` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because:
(1) `MOI.VectorAffineFunction{$T}`-in-`MOI.ExponentialCone` constraints are not supported
(1) `MOI.VectorAffineFunction{$T}`-in-`MOI.ExponentialCone` constraints are not supported because:
Cannot use `$(MOIB.Constraint.VectorSlackBridge{T,MOI.VectorAffineFunction{T},MOI.ExponentialCone})` because:
[1] constrained variables in `MOI.ExponentialCone` are not supported
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.Zeros` constraints are not supported because no added bridge supports bridging it.
""")
end
end
@testset "Continuous Linear with SDPAModel{$T}" for T in [Float64, Rational{Int}]
model = SDPAModel{T}()
bridged = MOIB.full_bridge_optimizer(model, T)
# For `ScalarAffineFunction`-in-`GreaterThan`,
# `Constraint.ScalarSlackBridge` -> `Variable.VectorizeBridge`
# is equivalent to
# `Constraint.VectorizeBridge` -> `Constraint.VectorSlackBridge`
# however, `Variable.VectorizeBridge` do not support modification of the
# set hence it makes some tests of `contlineartest` fail so we disable it.
MOIB.remove_bridge(bridged, MOIB.Constraint.ScalarSlackBridge{T})
exclude = ["partial_start"] # `VariablePrimalStart` not supported.
MOIT.contlineartest(bridged, MOIT.TestConfig{T}(solve=false), exclude)
end
@testset "SDPAModel with bridges and caching" begin
# This tests that the computation of the reverse dict in the
# caching optimizer works with negative indices
cached = MOIU.CachingOptimizer(MOIU.Model{Float64}(), MOIU.MANUAL)
vi_cache = MOI.add_variable(cached)
model = SDPAModel{Float64}()
bridged = MOIB.full_bridge_optimizer(model, Float64)
MOIU.reset_optimizer(cached, bridged)
MOIU.attach_optimizer(cached)
vi_bridged = first(MOI.get(bridged, MOI.ListOfVariableIndices()))
@test vi_bridged == MOI.VariableIndex(-1)
@test cached.model_to_optimizer_map[vi_cache] == vi_bridged
@test cached.optimizer_to_model_map[vi_bridged] == vi_cache
end
@testset "Continuous Conic with SDPAModel{Float64}" begin
model = SDPAModel{Float64}()
bridged = MOIB.full_bridge_optimizer(model, Float64)
MOIT.psds0vtest(bridged, MOIT.TestConfig(solve=false))
#exclude = ["exp", "dualexp", "pow", "dualpow", "logdet", "rootdets"]
#MOIT.contconictest(bridged, MOIT.TestConfig(solve=false), exclude)
end
# Model not supporting RotatedSecondOrderCone
MOIU.@model(NoRSOCModel,
(),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan),
(MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, MOI.SecondOrderCone,
MOI.NormInfinityCone, MOI.NormOneCone,
MOI.ExponentialCone, MOI.PositiveSemidefiniteConeTriangle),
(MOI.PowerCone,),
(),
(MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction),
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction, MOI.VectorQuadraticFunction))
# We only use floating point types as there is √2
@testset "Constrained variables in RSOC with $T" for T in [Float64, BigFloat]
bridged = MOIB.full_bridge_optimizer(NoRSOCModel{T}(), T)
@test MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.RotatedSecondOrderCone)
# It should be selected over `MOIB.Variable.RSOCtoPSDBridge` even if they
# are tied in terms of number of bridges because it is added first in
# `MOIB.full_bridge_optimizer`.
@test MOIB.bridge_type(bridged, MOI.RotatedSecondOrderCone) == MOIB.Variable.RSOCtoSOCBridge{T}
x, cx = MOI.add_constrained_variables(bridged, MOI.RotatedSecondOrderCone(3))
for i in 1:3
@test MOIB.bridge(bridged, x[i]) isa MOIB.Variable.RSOCtoSOCBridge{T}
end
@test MOIB.bridge(bridged, cx) isa MOIB.Variable.RSOCtoSOCBridge{T}
end
# Model not supporting VectorOfVariables and SingleVariable
MOIU.@model(NoVariableModel,
(MOI.ZeroOne, MOI.Integer),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan),
(MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, MOI.SecondOrderCone),
(),
(),
(MOI.ScalarAffineFunction,),
(),
(MOI.VectorAffineFunction,))
function MOI.supports_constraint(::NoVariableModel{T}, ::Type{MOI.SingleVariable},
::Type{<:MOIU.SUPPORTED_VARIABLE_SCALAR_SETS{T}}) where T
return false
end
@testset "Continuous Conic with NoVariableModel{$T}" for T in [Float64, Float32]
model = NoVariableModel{T}()
bridged = MOIB.full_bridge_optimizer(model, T)
# The best variable bridge for SOC and RSOC are respectively `SOCtoRSOC` and `RSOCtoSOC`.
# This forms a cycle because using the variable bridges is not in the shortest path.
# Therefore they should not be used when calling `add_constrained_variables`.
# Moreover, the printing should say that the variable bridge is not used.
@test MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.SecondOrderCone)
@test MOIB.bridge_type(bridged, MOI.SecondOrderCone) == MOIB.Variable.SOCtoRSOCBridge{T}
@test !MOIB.is_variable_bridged(bridged, MOI.RotatedSecondOrderCone)
@test MOI.supports_constraint(bridged, MOI.VectorOfVariables, MOI.RotatedSecondOrderCone)
@test MOIB.bridge_type(bridged, MOI.RotatedSecondOrderCone) == MOIB.Variable.RSOCtoSOCBridge{T}
@test !MOIB.is_variable_bridged(bridged, MOI.RotatedSecondOrderCone)
x, cx = MOI.add_constrained_variables(bridged, MOI.SecondOrderCone(3))
@test !any(v -> MOIB.is_bridged(bridged, v), x)
@test !MOIB.is_variable_bridged(bridged, cx)
@test MOIB.bridge(bridged, cx) isa MOIB.Constraint.VectorFunctionizeBridge{T,MOI.SecondOrderCone}
y, cy = MOI.add_constrained_variables(bridged, MOI.RotatedSecondOrderCone(4))
@test !any(v -> MOIB.is_bridged(bridged, v), y)
@test !MOIB.is_variable_bridged(bridged, cy)
@test MOIB.bridge(bridged, cy) isa MOIB.Constraint.RSOCBridge{T}
@test sprint(MOIB.print_graph, bridged) == MOI.Utilities.replace_acronym("""
Bridge graph with 5 variable nodes, 11 constraint nodes and 0 objective nodes.
[1] constrained variables in `MOI.RotatedSecondOrderCone` are supported (distance 2) by adding free variables and then constrain them, see (3).
[2] constrained variables in `MOI.PositiveSemidefiniteConeTriangle` are not supported
[3] constrained variables in `MOI.SecondOrderCone` are supported (distance 2) by adding free variables and then constrain them, see (1).
[4] constrained variables in `MOI.Nonnegatives` are supported (distance 2) by adding free variables and then constrain them, see (6).
[5] constrained variables in `MOI.Interval{$T}` are supported (distance 3) by adding free variables and then constrain them, see (8).
(1) `MOI.VectorOfVariables`-in-`MOI.SecondOrderCone` constraints are bridged (distance 1) by $(MOIB.Constraint.VectorFunctionizeBridge{T,MOI.SecondOrderCone}).
(2) `MOI.VectorAffineFunction{$T}`-in-`MOI.RotatedSecondOrderCone` constraints are bridged (distance 1) by $(MOIB.Constraint.RSOCBridge{T,MOI.VectorAffineFunction{T},MOI.VectorAffineFunction{T}}).
(3) `MOI.VectorOfVariables`-in-`MOI.RotatedSecondOrderCone` constraints are bridged (distance 1) by $(MOIB.Constraint.RSOCBridge{T,MOI.VectorAffineFunction{T},MOI.VectorOfVariables}).
(4) `MOI.VectorAffineFunction{$T}`-in-`MOI.PositiveSemidefiniteConeTriangle` constraints are not supported
(5) `MOI.VectorOfVariables`-in-`MOI.PositiveSemidefiniteConeTriangle` constraints are not supported
(6) `MOI.VectorOfVariables`-in-`MOI.Nonnegatives` constraints are bridged (distance 1) by $(MOIB.Constraint.NonnegToNonposBridge{T,MOI.VectorAffineFunction{T},MOI.VectorOfVariables}).
(7) `MOI.SingleVariable`-in-`MOI.GreaterThan{$T}` constraints are bridged (distance 1) by $(MOIB.Constraint.GreaterToLessBridge{T,MOI.ScalarAffineFunction{T},MOI.SingleVariable}).
(8) `MOI.SingleVariable`-in-`MOI.Interval{$T}` constraints are bridged (distance 2) by $(MOIB.Constraint.ScalarFunctionizeBridge{T,MOI.Interval{T}}).
(9) `MOI.ScalarAffineFunction{$T}`-in-`MOI.Interval{$T}` constraints are bridged (distance 1) by $(MOIB.Constraint.SplitIntervalBridge{T,MOI.ScalarAffineFunction{T},MOI.Interval{T},MOI.GreaterThan{T},MOI.LessThan{T}}).
(10) `MOI.SingleVariable`-in-`MOI.LessThan{$T}` constraints are bridged (distance 1) by $(MOIB.Constraint.LessToGreaterBridge{T,MOI.ScalarAffineFunction{T},MOI.SingleVariable}).
(11) `MOI.SingleVariable`-in-`MOI.EqualTo{$T}` constraints are bridged (distance 1) by $(MOIB.Constraint.VectorizeBridge{T,MOI.VectorAffineFunction{T},MOI.Zeros,MOI.SingleVariable}).
""")
end
MOIU.@model(OnlyNonnegVAF,
(), (), (MOI.Nonnegatives,), (),
(), (), (), (MOI.VectorAffineFunction,))
function MOI.supports_constraint(::OnlyNonnegVAF{T}, ::Type{MOI.SingleVariable},
::Type{<:MOIU.SUPPORTED_VARIABLE_SCALAR_SETS{T}}) where T
return false
end
struct InvariantUnderFunctionConversionAttribute <: MOI.AbstractConstraintAttribute end
MOIB.Constraint.invariant_under_function_conversion(::InvariantUnderFunctionConversionAttribute) = true
function _dict(model::OnlyNonnegVAF)
if !haskey(model.ext, :InvariantUnderFunctionConversionAttribute)
model.ext[:InvariantUnderFunctionConversionAttribute] = Dict{MOI.ConstraintIndex, Any}()
end
return model.ext[:InvariantUnderFunctionConversionAttribute]
end
function MOI.set(model::OnlyNonnegVAF,
::InvariantUnderFunctionConversionAttribute,
ci::MOI.ConstraintIndex, value)
_dict(model)[ci] = value
end
function MOI.get(model::OnlyNonnegVAF,
::InvariantUnderFunctionConversionAttribute,
ci::MOI.ConstraintIndex)
return _dict(model)[ci]
end
@testset "Context of substitution with $T" for T in [Float32, Float64]
@testset "Attribute" begin
# Two Variable bridge in context
model = OnlyNonnegVAF{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
MOIB.add_bridge(bridged, MOIB.Constraint.VectorFunctionizeBridge{T})
MOIB.add_bridge(bridged, MOIB.Variable.NonposToNonnegBridge{T})
MOIB.add_bridge(bridged, MOIB.Variable.VectorizeBridge{T})
x, cx = MOI.add_constrained_variable(bridged, MOI.LessThan(one(T)))
fx = MOI.SingleVariable(x)
vectorize = MOIB.bridge(bridged, x)
@test vectorize isa MOIB.Variable.VectorizeBridge
y = vectorize.variable
fy = MOI.SingleVariable(y)
flip = MOIB.bridge(bridged, y)
@test flip isa MOIB.Variable.NonposToNonnegBridge
Z = flip.flipped_variables
z = Z[1]
fz = MOI.SingleVariable(z)
vov_ci = flip.flipped_constraint
functionize = MOIB.bridge(bridged, vov_ci)
@test functionize isa MOIB.Constraint.VectorFunctionizeBridge
aff_ci = functionize.constraint
f(vi) = MOIB.Variable.unbridged_function(MOIB.Variable.bridges(bridged), vi)
@test f(y) ≈ one(T) * fx - one(T)
@test MOIB.call_in_context(bridged, x, bridge -> f(y)) === nothing
@test MOIB.call_in_context(bridged, y, bridge -> f(y)) === nothing
@test f(z) ≈ -one(T) * fy
@test MOIB.call_in_context(bridged, x, bridge -> f(z)) ≈ f(z)
@test MOIB.call_in_context(bridged, y, bridge -> f(z)) === nothing
attr = InvariantUnderFunctionConversionAttribute()
for func in [T(2) * fx, T(2) * fy, T(2) * fz]
MOI.set(model, attr, aff_ci, func)
@test MOI.get(model, attr, aff_ci) ≈ func
@test MOIB.call_in_context(bridged, vov_ci, bridge -> MOI.get(bridged, attr, vov_ci)) ≈ func
@test MOIB.call_in_context(bridged, y, bridge -> MOI.get(bridged, attr, vov_ci)) ≈ func
#@test MOIB.call_in_context(bridged, z, bridge -> MOI.get(bridged, attr, vov_ci)) ≈ func
end
end
@testset "Delete" begin
# One Variable bridge in context
model = NoVariableModel{T}()
bridged = MOIB.LazyBridgeOptimizer(model)
MOIB.add_bridge(bridged, MOIB.Variable.RSOCtoSOCBridge{T})
MOIB.add_bridge(bridged, MOIB.Constraint.VectorFunctionizeBridge{T})
x, cx = MOI.add_constrained_variables(bridged, MOI.RotatedSecondOrderCone(4))
y = MOI.add_variable(bridged)
@test MOI.get(bridged, MOI.NumberOfVariables()) == 5
@test MOI.is_valid(bridged, y)
MOI.delete(bridged, y)
@test MOI.get(bridged, MOI.NumberOfVariables()) == 4
@test !MOI.is_valid(bridged, y)
test_delete_bridged_variables(bridged, x, MOI.RotatedSecondOrderCone, 4, (
(MOI.VectorOfVariables, MOI.SecondOrderCone, 0),
(MOI.VectorAffineFunction{T}, MOI.SecondOrderCone, 0)
))
end
end
# Only supports GreaterThan and Nonnegatives
MOIU.@model(GreaterNonnegModel,
(),
(MOI.GreaterThan,),
(MOI.Nonnegatives,),
(),
(),
(MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction),
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction, MOI.VectorQuadraticFunction))
function MOI.supports_constraint(
::GreaterNonnegModel{T}, ::Type{MOI.SingleVariable},
::Type{<:Union{MOI.EqualTo{T}, MOI.LessThan{T}, MOI.Interval{T}}}) where T
return false
end
MOIU.@model(ModelNoVAFinSOC,
(),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval),
(MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives, MOI.SecondOrderCone,
MOI.NormInfinityCone, MOI.NormOneCone,
MOI.RotatedSecondOrderCone, MOI.GeometricMeanCone,
MOI.PositiveSemidefiniteConeTriangle, MOI.ExponentialCone),
(MOI.PowerCone, MOI.DualPowerCone),
(),
(MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction),
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction, MOI.VectorQuadraticFunction))
MOI.supports_constraint(::ModelNoVAFinSOC{Float64},
::Type{MOI.VectorAffineFunction{Float64}},
::Type{MOI.SecondOrderCone}) = false
# Model supporting nothing
MOIU.@model NothingModel () () () () () () () ()
function MOI.supports_constraint(
::NothingModel{T}, ::Type{MOI.SingleVariable},
::Type{<:Union{MOI.EqualTo{T}, MOI.GreaterThan{T}, MOI.LessThan{T},
MOI.Interval{T}, MOI.Integer, MOI.ZeroOne}}) where T
return false
end
struct BridgeAddingNoConstraint{T} <: MOI.Bridges.Constraint.AbstractBridge end
MOIB.added_constrained_variable_types(::Type{<:BridgeAddingNoConstraint}) = Tuple{DataType}[]
MOIB.added_constraint_types(::Type{<:BridgeAddingNoConstraint}) = Tuple{DataType, DataType}[]
function MOI.supports_constraint(::Type{<:BridgeAddingNoConstraint},
::Type{MOI.SingleVariable},
::Type{MOI.Integer})
return true
end
function MOIB.Constraint.concrete_bridge_type(::Type{<:BridgeAddingNoConstraint{T}},
::Type{MOI.SingleVariable},
::Type{MOI.Integer}) where {T}
return BridgeAddingNoConstraint{T}
end
const LessThanIndicatorSetOne{T} = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE, MOI.LessThan{T}}
MOIU.@model(ModelNoZeroIndicator,
(MOI.ZeroOne, MOI.Integer),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval,
MOI.Semicontinuous, MOI.Semiinteger),
(MOI.Reals, MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives,
MOI.NormInfinityCone, MOI.NormOneCone,
MOI.SecondOrderCone, MOI.RotatedSecondOrderCone,
MOI.GeometricMeanCone, MOI.ExponentialCone, MOI.DualExponentialCone,
MOI.RelativeEntropyCone, MOI.NormSpectralCone, MOI.NormNuclearCone,
MOI.PositiveSemidefiniteConeTriangle, MOI.PositiveSemidefiniteConeSquare,
MOI.RootDetConeTriangle, MOI.RootDetConeSquare, MOI.LogDetConeTriangle,
MOI.LogDetConeSquare),
(MOI.PowerCone, MOI.DualPowerCone, MOI.SOS1, MOI.SOS2, LessThanIndicatorSetOne),
(), (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction),
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction, MOI.VectorQuadraticFunction))
MOIU.@model(ModelNoIndicator,
(MOI.ZeroOne, MOI.Integer),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval,
MOI.Semicontinuous, MOI.Semiinteger),
(MOI.Reals, MOI.Zeros, MOI.Nonnegatives, MOI.Nonpositives,
MOI.NormInfinityCone, MOI.NormOneCone,
MOI.SecondOrderCone, MOI.RotatedSecondOrderCone,
MOI.GeometricMeanCone, MOI.ExponentialCone, MOI.DualExponentialCone,
MOI.RelativeEntropyCone, MOI.NormSpectralCone, MOI.NormNuclearCone,
MOI.PositiveSemidefiniteConeTriangle, MOI.PositiveSemidefiniteConeSquare,
MOI.RootDetConeTriangle, MOI.RootDetConeSquare, MOI.LogDetConeTriangle,
MOI.LogDetConeSquare),
(MOI.PowerCone, MOI.DualPowerCone, MOI.SOS1, MOI.SOS2),
(), (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction),
(MOI.VectorOfVariables,),
(MOI.VectorAffineFunction, MOI.VectorQuadraticFunction))
@testset "Bridge adding no constraint" begin
mock = MOIU.MockOptimizer(NothingModel{Int}())
bridged = MOIB.LazyBridgeOptimizer(mock)
MOI.Bridges.add_bridge(bridged, BridgeAddingNoConstraint{Float64})
@test MOI.Bridges.supports_bridging_constraint(bridged,
MOI.SingleVariable,
MOI.Integer)
end
@testset "Unsupported constraint with cycles" begin
# Test that `supports_constraint` works correctly when it is not
# supported but the bridges forms a cycle
mock = MOIU.MockOptimizer(NothingModel{Float64}())
bridged = MOIB.full_bridge_optimizer(mock, Float64)
@test !MOI.supports_constraint(
bridged, MOI.SingleVariable, MOI.GreaterThan{Float64})
@test !MOI.supports_constraint(
bridged, MOI.VectorAffineFunction{Float64}, MOI.Nonpositives)
end
mock = MOIU.MockOptimizer(NoRSOCModel{Float64}())
bridged_mock = MOIB.LazyBridgeOptimizer(mock)
@testset "UnsupportedConstraint when it cannot be bridged" begin
x = MOI.add_variables(bridged_mock, 4)
err = MOI.UnsupportedConstraint{MOI.VectorOfVariables,
MOI.RotatedSecondOrderCone}()
@test_throws err begin
MOI.add_constraint(bridged_mock, MOI.VectorOfVariables(x),
MOI.RotatedSecondOrderCone(4))