File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -95,10 +95,9 @@ satisfy(constraints::Array{<:Constraint}=Constraint[]; numeric_type = Float64) =
95
95
satisfy (constraint:: Constraint ; numeric_type = Float64) = satisfy ([constraint]; numeric_type = numeric_type)
96
96
97
97
# +(constraints, constraints) is defined in constraints.jl
98
- add_constraints! (p:: Problem , constraints:: Array{<:Constraint} ) =
99
- + (p. constraints, constraints)
98
+ add_constraints! (p:: Problem , constraints:: Array{<:Constraint} ) = append! (p. constraints, constraints)
100
99
add_constraints! (p:: Problem , constraint:: Constraint ) = add_constraints! (p, [constraint])
101
- add_constraint! = add_constraints!
100
+ const add_constraint! = add_constraints!
102
101
103
102
# caches conic form of x when x is the solution to the optimization problem p
104
103
function cache_conic_form! (conic_forms:: UniqueConicForms , x:: AbstractExpr , p:: Problem )
Original file line number Diff line number Diff line change @@ -274,6 +274,23 @@ using Convex: AbstractExpr, ConicObj
274
274
@test_logs Convex. NotDcp ()
275
275
Convex. DCP_WARNINGS[] = true
276
276
@test_logs (:warn , r" not DCP compliant" ) Convex. NotDcp ()
277
-
277
+
278
+ end
279
+
280
+ @testset " `add_constraints!` (#380)" begin
281
+ x = Variable (3 , 3 )
282
+ p = minimize (norm_1 (x))
283
+ y = randn (3 , 3 )
284
+ c = (norm2 (x- y) < 1 )
285
+ @test length (p. constraints) == 0
286
+ add_constraint! (p, c)
287
+ @test length (p. constraints) == 1
288
+ empty! (p. constraints)
289
+ add_constraints! (p, c)
290
+ @test length (p. constraints) == 1
291
+ empty! (p. constraints)
292
+ c2 = (norm2 (x- rand (3 ,3 )) < 3 )
293
+ add_constraints! (p, [c, c2])
294
+ @test length (p. constraints) == 2
278
295
end
279
296
end
You can’t perform that action at this time.
0 commit comments