Skip to content

Commit

Permalink
Various minor maintenance changes (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jun 9, 2023
1 parent 2aaaa90 commit 87f8884
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
os: [ubuntu-latest, macOS-latest, windows-latest]
arch: [x64]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="0.15.11"))
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
using JuliaFormatter
format(".", verbose=true)
out = String(read(Cmd(`git diff`)))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You can either store the license in the `PATH_LICENSE_STRING` environment
variable, or you can use the `PATHSolver.c_api_License_SetString` function
immediately after importing the `PATHSolver` package:
```julia
using PATHSolver
import PATHSolver
PATHSolver.c_api_License_SetString("<LICENSE STRING>")
```
where `<LICENSE STRING>` is replaced by the current license string.
Expand Down Expand Up @@ -158,7 +158,7 @@ Here is the same example using `PATHSolver.solve_mcp`. Note that you must
manually construct the sparse Jacobian callback.

```julia
julia> using PATHSolver
julia> import PATHSolver

julia> M = [
0 0 -1 -1
Expand Down
6 changes: 0 additions & 6 deletions deps/.gitignore

This file was deleted.

9 changes: 7 additions & 2 deletions src/C_API.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2016 Changhyun Kwon, Oscar Dowson, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

# PATH uses the Float64 value 1e20 to represent +infinity.
const INFINITY = 1e20

Expand Down Expand Up @@ -665,7 +670,7 @@ where:
chosen by the user as the `nnz` argumennt to `solve_mcp`.
* `x` is the value of the decision variables at which to evaluate the Jacobian.
The remainning arguments, `col`, `len`, `row`, and `data`, specifiy a sparse
The remaining arguments, `col`, `len`, `row`, and `data`, specify a sparse
column representation of the Jacobian matrix. These must be filled in by your
function.
Expand Down Expand Up @@ -892,9 +897,9 @@ function solve_mcp(
lb::Vector{Cdouble},
ub::Vector{Cdouble},
z::Vector{Cdouble};
nnz = SparseArrays.nnz(M),
kwargs...,
)
nnz = SparseArrays.nnz(M)
return solve_mcp(
_linear_function(M, q),
_linear_jacobian(M),
Expand Down
18 changes: 13 additions & 5 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const MOI = MathOptInterface
# Copyright (c) 2016 Changhyun Kwon, Oscar Dowson, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

MOI.Utilities.@model(
Optimizer,
Expand Down Expand Up @@ -68,8 +71,12 @@ A full list of options can be found at http://pages.cs.wisc.edu/~ferris/path/opt
### Example
optimizer = PATH.Optimizer()
MOI.set(optimizer, MOI.RawOptimizerAttribute("output"), "no")
```julia
import PATHSolver
import MathOptInterface as MOI
model = PATHSolver.Optimizer()
MOI.set(model, MOI.RawOptimizerAttribute("output"), "no")
```
"""
function Optimizer()
model = Optimizer{Float64}()
Expand Down Expand Up @@ -210,7 +217,7 @@ function _F_linear_operator(model::Optimizer)
M[row_i, s_term.variable.value] += s_term.coefficient
end
end
return M, q
return M, q, SparseArrays.nnz(M)
end

_finite(x, y) = isfinite(x) ? x : y
Expand All @@ -233,13 +240,14 @@ end
function MOI.optimize!(model::Optimizer)
model.ext[:solution] = nothing
lower, upper, initial = _bounds_and_starting(model)
M, q = _F_linear_operator(model)
M, q, nnz = _F_linear_operator(model)
status, x, info = solve_mcp(
M,
q,
lower,
upper,
initial;
nnz = nnz,
silent = model.ext[:silent],
jacobian_structure_constant = true,
jacobian_data_contiguous = true,
Expand Down
7 changes: 6 additions & 1 deletion src/PATHSolver.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Copyright (c) 2016 Changhyun Kwon, Oscar Dowson, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module PATHSolver

import DataDeps
import MathOptInterface
import MathOptInterface as MOI
import SparseArrays

function __init__()
Expand Down
10 changes: 8 additions & 2 deletions test/C_API.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Copyright (c) 2016 Changhyun Kwon, Oscar Dowson, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module TestCAPI

using PATHSolver
using SparseArrays
using Test

import PATHSolver
import SparseArrays

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
Expand Down
11 changes: 8 additions & 3 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Copyright (c) 2016 Changhyun Kwon, Oscar Dowson, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module TestMOIWrapper

using PATHSolver
using Test

using MathOptInterface
const MOI = MathOptInterface
import MathOptInterface as MOI
import PATHSolver

function runtests()
for name in names(@__MODULE__; all = true)
Expand Down Expand Up @@ -49,6 +53,7 @@ function test_infeasible()
@test MOI.get(model, MOI.TerminationStatus()) == MOI.INVALID_MODEL
@test MOI.get(model, MOI.RawStatusString()) == "Problem has a bound error"
@test MOI.get(model, MOI.PrimalStatus()) == MOI.UNKNOWN_RESULT_STATUS
return
end

function test_ZeroOne()
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Copyright (c) 2016 Changhyun Kwon, Oscar Dowson, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

using Test

@testset "PATH" begin
Expand Down

0 comments on commit 87f8884

Please sign in to comment.