Skip to content

Commit

Permalink
add test for a simple quadratic function
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoladicicco committed Jul 22, 2024
1 parent af5e884 commit 1f928de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function armijo_line_search(f, x, d, fx, xmin, xmax; α0 = 1.0, β = 0.5, c = 1e
end

"""
_coordinate_descent!(s, x)
_coordinate_descent_move!(s, x)
Runs an iteration of coordinate descent over axis "x".
The derivative is (temporarily?) computed via finite difference.
Expand Down Expand Up @@ -412,6 +412,7 @@ function _step!(s)
x = _select_worse(s)
_verbose(s, "Selected x = $x")

# TODO: this if statement is currently not working, every variable is treated as integer
if get_domain(s, x) isa ContinuousDomain
# We perform coordinate descent over the variable axis
best_values, best_swap, tabu = _coordinate_descent_move!(s, x)
Expand Down
26 changes: 24 additions & 2 deletions test/raw_solver.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Intervals

function mincut(graph; source, sink, interdiction = 0)
m = model(; kind = :cut)
n = size(graph, 1)
Expand Down Expand Up @@ -117,6 +115,20 @@ function chemical_equilibrium(A, B, C)
return m
end

function sum_squares(n)
m = model(; kind = :sum_squares)

d = domain(-10.0 .. 10.0)

foreach(_ -> variable!(m, d), 1:n)

ss = x -> sum(j -> j * x[j] * x[j], 1:n)

objective!(m, ss)

return m
end

@testset "Raw solver: internals" begin
models = [
sudoku(2)
Expand Down Expand Up @@ -248,3 +260,13 @@ end
display(solution(s))
display(s.time_stamps)
end

@testset "Raw solver: sum squares" begin
# Sanity check: simple quadratic function with a trivial minimum at 0
n = 10
m = sum_squares(n)
s = solver(m; options = Options(print_level = :minimal))
solve!(s)
display(solution(s))
display(s.time_stamps)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ConstraintDomains
import CompositionalNetworks
@everywhere using Constraints
using Dictionaries
using Intervals
@everywhere using LocalSearchSolvers
using Test
using TestItemRunner
Expand Down

0 comments on commit 1f928de

Please sign in to comment.