Skip to content

Commit bf51e71

Browse files
Apply suggestions from code review
Co-authored-by: Andrew Winters <andrew.ross.winters@liu.se>
1 parent 06f04b3 commit bf51e71

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1111

1212
[weakdeps]
1313
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
14-
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
1514
KernelInterpolation = "95686e15-3c94-4443-8f08-76d06d509f7b"
1615
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
16+
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
1717

1818
[extensions]
19-
MathOptInterfaceHiGHSExt = ["HiGHS", "MathOptInterface"]
2019
KernelInterpolationExt = "KernelInterpolation"
2120
MakieExt = "Makie"
21+
MathOptInterfaceHiGHSExt = ["HiGHS", "MathOptInterface"]
2222

2323
[compat]
2424
Downloads = "1.6"
2525
HiGHS = "1.0"
26-
MathOptInterface = "1.0"
2726
KernelInterpolation = "0.3.5"
2827
LinearAlgebra = "1"
2928
Makie = "0.21, 0.22, 0.24"
29+
MathOptInterface = "1.0"
3030
SparseArrays = "1"
3131
StaticArrays = "1.9"
3232
julia = "1.10"

docs/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
33
Changelog = "5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
44
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
55
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
6-
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
76
KernelInterpolation = "95686e15-3c94-4443-8f08-76d06d509f7b"
7+
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
88
OrdinaryDiffEqLowStorageRK = "b0944070-b475-4768-8dec-fb6eb410534d"
99
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
1010
TrixiBottomTopography = "86af9953-43df-404b-8eaa-d20d82623a82"
@@ -18,8 +18,8 @@ CairoMakie = "0.13, 0.15"
1818
Changelog = "1.1"
1919
Documenter = "1.3"
2020
HiGHS = "1.0"
21-
MathOptInterface = "1.0"
2221
KernelInterpolation = "0.3.5"
22+
MathOptInterface = "1.0"
2323
OrdinaryDiffEqLowStorageRK = "1.3"
2424
Trixi = "0.12, 0.13, 0.14, 0.15, 0.16"
2525
TrixiShallowWater = "0.2"

ext/MathOptInterfaceHiGHSExt.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ function LaverySpline1DModel(len::Int, delta_y::Vector{T}, lambda::T,
7878
MOI.set(model,
7979
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
8080
MOI.ScalarAffineFunction{T}(obj_terms, zero(T)))
81+
# Indicate that the objective function should be minimized
8182
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
8283

8384
# constraints
84-
# abs_E[i,k] constraints
85+
# Build constraints from abs(aa[k] * b[i] + bb[k] * b[i + 1] - cc[k] * delta_y[i])
86+
# which are nonlinear. Convert into linear constraints by considering each side
87+
# of the inequality separately.
8588
buf3 = Vector{MOI.ScalarAffineTerm{T}}(undef, 3)
8689
for i in 1:n_sum, k in 1:integral_steps
8790
s = vars[abs_E_idx(i, k)]
@@ -104,7 +107,7 @@ function LaverySpline1DModel(len::Int, delta_y::Vector{T}, lambda::T,
104107
MOI.GreaterThan(cc[k] * delta_y[i]))
105108
end
106109

107-
# abs_b[i] constraints
110+
# Then come the remaining constraints on the sign of `abs_b[i]`
108111
buf2 = Vector{MOI.ScalarAffineTerm{T}}(undef, 2)
109112
for i in 1:n_b
110113
s = vars[abs_b_idx(i)]
@@ -356,11 +359,8 @@ function LaverySpline2D(x::Vector{T}, y::Vector{T}, z::Matrix{T};
356359
obj_terms = Vector{MOI.ScalarAffineTerm{T}}(undef, n_vars)
357360

358361
for k in 1:n_vars
359-
c = if k <= 2 * n * m
360-
lambda # bx or by block
361-
else
362-
one(T) # dxbx, dyby, dyxbx, dxyby blocks
363-
end
362+
# Assign `lambda` to bx or by block; `one(T)` to dxbx, dyby, dyxbx, dxyby blocks
363+
c = k <= 2 * n * m ? lambda : one(T)
364364
obj_terms[k] = MOI.ScalarAffineTerm{T}(c, vars[k])
365365
end
366366

0 commit comments

Comments
 (0)