HPRLP-C Julia Interface
Source: official HPR-LP-C documentation.
Julia interface for HPR-LP-C 0.1.3. The build detects the GPU architecture;
CUDA 13.3+ uses cusparseSpMVOp, while older toolkits use cusparseSpMV.
Installation
cd bindings/julia
bash install.sh
This script compiles the backend and installs the Julia package of HPR-LP-C locally.
Examples
Example 1: Build model directly from matrices
cd examples
julia --project=../package example_direct_lp.jl
Quick overview: The following snippet demonstrates how to define and solve a small LP problem directly from matrices. For a complete version with additional options, see example_direct_lp.jl.
using HPRLP
using SparseArrays
# Define LP: minimize c'x subject to AL ≤ A*x ≤ AU, l ≤ x ≤ u
A = sparse([1.0 2.0; 3.0 1.0])
AL = [-Inf, -Inf]
AU = [10.0, 12.0]
l = [0.0, 0.0]
u = [Inf, Inf]
c = [-3.0, -5.0]
# Create model
model = Model(A, AL, AU, l, u, c)
# Configure solver parameters
params = Parameters(
stop_tol = 1e-9,
device_number = 0
)
# Solve
result = solve(model, params)
if is_optimal(result)
println("Optimal objective: ", result.primal_obj)
println("Optimal solution: ", result.x)
end
Model(A, AL, AU, l, u, c)
Create an LP model directly from matrices and vectors.
Argument |
Description |
|---|---|
|
Sparse constraint matrix (m×n) |
|
Constraint bounds |
|
Variable bounds |
|
Objective coefficients |
Returns: Model object
Example 2: Read model from an MPS file
cd examples
julia --project=../package example_mps_file.jl
Quick overview: The following snippet demonstrates how to define and solve an LP problem directly from an MPS file. For a complete version with additional options, see example_mps_file.jl.
using HPRLP
# Create model from MPS file
model = Model("problem.mps")
# Solve
result = solve(model)
println(result)
Model(filename::String)
Create an LP model by reading an MPS file.
Argument |
Description |
|---|---|
|
Path to the MPS file |
Returns: Model object
solve(model::Model, params=nothing)
Solve the given LP model.
Argument |
Description |
|---|---|
|
LP model object |
|
Optional solver parameters |
Returns |
|
Example 3: Use JuMP to construct and solve LPs
cd examples
julia --project=../package example_jump.jl
Parameters
Solver configuration options (specified as keyword arguments):
Parameter |
Description |
Default |
|---|---|---|
|
Maximum iterations |
Unlimited |
|
Stopping tolerance |
|
|
Time limit in seconds |
|
|
CUDA device ID |
|
|
Convergence check interval |
|
|
Force the cuSPARSE SpMVOp path and disable fused-kernel autotuning |
|
|
Print backend autotuning diagnostics when fused kernels are enabled |
|
|
Apply Ruiz scaling |
|
|
Apply Pock–Chambolle scaling |
|
|
Apply bounds/cost scaling |
|
|
Apply embedded PSLP presolve/postsolve in the C core |
|
Results
The Results object contains solution and performance information after solving the LP:
Field |
Description |
|---|---|
|
Solver status: |
|
Primal solution |
|
Dual solution |
|
Bound-dual solution |
|
Primal objective value |
|
Duality gap |
|
Final KKT residual |
|
Total iterations |
|
Solve time (seconds) |
|
Iterations to reach 1e-4/1e-6/1e-8 tolerance |
|
Time to reach corresponding tolerance |
BatchedResults
Field |
Description |
|---|---|
|
Per-instance solver statuses |
|
Primal and bound-dual matrices shaped |
|
Dual matrix shaped |
|
Per-instance vectors |
|
Batched timing fields |