Skip to content

Commit

Permalink
remove x0
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffroyleconte authored and dpo committed Mar 16, 2024
1 parent 2dedd7d commit 410e0cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/qp_rand_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export qp_rand_model
using .QuadraticModels

"""
model, x0 = qp_rand_model(n; dens = 1.0e-4, convex = false)
model = qp_rand_model(n; dens = 1.0e-4, convex = false)
Return an instance of a `QuadraticModel` representing
Expand All @@ -16,20 +16,19 @@ with H = A + A' or H = A * A' (see the `convex` keyword argument) where A is a r
## Keyword arguments
* `dens :: Real`: density of `A`` used to generate the quadratic model (default: `1.0e-4`).
* `dens :: Real`: density of `A` with `0 < dens ≤ 1` used to generate the quadratic model (default: `1.0e-4`).
* `convex :: Bool`: true to generate positive definite `H` (default: `false`).
## Return Value
An instance of a `QuadraticModel`.
"""
function qp_rand_model(n::Int; dens::R = 1.0e-4, convex::Bool = false) where {R <: Real}
@assert 0 < dens 1
A = sprandn(R, n, n, dens)
H = convex ? (A * A') : (A + A')
c = randn(R, n)
l = -one(R) .- rand(R, n)
u = one(R) .+ rand(R, n)
qp = QuadraticModel(c, H; lvar = l, uvar = u)
x0 = zeros(R, n)
qp, x0
QuadraticModel(c, H; lvar = l, uvar = u, x0 = zeros(R, n))
end
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ end

@testset "QP-rand" begin
n, dens = 100, 0.1
model, x0 = qp_rand_model(n; dens = dens, convex = false)
model = qp_rand_model(n; dens = dens, convex = false)
@test all(-2.0 .≤ model.meta.lvar .≤ 0.0)
@test all(0.0 .≤ model.meta.uvar .≤ 2.0)
@test all(model.meta.x0 .== x0)
@test all(model.meta.x0 .== 0)

model, x0 = qp_rand_model(n; dens = dens, convex = true)
model = qp_rand_model(n; dens = dens, convex = true)
@test all(-2.0 .≤ model.meta.lvar .≤ 0.0)
@test all(0.0 .≤ model.meta.uvar .≤ 2.0)
@test all(model.meta.x0 .== x0)
@test all(model.meta.x0 .== 0)
end

0 comments on commit 410e0cc

Please sign in to comment.