Skip to content

Commit c30c4b0

Browse files
authored
Merge pull request #381 from JuliaOpt/fix-add-constraint!
Fix `add_constraint!`
2 parents 9e55404 + 9dc33ae commit c30c4b0

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
Manifest.toml
88
benchmark/*.json
99
test/Project.toml
10+
dev

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Convex"
22
uuid = "f65535da-76fb-5f13-bab9-19810c17039a"
3-
version = "0.13.2"
3+
version = "0.13.3"
44

55
[deps]
66
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/problems.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ satisfy(constraints::Array{<:Constraint}=Constraint[]; numeric_type = Float64) =
9595
satisfy(constraint::Constraint; numeric_type = Float64) = satisfy([constraint]; numeric_type = numeric_type)
9696

9797
# +(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)
10099
add_constraints!(p::Problem, constraint::Constraint) = add_constraints!(p, [constraint])
101-
add_constraint! = add_constraints!
100+
const add_constraint! = add_constraints!
102101

103102
# caches conic form of x when x is the solution to the optimization problem p
104103
function cache_conic_form!(conic_forms::UniqueConicForms, x::AbstractExpr, p::Problem)

test/test_utilities.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,23 @@ using Convex: AbstractExpr, ConicObj
274274
@test_logs Convex.NotDcp()
275275
Convex.DCP_WARNINGS[] = true
276276
@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
278295
end
279296
end

0 commit comments

Comments
 (0)