Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ function _literate_directory(dir)
end
end
for filename in _file_list(dir, dir, ".jl")
# `include` the file to test it before `#src` lines are removed. It is
# in a testset to isolate local variables between files.
Test.@testset "$(filename)" begin
_include_sandbox(filename)
end
Literate.markdown(
filename,
dir;
Expand Down
10 changes: 4 additions & 6 deletions docs/src/tutorials/algorithms/benders_decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ set_silent(model)
@constraint(model, [i = 2:(n-1)], sum(y[i, :]) == sum(y[:, i]))
@objective(model, Min, 0.1 * sum(x) - sum(y[1, :]))
optimize!(model)
assert_is_solved_and_feasible(model) #src
assert_is_solved_and_feasible(model)
solution_summary(model)

# The optimal objective value is -5.1:

Test.@test isapprox(objective_value(model), -5.1; atol = 1e-4) #src
Test.@test isapprox(objective_value(model), -5.1; atol = 1e-4)
objective_value(model)

# and the optimal flows are:
Expand Down Expand Up @@ -434,8 +434,7 @@ inplace_solution = optimal_flows(optimal_ret.y)

# which is the same as the monolithic solution:

Test.@test inplace_solution == monolithic_solution #src
inplace_solution == monolithic_solution
Test.@test inplace_solution == monolithic_solution

# ## Feasibility cuts

Expand Down Expand Up @@ -541,5 +540,4 @@ feasible_inplace_solution = optimal_flows(optimal_ret.y)
# which is the same as the monolithic solution (because `sum(y) >= 1` in the
# monolithic solution):

Test.@test feasible_inplace_solution == monolithic_solution #src
feasible_inplace_solution == monolithic_solution
Test.@test feasible_inplace_solution == monolithic_solution
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import DataFrames
import HiGHS
import Plots
import SparseArrays
import Test #src
import Test

# ## Background

Expand Down Expand Up @@ -236,8 +236,8 @@ set_silent(model)
@constraint(model, demand[i in 1:I], patterns[i]' * x >= data.pieces[i].d)
optimize!(model)
assert_is_solved_and_feasible(model)
Test.@test isapprox(objective_value(model), 386; atol = 1e-6)
solution_summary(model)
Test.@test isapprox(objective_value(model), 386; atol = 1e-6) #src

# This solution requires 386 rolls. This solution is sub-optimal because the
# model does not contain the full set of possible patterns.
Expand Down Expand Up @@ -359,8 +359,7 @@ filter!(row -> row.rolls > 0, solution)
# solutions. We can create a integer feasible solution by rounding up the
# orders. This requires 306 rolls:

Test.@test sum(ceil.(Int, solution.rolls)) == 306 #src
sum(ceil.(Int, solution.rolls))
Test.@test sum(ceil.(Int, solution.rolls)) == 306

# Alternatively, we can re-introduce the integrality constraints and resolve the
# problem:
Expand All @@ -375,7 +374,7 @@ filter!(row -> row.rolls > 0, solution)

# This now requires 299 rolls:

Test.@test isapprox(sum(solution.rolls), 299; atol = 1e-6) #src
Test.@test isapprox(sum(solution.rolls), 299; atol = 1e-6)
sum(solution.rolls)

# Note that this may not be the global minimum because we are not adding new
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/applications/optimal_power_flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ set_silent(model)
# real power range (all 10, as it turns out in this case):

basic_lower_bound = value(lower_bound, objective_function(model));
Test.@test isapprox(basic_lower_bound, 1188.75; atol = 1e-2) #src
Test.@test isapprox(basic_lower_bound, 1188.75; atol = 1e-2)
println("Objective value (basic lower bound) : $basic_lower_bound")

# to see that we can do no better than an objective cost of 1188.75.
Expand Down Expand Up @@ -282,7 +282,7 @@ P_G = real(S_G)

optimize!(model)
assert_is_solved_and_feasible(model)
Test.@test isapprox(objective_value(model), 3087.84; atol = 1e-2) #src
Test.@test isapprox(objective_value(model), 3087.84; atol = 1e-2)
solution_summary(model)

#-
Expand Down Expand Up @@ -422,7 +422,7 @@ optimize!(model)

assert_is_solved_and_feasible(model; allow_almost = true)
sdp_relaxation_lower_bound = round(objective_value(model); digits = 2)
Test.@test isapprox(sdp_relaxation_lower_bound, 2753.04; rtol = 1e-3) #src
Test.@test isapprox(sdp_relaxation_lower_bound, 2753.04; rtol = 1e-3)
println(
"Objective value (W & V relax. lower bound): $sdp_relaxation_lower_bound",
)
Expand Down
8 changes: 4 additions & 4 deletions docs/src/tutorials/conic/arbitrary_precision.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using JuMP
import CDDLib
import Clarabel
import Test #src
import Test

# ## Higher-precision arithmetic

Expand Down Expand Up @@ -102,7 +102,7 @@ value.(x) .- [3 // 7, 3 // 14]

# The primal feasibility violation is on the order of `1e-16`

Test.@test 1e-16 <= maximum(values(primal_feasibility_report(model))) <= 1e-15 #src
Test.@test 1e-16 <= maximum(values(primal_feasibility_report(model))) <= 1e-15
primal_feasibility_report(model)

# But by reducing the tolerances, we can obtain a more accurate solution:
Expand All @@ -116,7 +116,7 @@ value.(x) .- [3 // 7, 3 // 14]

# The primal feasibility violation is also much smaller:

Test.@test maximum(values(primal_feasibility_report(model))) < 1e-30 #src
Test.@test maximum(values(primal_feasibility_report(model))) < 1e-30
primal_feasibility_report(model)

# ## Rational arithmetic
Expand Down Expand Up @@ -176,5 +176,5 @@ value(c2)
# Because the solution is in exact arithmetic, there are no primal
# infeasibilities:

Test.@test isempty(primal_feasibility_report(model)) #src
Test.@test isempty(primal_feasibility_report(model))
primal_feasibility_report(model)
4 changes: 2 additions & 2 deletions docs/src/tutorials/conic/ellipse_approx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ f = [1 - S[i, :]' * Z * S[i, :] + 2 * S[i, :]' * z - s for i in 1:m]
@objective(model, Max, 1 * t + 0)
optimize!(model)
assert_is_solved_and_feasible(model)
Test.@test isapprox(D, value.(Z); atol = 1e-3) #src
Test.@test isapprox(D, value.(Z); atol = 1e-3)
solve_time_1 = solve_time(model)

# This formulation gives the much smaller graph:
Expand Down Expand Up @@ -242,7 +242,7 @@ f = [1 - S[i, :]' * Z * S[i, :] + 2 * S[i, :]' * z - s for i in 1:m]
@objective(model, Max, 1 * t + 0)
optimize!(model)
assert_is_solved_and_feasible(model)
Test.@test isapprox(D, value.(Z); atol = 1e-3) #src
Test.@test isapprox(D, value.(Z); atol = 1e-3)
solve_time_2 = solve_time(model)

# This formulation gives the much smaller graph:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/conic/min_ellipse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ q = P \ value.(P_q)
# Finally, overlaying the solution in the plot we see the minimal area enclosing
# ellipsoid:

Test.@test isapprox(P, [0.4237 -0.0396; -0.0396 0.3163]; atol = 1e-2) #src
Test.@test isapprox(q, [-0.3960, -0.0214]; atol = 1e-2) #src
Test.@test isapprox(P, [0.4237 -0.0396; -0.0396 0.3163]; atol = 1e-2)
Test.@test isapprox(q, [-0.3960, -0.0214]; atol = 1e-2)

Plots.plot!(
plot,
Expand Down
8 changes: 4 additions & 4 deletions docs/src/tutorials/conic/simple_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function example_k_means_clustering()
assert_is_solved_and_feasible(model)
Z_val = value.(Z)
current_cluster, visited = 0, Set{Int}()
solution = [1, 1, 2, 1, 2, 2] #src
solution = [1, 1, 2, 1, 2, 2]
for i in 1:m
if !(i in visited)
current_cluster += 1
Expand All @@ -175,7 +175,7 @@ function example_k_means_clustering()
if isapprox(Z_val[i, i], Z_val[i, j]; atol = 1e-3)
println(a[j])
push!(visited, j)
Test.@test solution[j] == current_cluster #src
Test.@test solution[j] == current_cluster
end
end
end
Expand Down Expand Up @@ -218,12 +218,12 @@ function example_correlation_problem()
optimize!(model)
assert_is_solved_and_feasible(model)
println("An upper bound for ρ_AC is $(value(ρ["A", "C"]))")
Test.@test value(ρ["A", "C"]) ≈ 0.87195 atol = 1e-4 #src
Test.@test value(ρ["A", "C"]) ≈ 0.87195 atol = 1e-4
@objective(model, Min, ρ["A", "C"])
optimize!(model)
assert_is_solved_and_feasible(model)
println("A lower bound for ρ_AC is $(value(ρ["A", "C"]))")
Test.@test value(ρ["A", "C"]) ≈ -0.978 atol = 1e-3 #src
Test.@test value(ρ["A", "C"]) ≈ -0.978 atol = 1e-3
return
end

Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/getting_started/sum_if.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ nodes, edges, demand = build_random_graph(1_000, 2_000)
run_times = Float64[]
factors = 1:10
for factor in factors
GC.gc() #src
GC.gc()
graph = build_random_graph(1_000 * factor, 5_000 * factor)
push!(run_times, @elapsed build_naive_model(graph...))
end
Expand Down Expand Up @@ -217,7 +217,7 @@ run_times_naive = Float64[]
run_times_cached = Float64[]
factors = 1:10
for factor in factors
GC.gc() #src
GC.gc()
graph = build_random_graph(1_000 * factor, 5_000 * factor)
push!(run_times_naive, @elapsed build_naive_model(graph...))
push!(run_times_cached, @elapsed build_cached_model(graph...))
Expand Down
19 changes: 9 additions & 10 deletions docs/src/tutorials/getting_started/tolerances.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ set_silent(model)
@variable(model, x >= 0)
@constraint(model, x == -1e-8)
optimize!(model)
assert_is_solved_and_feasible(model) #src
assert_is_solved_and_feasible(model)
is_solved_and_feasible(model)

#-
Expand All @@ -122,7 +122,7 @@ value(x)

set_attribute(model, "primal_feasibility_tolerance", 1e-10)
optimize!(model)
@assert !is_solved_and_feasible(model) #src
@assert !is_solved_and_feasible(model)
is_solved_and_feasible(model)

# ### Realistic example
Expand All @@ -142,7 +142,7 @@ optimize!(model)

# SCS reports that it solved the problem to optimality:

assert_is_solved_and_feasible(model) #src
assert_is_solved_and_feasible(model)
is_solved_and_feasible(model)

# and that the solution for `x[1]` is nearly zero:
Expand Down Expand Up @@ -199,7 +199,6 @@ optimize!(model)

#-

assert_is_solved_and_feasible(model) #src
assert_is_solved_and_feasible(model)
value(x[1])

Expand Down Expand Up @@ -234,12 +233,12 @@ set_attribute(model, "presolve", "off")
set_attribute(model, "mip_heuristic_run_feasibility_jump", false)
@variable(model, x == 1 + 1e-6, Int)
optimize!(model)
assert_is_solved_and_feasible(model) #src
assert_is_solved_and_feasible(model)
is_solved_and_feasible(model)

# HiGHS found an optimal solution, and the value of `x` is:

@assert isapprox(value(x), 1.000001) #src
@assert isapprox(value(x), 1.000001)
value(x)

# In other words, HiGHS thinks that the solution `x = 1.000001` satisfies the
Expand All @@ -255,7 +254,7 @@ primal_feasibility_report(model)

set_attribute(model, "mip_feasibility_tolerance", 1e-10)
optimize!(model)
@assert !is_solved_and_feasible(model) #src
@assert !is_solved_and_feasible(model)
is_solved_and_feasible(model)

# ### Realistic example
Expand Down Expand Up @@ -348,7 +347,7 @@ set_silent(model)
@variable(model, y >= 0)
@constraint(model, x + 1e8 * y == -1)
optimize!(model)
@assert !is_solved_and_feasible(model) #src
@assert !is_solved_and_feasible(model)
is_solved_and_feasible(model)

# The feasible solution `(x, y) = (0.0, -1e-8)` has a maximum primal violation
Expand All @@ -371,7 +370,7 @@ set_silent(model)
@constraint(model, y <= 0.5)
@constraint(model, x <= M * y)
optimize!(model)
@assert !is_solved_and_feasible(model) #src
@assert !is_solved_and_feasible(model)
is_solved_and_feasible(model)

# HiGHS reports the problem is infeasible, but there is a feasible (to
Expand All @@ -394,7 +393,7 @@ set_start_value(y, 1e-6)
# Now HiGHS will report that the problem is feasible:

optimize!(model)
assert_is_solved_and_feasible(model) #src
assert_is_solved_and_feasible(model)
is_solved_and_feasible(model)

# ## Problem is optimal, solution is infeasible
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/linear/cannery.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ solution_summary(model)
# What's the optimal shipment?

assert_is_solved_and_feasible(model)
Test.@test isapprox(objective_value(model), 1_680.0, atol = 1e-6) #src
Test.@test isapprox(objective_value(model), 1_680.0, atol = 1e-6)
for p in P, m in M
println(p, " => ", m, ": ", value(x[p, m]))
end
6 changes: 3 additions & 3 deletions docs/src/tutorials/linear/factory_schedule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import CSV
import DataFrames
import HiGHS
import StatsPlots
import Test #src
import Test

# ## Formulation

Expand Down Expand Up @@ -209,8 +209,8 @@ end

solution = solve_factory_scheduling(demand_df, factory_df);

Test.@test solution.termination_status == OPTIMAL #src
Test.@test solution.cost == 12_906_400.0 #src
Test.@test solution.termination_status == OPTIMAL
Test.@test solution.cost == 12_906_400.0

# Let's see what `solution` contains:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/linear/multi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ end

optimize!(model)
assert_is_solved_and_feasible(model)
Test.@test objective_value(model) == 225_700.0 #src
Test.@test objective_value(model) == 225_700.0
solution_summary(model)

# and print the solution:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/linear/multi_objective_project_planning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import DataFrames
import HiGHS
import MultiObjectiveAlgorithms as MOA
import Plots
import Test #src
import Test

# ## Background

Expand Down Expand Up @@ -132,7 +132,7 @@ optimize!(model)

# The algorithm found 21 non-dominated solutions:

Test.@test result_count(model) == 21 #src
Test.@test result_count(model) == 21
solution_summary(model)

# The [`objective_bound`](@ref) is the ideal point, that is, a lower bound on
Expand Down
Loading