MATLAB Version

This page shows how to use the MATLAB interface of HPR-LP: run demos, build custom problems, adjust solver settings, and interpret results.


Running examples

The demo LP problem is:

Test problem (LP)

The default demo problem we ship is a small linear program of the form

\[\begin{split} \begin{aligned} \min \quad & - 3 x_1 - 5 x_2\\ \text{s.t.} \quad & x_1 + 2 x_2 \le 10, \\ & 3 x_1 + x_2 \le 12, \\ & x_1 \ge 0, \\ & x_2 \ge 0. \end{aligned} \end{split}\]

Usage 1: Test Instances in MPS Format

Setting Data and Result Paths

Before running the scripts, please modify run_single_file.m or run_dataset.m in the scripts directory to specify the data path and result path according to your setup.

Running a Single Instance

To test the script on a single instance (.mps file):

% Set parameters (optional)
params = HPRLPParameters();
params.stoptol = 1e-4;
params.time_limit = 3600;

% Solve from MPS file
results = runFile('your_problem.mps', params);

% Check results
fprintf('Status: %s\n', results.output_type);
fprintf('Objective: %.6e\n', results.primal_obj);

Running All Instances in a Directory

To process all .mps files in a directory:

% Configure parameters
params = HPRLPParameters();
params.stoptol = 1e-4;
params.time_limit = 600;

% Run on all files in the directory
runDataset('/path/to/mps/files', '/path/to/results', params);

Usage 2: Define Your LP Model in MATLAB Scripts

Example 1: Define an LP Instance Directly in MATLAB

This example demonstrates how to construct and solve a linear programming problem directly in MATLAB without relying on MPS files.

run('demo/demo_Abc.m')

The script demonstrates:

  • Direct matrix-based LP formulation

  • Setting up the problem: min c'*x subject to AL A*x AU, l x u

  • Solving with HPR-LP

  • Accessing solution values

Example problem from the demo:

% Define LP: min -3*x1 - 5*x2
%     s.t. -x1 - 2*x2 >= -10
%          -3*x1 - x2 >= -12
%          x1 >= 0, x2 >= 0

A = sparse([-1 -2; -3 -1]);
AL = [-10; -12];
AU = [Inf; Inf];
c = [-3; -5];
l = [0; 0];
u = [Inf; Inf];
obj_constant = 0.0;

params = HPRLPParameters();
params.stoptol = 1e-4;

result = runAbc(A, c, AL, AU, l, u, obj_constant, params);

fprintf('Objective value: %.10f\n', result.primal_obj);
fprintf('x1 = %.10f\n', full(result.x(1)));
fprintf('x2 = %.10f\n', full(result.x(2)));

Parameters

Below is a list of the parameters in HPR-LP along with their default values and usage:

Parameter Default Value Description
time_limit3600Maximum allowed runtime (seconds) for the algorithm.
stoptol1e-4Stopping tolerance for convergence checks.
max_iterintmaxMaximum number of iterations allowed.
check_iter150Number of iterations to check residuals.
use_Ruiz_scalingtrueWhether to apply Ruiz scaling.
use_Pock_Chambolle_scalingtrueWhether to use the Pock-Chambolle scaling.
use_bc_scalingtrueWhether to use the scaling for b and c.
print_frequency-1 (auto)Print the log every print_frequency iterations.

Result Explanation

After solving an instance, you can access the result variables as shown below:

% Example from demo/demo_Abc.m
fprintf('Objective value: %.10f\n', result.primal_obj);
fprintf('x1 = %.10f\n', full(result.x(1)));
fprintf('x2 = %.10f\n', full(result.x(2)));
Category Variable Description
Iteration CountsiterTotal number of iterations performed by the algorithm.
iter_4Number of iterations required to achieve an accuracy of 1e-4.
iter_6Number of iterations required to achieve an accuracy of 1e-6.
iter_8Number of iterations required to achieve an accuracy of 1e-8.
Time MetricstimeTotal time in seconds taken by the algorithm.
time_4Time in seconds taken to achieve an accuracy of 1e-4.
time_6Time in seconds taken to achieve an accuracy of 1e-6.
time_8Time in seconds taken to achieve an accuracy of 1e-8.
power_timeTime in seconds used by the power method.
Objective Valuesprimal_objThe primal objective value obtained.
gapThe gap between the primal and dual objective values.
ResidualsresidualsRelative residuals of the primal feasibility, dual feasibility, and duality gap.
Algorithm Statusoutput_typeThe final status of the algorithm:
- OPTIMAL: Found optimal solution
- MAX_ITER: Max iterations reached
- TIME_LIMIT: Time limit reached
Solution VectorsxThe final solution vector x.
yThe final solution vector y.
zThe final solution vector z.