| Title: | R Interface to the 'COIN-OR' 'Clp' Linear Programming Solver |
|---|---|
| Description: | Solves linear programs with 'Clp', the simplex and interior point code of the 'COIN-OR' project <https://github.com/coin-or/Clp>. Provides a one-call solver interface for dense and sparse constraint matrices, and complete low level bindings to the 'Clp' callable library covering problem construction, warm starts, presolve options, basis access and 'MPS' files. A compatibility layer reproduces the interface of the archived 'clpAPI' package so that existing code keeps working. 'Clp' itself is not bundled and must be installed on the system; the 'Rtools' toolchain supplies it on 'Windows', from 'Rtools' 4.3 on. |
| Authors: | Sam Lovick [aut, cre] |
| Maintainer: | Sam Lovick <[email protected]> |
| License: | EPL |
| Version: | 0.1.1 |
| Built: | 2026-09-16 09:57:35 UTC |
| Source: | https://github.com/samlovick/coinclp |
Add and delete rows and columns, clpAPI style
addRowsCLP(lp, nrows, lb, ub, rowst, cols, val) addColsCLP(lp, ncols, lb, ub, obj, colst, rows, val) delRowsCLP(lp, num, i) delColsCLP(lp, num, j)addRowsCLP(lp, nrows, lb, ub, rowst, cols, val) addColsCLP(lp, ncols, lb, ub, obj, colst, rows, val) delRowsCLP(lp, num, i) delColsCLP(lp, num, j)
lp |
A |
nrows, ncols
|
Number of rows or columns to add. |
lb, ub
|
Bounds for the new rows or columns. |
rowst, colst
|
Integer vectors of starts, length |
cols, rows
|
0-based indices of the new entries. |
val |
Numeric vector of the new entries. |
obj |
Objective coefficients for the new columns. |
num |
Number of rows or columns to delete. |
i, j
|
0-based positions to delete. |
NULL, invisibly.
lp <- initProbCLP() loadMatrixCLP(lp, 2, 0, c(0, 0, 0), integer(0), numeric(0)) addRowsCLP(lp, 1, -1e30, 4, c(0, 2), c(0, 1), c(1, 1)) getNumRowsCLP(lp) delProbCLP(lp)lp <- initProbCLP() loadMatrixCLP(lp, 2, 0, c(0, 0, 0), integer(0), numeric(0)) addRowsCLP(lp, 1, -1e30, 4, c(0, 2), c(0, 1), c(1, 1)) getNumRowsCLP(lp) delProbCLP(lp)
clp_add_rows() and clp_add_columns() extend a model with
entries given in compressed sparse form; clp_delete_rows() and
clp_delete_columns() remove them. All indices are 0-based.
clp_add_rows( model, number, rowlb = NULL, rowub = NULL, rowstarts, columns, elements ) clp_add_columns( model, number, collb = NULL, colub = NULL, obj = NULL, colstarts, rows, elements ) clp_delete_rows(model, which) clp_delete_columns(model, which)clp_add_rows( model, number, rowlb = NULL, rowub = NULL, rowstarts, columns, elements ) clp_add_columns( model, number, collb = NULL, colub = NULL, obj = NULL, colstarts, rows, elements ) clp_delete_rows(model, which) clp_delete_columns(model, which)
model |
A |
number |
Number of rows or columns being added. |
rowlb, rowub
|
Numeric vectors of bounds for the new rows, or |
rowstarts |
Integer vector of length |
columns |
Integer vector of 0-based column indices of the new entries. |
elements |
Numeric vector of matrix entries. |
collb, colub
|
Numeric vectors of bounds for the new columns, or |
obj |
Objective coefficients for the new columns, or |
colstarts |
Integer vector of length |
rows |
Integer vector of 0-based row indices of the new entries. |
which |
Integer vector of 0-based positions to delete. |
NULL, invisibly.
model <- clp_model() clp_load_problem(model, 2, 0, start = c(0L, 0L, 0L), index = integer(0), value = numeric(0), obj = c(1, 1)) clp_add_rows(model, 1, rowlb = -clp_inf(), rowub = 5, rowstarts = c(0L, 2L), columns = c(0L, 1L), elements = c(1, 1)) clp_num_rows(model) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 0, start = c(0L, 0L, 0L), index = integer(0), value = numeric(0), obj = c(1, 1)) clp_add_rows(model, 1, rowlb = -clp_inf(), rowub = 5, rowstarts = c(0L, 2L), columns = c(0L, 1L), elements = c(1, 1)) clp_num_rows(model) clp_free(model)
After a solve, these return the primal and dual solution.
clp_col_solution() is the primal solution, clp_reduced_costs()
the dual values on the columns, clp_row_activity() the row activities
and clp_row_price() the dual values (shadow prices) on the rows.
clp_col_solution(model) clp_reduced_costs(model) clp_row_activity(model) clp_row_price(model) clp_set_col_solution(model, value)clp_col_solution(model) clp_reduced_costs(model) clp_row_activity(model) clp_row_price(model) clp_set_col_solution(model, value)
model |
A |
value |
Numeric starting solution, one entry per column. |
A numeric vector, or NULL invisibly for the setter.
model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(-1, -1), rowub = 1) clp_initial_solve(model) clp_col_solution(model) clp_row_price(model) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(-1, -1), rowub = 1) clp_initial_solve(model) clp_col_solution(model) clp_row_price(model) clp_free(model)
Control parameters for clp_solve()
clp_control( log_level = 0L, algorithm = c("auto", "primal", "dual", "barrier", "barrier_nocross"), presolve = TRUE, max_iterations = NULL, max_seconds = NULL, primal_tolerance = NULL, dual_tolerance = NULL, scaling = NULL )clp_control( log_level = 0L, algorithm = c("auto", "primal", "dual", "barrier", "barrier_nocross"), presolve = TRUE, max_iterations = NULL, max_seconds = NULL, primal_tolerance = NULL, dual_tolerance = NULL, scaling = NULL )
log_level |
How much Clp prints: 0 silent (the default), up to 4. |
algorithm |
One of |
presolve |
Run Clp's presolve. Ignored when |
max_iterations |
Iteration limit, or |
max_seconds |
Time limit in seconds, or |
primal_tolerance, dual_tolerance
|
Simplex tolerances, or |
scaling |
Scaling mode: 0 off, 1 equilibrium, 2 geometric, 3 auto,
4 dynamic, or |
A list of control settings for clp_solve.
clp_control(algorithm = "dual", max_seconds = 10)clp_control(algorithm = "dual", max_seconds = 10)
Frees the solver memory behind a model. This happens automatically when the model is garbage collected; call it explicitly when working with many or large models. Calling it twice is harmless, but using the model afterwards is an error.
clp_free(model)clp_free(model)
model |
A |
NULL, invisibly.
model <- clp_model() clp_free(model) clp_is_open(model)model <- clp_model() clp_free(model) clp_is_open(model)
Clp represents an infinite bound by 1e30 rather than by Inf.
clp_inf() returns that value, and the high level interface
translates Inf and -Inf to it automatically.
clp_inf()clp_inf()
A single number, 1e30.
clp_inf()clp_inf()
The entry points of the Clp callable library. clp_initial_solve()
lets Clp choose the algorithm and applies presolve, which is the right
default for most problems; the others force a particular method.
clp_primal_simplex() and clp_dual_simplex() run the simplex
without presolve, which is what you want when re-solving a modified model
from a warm start.
clp_initial_solve(model) clp_initial_dual_solve(model) clp_initial_primal_solve(model) clp_initial_barrier_solve(model) clp_initial_barrier_no_cross_solve(model) clp_initial_solve_with_options(model, options) clp_primal_simplex(model, if_values_pass = 0L) clp_dual_simplex(model, if_values_pass = 0L) clp_idiot(model, try_hard = 0L) clp_crash(model, gap = 0, pivot = 0L)clp_initial_solve(model) clp_initial_dual_solve(model) clp_initial_primal_solve(model) clp_initial_barrier_solve(model) clp_initial_barrier_no_cross_solve(model) clp_initial_solve_with_options(model, options) clp_primal_simplex(model, if_values_pass = 0L) clp_dual_simplex(model, if_values_pass = 0L) clp_idiot(model, try_hard = 0L) clp_crash(model, gap = 0, pivot = 0L)
model |
A |
options |
A |
if_values_pass |
Pass 1 to start from the values in
|
try_hard |
Effort level for the idiot crash. |
gap |
Bound gap below which variables may be flipped by the crash. |
pivot |
Crash pivoting rule: 0 none, 1 simple, 2 mini iterations. |
An integer return code from Clp: 0 if it solved the problem,
1 if the problem is primal infeasible, 2 if dual infeasible, and other
values if it stopped early. clp_idiot() returns NULL
invisibly. Use clp_status for the status of the model
itself.
model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(-1, -2), rowub = 3) clp_set_log_level(model, 0L) clp_initial_solve(model) clp_objective_value(model) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(-1, -2), rowub = 3) clp_set_log_level(model, 0L) clp_initial_solve(model) clp_objective_value(model) clp_free(model)
Is a model still usable?
clp_is_open(model)clp_is_open(model)
model |
A |
TRUE if the model still holds a live Clp problem.
model <- clp_model() clp_is_open(model)model <- clp_model() clp_is_open(model)
Convenience predicates over the last solve, mirroring the OSI-style queries in the Clp callable library.
clp_is_proven_optimal(model) clp_is_proven_primal_infeasible(model) clp_is_proven_dual_infeasible(model) clp_is_abandoned(model) clp_is_primal_objective_limit_reached(model) clp_is_dual_objective_limit_reached(model) clp_is_iteration_limit_reached(model) clp_primal_feasible(model) clp_dual_feasible(model)clp_is_proven_optimal(model) clp_is_proven_primal_infeasible(model) clp_is_proven_dual_infeasible(model) clp_is_abandoned(model) clp_is_primal_objective_limit_reached(model) clp_is_dual_objective_limit_reached(model) clp_is_iteration_limit_reached(model) clp_primal_feasible(model) clp_dual_feasible(model)
model |
A |
A single logical value.
model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowlb = 1) clp_initial_solve(model) clp_is_proven_optimal(model) clp_free(model)model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowlb = 1) clp_initial_solve(model) clp_is_proven_optimal(model) clp_free(model)
Loads a complete linear program given by a column-major (compressed sparse
column) constraint matrix. This is the callable library's
Clp_loadProblem and takes 0-based indices.
clp_load_problem( model, ncols, nrows, start, index, value, collb = NULL, colub = NULL, obj = NULL, rowlb = NULL, rowub = NULL )clp_load_problem( model, ncols, nrows, start, index, value, collb = NULL, colub = NULL, obj = NULL, rowlb = NULL, rowub = NULL )
model |
A |
ncols |
Number of columns (variables). |
nrows |
Number of rows (constraints). |
start |
Integer vector of length |
index |
Integer vector of 0-based row indices, one per matrix entry. |
value |
Numeric vector of matrix entries. |
collb, colub
|
Numeric vectors of column bounds, or |
obj |
Numeric vector of objective coefficients, or |
rowlb, rowub
|
Numeric vectors of row bounds, or |
Any of the bound and objective arguments may be NULL, in which case
Clp applies its defaults: columns get [0, Inf) bounds and a zero
objective, rows get (-Inf, Inf).
NULL, invisibly. The model is modified in place.
clp_solve, which builds this representation from an
ordinary R matrix.
# maximise 2x + 3y subject to x + y <= 4, x + 3y <= 6 model <- clp_model() clp_load_problem(model, ncols = 2, nrows = 2, start = c(0L, 2L, 4L), index = c(0L, 1L, 0L, 1L), value = c(1, 1, 1, 3), collb = c(0, 0), colub = c(clp_inf(), clp_inf()), obj = c(-2, -3), rowlb = c(-clp_inf(), -clp_inf()), rowub = c(4, 6)) clp_initial_solve(model) clp_col_solution(model) clp_free(model)# maximise 2x + 3y subject to x + y <= 4, x + 3y <= 6 model <- clp_model() clp_load_problem(model, ncols = 2, nrows = 2, start = c(0L, 2L, 4L), index = c(0L, 1L, 0L, 1L), value = c(1, 1, 1, 3), collb = c(0, 0), colub = c(clp_inf(), clp_inf()), obj = c(-2, -3), rowlb = c(-clp_inf(), -clp_inf()), rowub = c(4, 6)) clp_initial_solve(model) clp_col_solution(model) clp_free(model)
Attaches a quadratic term to the objective, in column-major form. Clp
itself only solves such models with its quadratic simplex; most users want
the linear objective set by clp_set_objective.
clp_load_quadratic_objective(model, ncols, start, column, element)clp_load_quadratic_objective(model, ncols, start, column, element)
model |
A |
ncols |
Number of columns in the quadratic term. |
start |
Integer vector of 0-based column starts, length |
column |
Integer vector of 0-based column indices. |
element |
Numeric vector of coefficients. |
NULL, invisibly.
model <- clp_model() clp_load_problem(model, 1, 0, start = c(0L, 0L), index = integer(0), value = numeric(0)) clp_load_quadratic_objective(model, 1, c(0L, 1L), 0L, 2) clp_free(model)model <- clp_model() clp_load_problem(model, 1, 0, start = c(0L, 0L), index = integer(0), value = numeric(0)) clp_load_quadratic_objective(model, 1, c(0L, 1L), 0L, 2) clp_free(model)
clp_log_level() controls how much Clp prints: 0 silent, 1 just the
final line, 2 factorizations, 3 more, 4 verbose. clp_scaling()
selects the scaling mode (0 off, 1 equilibrium, 2 geometric, 3 auto,
4 dynamic). clp_perturbation() and clp_algorithm() expose
the corresponding simplex settings.
clp_log_level(model) clp_set_log_level(model, value) clp_scaling(model) clp_set_scaling(model, value) clp_perturbation(model) clp_set_perturbation(model, value) clp_algorithm(model) clp_set_algorithm(model, value) clp_iterations(model) clp_set_iterations(model, value)clp_log_level(model) clp_set_log_level(model, value) clp_scaling(model) clp_set_scaling(model, value) clp_perturbation(model) clp_set_perturbation(model, value) clp_algorithm(model) clp_set_algorithm(model, value) clp_iterations(model) clp_set_iterations(model, value)
model |
A |
value |
The new value. |
The getters return an integer; the setters NULL invisibly.
model <- clp_model() clp_set_log_level(model, 0L) clp_log_level(model) clp_free(model)model <- clp_model() clp_set_log_level(model, 0L) clp_log_level(model) clp_free(model)
clp_matrix() returns the constraint matrix as triplets with 1-based
positions, which is convenient in R. The other functions expose Clp's own
column-major arrays unchanged, with 0-based indices; note that the stored
matrix may contain gaps, so clp_vector_lengths() rather than the
differences of clp_vector_starts() gives the entries per column.
clp_matrix(model) clp_vector_starts(model) clp_vector_lengths(model) clp_indices(model) clp_elements(model)clp_matrix(model) clp_vector_starts(model) clp_vector_lengths(model) clp_indices(model) clp_elements(model)
model |
A |
clp_matrix() returns a list with components i,
j, v, nrow and ncol. The others return the
corresponding Clp array.
model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 2), rowub = 3) clp_matrix(model) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 2), rowub = 3) clp_matrix(model) clp_free(model)
Creates an empty problem in the COIN-OR Clp callable library. The result
is an external pointer with class "clp_model"; the underlying
solver object is released when the model is garbage collected, or
immediately by clp_free.
clp_model()clp_model()
New models start silent, unlike Clp's own default: raise the message level
with clp_set_log_level to see the solver's reporting.
An object of class "clp_model".
clp_solve for a one-call interface that builds and
solves a model for you, clp_load_problem for filling a
model in yourself.
model <- clp_model() clp_num_cols(model) clp_free(model)model <- clp_model() clp_num_cols(model) clp_free(model)
Needs a Clp build that provides Clp_modifyCoefficient (1.18 or
later); check with clp_features().
clp_modify_coefficient(model, row, col, value, keep_zero = TRUE)clp_modify_coefficient(model, row, col, value, keep_zero = TRUE)
model |
A |
row, col
|
0-based row and column position. |
value |
New coefficient. |
keep_zero |
Keep the entry in the sparse structure when |
NULL, invisibly.
if (isTRUE(clp_features()[["modify_coefficient"]])) { model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, rowub = 1) clp_modify_coefficient(model, 0, 0, 2) clp_free(model) }if (isTRUE(clp_features()[["modify_coefficient"]])) { model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, rowub = 1) clp_modify_coefficient(model, 0, 0, 2) clp_free(model) }
Size of a model
clp_num_rows(model) clp_num_cols(model) clp_num_elements(model)clp_num_rows(model) clp_num_cols(model) clp_num_elements(model)
model |
A |
The number of rows, columns or stored matrix entries.
clp_num_elements() returns a double, since Clp counts entries in a
type that may exceed the range of an R integer.
model <- clp_model() clp_resize(model, 3, 4) c(clp_num_rows(model), clp_num_cols(model)) clp_free(model)model <- clp_model() clp_resize(model, 3, 4) c(clp_num_rows(model), clp_num_cols(model)) clp_free(model)
Read or replace the objective coefficients and the row and column bounds
of a model. The getters return Clp's own values, in which an infinite
bound is clp_inf() rather than Inf.
clp_objective(model) clp_col_lower(model) clp_col_upper(model) clp_row_lower(model) clp_row_upper(model) clp_set_objective(model, value) clp_set_col_lower(model, value) clp_set_col_upper(model, value) clp_set_row_lower(model, value) clp_set_row_upper(model, value)clp_objective(model) clp_col_lower(model) clp_col_upper(model) clp_row_lower(model) clp_row_upper(model) clp_set_objective(model, value) clp_set_col_lower(model, value) clp_set_col_upper(model, value) clp_set_row_lower(model, value) clp_set_row_upper(model, value)
model |
A |
value |
A numeric vector with one entry per column (objective and column bounds) or per row (row bounds). |
The getters return a numeric vector; the setters return NULL
invisibly.
model <- clp_model() clp_load_problem(model, 2, 0, start = c(0L, 0L, 0L), index = integer(0), value = numeric(0), obj = c(1, 2)) clp_objective(model) clp_set_objective(model, c(3, 4)) clp_objective(model) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 0, start = c(0L, 0L, 0L), index = integer(0), value = numeric(0), obj = c(1, 2)) clp_objective(model) clp_set_objective(model, c(3, 4)) clp_objective(model) clp_free(model)
Objective value and offset
clp_objective_value(model) clp_objective_offset(model) clp_set_objective_offset(model, value)clp_objective_value(model) clp_objective_offset(model) clp_set_objective_offset(model, value)
model |
A |
value |
A constant added to the objective. |
A number, or NULL invisibly for the setter.
model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = -1, rowub = 2) clp_initial_solve(model) clp_objective_value(model) clp_free(model)model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = -1, rowub = 2) clp_initial_solve(model) clp_objective_value(model) clp_free(model)
Clp stores the direction as a number: 1 to minimise, -1 to maximise and 0
to ignore the objective. clp_obj_sense() is Clp's OSI-style
spelling of the same setting.
clp_optimization_direction(model) clp_set_optimization_direction(model, value) clp_obj_sense(model) clp_set_obj_sense(model, value)clp_optimization_direction(model) clp_set_optimization_direction(model, value) clp_obj_sense(model) clp_set_obj_sense(model, value)
model |
A |
value |
1 (minimise), -1 (maximise) or 0 (ignore the objective). |
The getters return a number; the setters NULL invisibly.
model <- clp_model() clp_set_optimization_direction(model, -1) clp_optimization_direction(model) clp_free(model)model <- clp_model() clp_set_optimization_direction(model, -1) clp_optimization_direction(model) clp_free(model)
Creates a ClpSolve options object, the structure Clp uses to steer
clp_initial_solve_with_options. Options are set with the
clp_options_* functions.
clp_options()clp_options()
An external pointer with class "clp_options".
opts <- clp_options() clp_options_set_solve_type(opts, 1L) # primal simplex clp_options_get_solve_type(opts)opts <- clp_options() clp_options_set_solve_type(opts, 1L) # primal simplex clp_options_get_solve_type(opts)
Switch single presolve transformations on or off in a
clp_options object. Each getter returns Clp's current
setting for that transformation.
clp_options_do_dual(options) clp_options_set_do_dual(options, value) clp_options_do_singleton(options) clp_options_set_do_singleton(options, value) clp_options_do_doubleton(options) clp_options_set_do_doubleton(options, value) clp_options_do_tripleton(options) clp_options_set_do_tripleton(options, value) clp_options_do_tighten(options) clp_options_set_do_tighten(options, value) clp_options_do_forcing(options) clp_options_set_do_forcing(options, value) clp_options_do_implied_free(options) clp_options_set_do_implied_free(options, value) clp_options_do_dupcol(options) clp_options_set_do_dupcol(options, value) clp_options_do_duprow(options) clp_options_set_do_duprow(options, value) clp_options_do_singleton_column(options) clp_options_set_do_singleton_column(options, value) clp_options_presolve_actions(options) clp_options_set_presolve_actions(options, value) clp_options_substitution(options) clp_options_set_substitution(options, value) clp_options_infeasible_return(options) clp_options_set_infeasible_return(options, value)clp_options_do_dual(options) clp_options_set_do_dual(options, value) clp_options_do_singleton(options) clp_options_set_do_singleton(options, value) clp_options_do_doubleton(options) clp_options_set_do_doubleton(options, value) clp_options_do_tripleton(options) clp_options_set_do_tripleton(options, value) clp_options_do_tighten(options) clp_options_set_do_tighten(options, value) clp_options_do_forcing(options) clp_options_set_do_forcing(options, value) clp_options_do_implied_free(options) clp_options_set_do_implied_free(options, value) clp_options_do_dupcol(options) clp_options_set_do_dupcol(options, value) clp_options_do_duprow(options) clp_options_set_do_duprow(options, value) clp_options_do_singleton_column(options) clp_options_set_do_singleton_column(options, value) clp_options_presolve_actions(options) clp_options_set_presolve_actions(options, value) clp_options_substitution(options) clp_options_set_substitution(options, value) clp_options_infeasible_return(options) clp_options_set_infeasible_return(options, value)
options |
A |
value |
The new value; 0 or 1 for the switches. |
The getters return an integer; the setters NULL invisibly.
opts <- clp_options() clp_options_set_do_dual(opts, 1L) clp_options_do_dual(opts) clp_options_free(opts)opts <- clp_options() clp_options_set_do_dual(opts, 1L) clp_options_do_dual(opts) clp_options_free(opts)
Release a Clp options object
clp_options_free(options)clp_options_free(options)
options |
A |
NULL, invisibly.
opts <- clp_options() clp_options_free(opts)opts <- clp_options() clp_options_free(opts)
Settings on a clp_options object, passed to
clp_initial_solve_with_options.
clp_options_set_solve_type(options, method, extra = -1L) clp_options_get_solve_type(options) clp_options_set_presolve_type(options, amount, extra = -1L) clp_options_get_presolve_type(options) clp_options_get_presolve_passes(options) clp_options_set_special_option(options, which, value, extra = -1L) clp_options_get_special_option(options, which) clp_options_get_extra_info(options, which)clp_options_set_solve_type(options, method, extra = -1L) clp_options_get_solve_type(options) clp_options_set_presolve_type(options, amount, extra = -1L) clp_options_get_presolve_type(options) clp_options_get_presolve_passes(options) clp_options_set_special_option(options, which, value, extra = -1L) clp_options_get_special_option(options, which) clp_options_get_extra_info(options, which)
options |
A |
method |
Algorithm code, see Details. |
extra |
Extra information for the setting; -1 selects Clp's default. |
amount |
Presolve code, see Details. |
which |
Index of the special option or extra information slot. |
value |
The new value. |
The solve type selects the algorithm: 0 dual simplex, 1 primal simplex, 2 primal or sprint, 3 barrier, 4 barrier without crossover, 5 automatic. The presolve type is 0 presolve on, 1 presolve off, 2 a fixed number of passes, 3 number and cost.
The getters return an integer; the setters NULL invisibly.
opts <- clp_options() clp_options_set_solve_type(opts, 0L) # dual simplex clp_options_set_presolve_type(opts, 1L) # presolve off clp_options_get_solve_type(opts) clp_options_free(opts)opts <- clp_options() clp_options_set_solve_type(opts, 0L) # dual simplex clp_options_set_presolve_type(opts, 1L) # presolve off clp_options_get_solve_type(opts) clp_options_free(opts)
Getters and setters for the simplex tolerances and the stopping criteria.
clp_primal_tolerance(model) clp_set_primal_tolerance(model, value) clp_dual_tolerance(model) clp_set_dual_tolerance(model, value) clp_dual_objective_limit(model) clp_set_dual_objective_limit(model, value) clp_dual_bound(model) clp_set_dual_bound(model, value) clp_infeasibility_cost(model) clp_set_infeasibility_cost(model, value) clp_max_seconds(model) clp_set_max_seconds(model, value) clp_max_iterations(model) clp_set_max_iterations(model, value) clp_hit_max_iterations(model) clp_small_element_value(model) clp_set_small_element_value(model, value)clp_primal_tolerance(model) clp_set_primal_tolerance(model, value) clp_dual_tolerance(model) clp_set_dual_tolerance(model, value) clp_dual_objective_limit(model) clp_set_dual_objective_limit(model, value) clp_dual_bound(model) clp_set_dual_bound(model, value) clp_infeasibility_cost(model) clp_set_infeasibility_cost(model, value) clp_max_seconds(model) clp_set_max_seconds(model, value) clp_max_iterations(model) clp_set_max_iterations(model, value) clp_hit_max_iterations(model) clp_small_element_value(model) clp_set_small_element_value(model, value)
model |
A |
value |
The new value. |
clp_set_max_seconds() takes a number of seconds from now, and a
negative value removes the limit. Clp turns that into an absolute
deadline by adding the processor time already used, so
clp_max_seconds() reads back the deadline rather than the number
that was set.
The getters return a number; the setters NULL invisibly.
model <- clp_model() clp_set_primal_tolerance(model, 1e-8) clp_primal_tolerance(model) clp_set_max_iterations(model, 1000L) clp_max_iterations(model) clp_free(model)model <- clp_model() clp_set_primal_tolerance(model, 1e-8) clp_primal_tolerance(model) clp_set_max_iterations(model, 1000L) clp_max_iterations(model) clp_free(model)
Asks Clp to dump the model to the console. Useful for small problems when debugging a model build.
clp_print_model(model, prefix = "clp")clp_print_model(model, prefix = "clp")
model |
A |
prefix |
A string Clp puts in front of each line. |
NULL, invisibly.
model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, rowub = 1) clp_print_model(model) clp_free(model)model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, rowub = 1) clp_print_model(model) clp_free(model)
The name of the problem
clp_problem_name(model) clp_set_problem_name(model, name)clp_problem_name(model) clp_set_problem_name(model, name)
model |
A |
name |
A single character string. |
clp_problem_name() returns a string; the setter returns
Clp's integer return code, invisibly.
model <- clp_model() clp_set_problem_name(model, "transport") clp_problem_name(model) clp_free(model)model <- clp_model() clp_set_problem_name(model, "transport") clp_problem_name(model) clp_free(model)
Reads a problem in MPS format into a model, using Clp's own reader. Gzipped files are handled by Clp when it was built with zlib.
clp_read_mps(model, file, keep_names = TRUE, ignore_errors = FALSE)clp_read_mps(model, file, keep_names = TRUE, ignore_errors = FALSE)
model |
A |
file |
Path to the MPS file. |
keep_names |
Keep the row and column names from the file. |
ignore_errors |
Carry on after errors in the file. |
Clp's integer return code, invisibly: 0 on success.
model <- clp_model() path <- system.file("extdata", "productmix.mps", package = "coinclp") if (nzchar(path)) { clp_read_mps(model, path) clp_num_rows(model) } clp_free(model)model <- clp_model() path <- system.file("extdata", "productmix.mps", package = "coinclp") if (nzchar(path)) { clp_read_mps(model, path) clp_num_rows(model) } clp_free(model)
Change the size of a model
clp_resize(model, nrows, ncols)clp_resize(model, nrows, ncols)
model |
A |
nrows, ncols
|
New numbers of rows and columns. |
NULL, invisibly.
model <- clp_model() clp_resize(model, 2, 3) clp_num_cols(model) clp_free(model)model <- clp_model() clp_resize(model, 2, 3) clp_num_cols(model) clp_free(model)
clp_row_names() and clp_col_names() return all names as a
character vector; clp_row_name() and clp_col_name() fetch a
single one by 0-based position, as in the C API. A model that carries no
names of its own reports the generated defaults "R0000000" and
"C0000000"; clp_length_names() is 0 in that case.
clp_row_names(model) clp_col_names(model) clp_row_name(model, index) clp_col_name(model, index) clp_set_names(model, row_names, col_names) clp_set_row_name(model, index, name) clp_set_col_name(model, index, name) clp_drop_names(model) clp_length_names(model)clp_row_names(model) clp_col_names(model) clp_row_name(model, index) clp_col_name(model, index) clp_set_names(model, row_names, col_names) clp_set_row_name(model, index, name) clp_set_col_name(model, index, name) clp_drop_names(model) clp_length_names(model)
model |
A |
index |
0-based row or column position. |
row_names, col_names
|
Character vectors with one entry per row or column. |
name |
A single name. |
clp_set_names() replaces every name at once and works with any Clp
version. clp_set_row_name() and clp_set_col_name() change a
single name but need Clp 1.18 or later; see clp_features.
The getters return character vectors or a single string;
clp_length_names() an integer; the setters NULL invisibly.
model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), rowub = 1) clp_set_names(model, "supply", c("x", "y")) clp_col_names(model) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), rowub = 1) clp_set_names(model, "supply", c("x", "y")) clp_col_names(model) clp_free(model)
Writes or reads Clp's own binary snapshot of a model. The format is
Clp's internal one: it is not portable between Clp versions or machines,
but it is a fast way to hand a model back to the same solver later.
clp_restore_model() replaces whatever the model held.
clp_save_model(model, file) clp_restore_model(model, file)clp_save_model(model, file) clp_restore_model(model, file)
model |
A |
file |
Path of the snapshot file. |
A note for anyone running this under valgrind: Clp's saveModel()
writes a C struct to the file whole, and the struct's trailing padding
bytes are never assigned, so valgrind reports uninitialised bytes passed
to write() (Clp 1.17, ‘ClpSimplex.cpp’, Clp_scalars).
It is harmless, since padding is never read back, but it comes from inside
the Clp library and cannot be silenced from R. For a portable file that
other software can read, use clp_write_mps instead.
Clp's integer return code, invisibly: 0 on success.
## Not run: # Not run in checks: Clp's saveModel() trips valgrind, see Details. model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowub = 2) path <- tempfile() clp_save_model(model, path) clp_restore_model(model, path) clp_free(model) unlink(path) ## End(Not run)## Not run: # Not run in checks: Clp's saveModel() trips valgrind, see Details. model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowub = 2) path <- tempfile() clp_save_model(model, path) clp_restore_model(model, path) clp_free(model) unlink(path) ## End(Not run)
Clp is a linear programming solver and always solves the continuous relaxation; these markers exist so that a model can be handed on to a branch and bound code such as Cbc.
clp_set_integer(model, is_integer) clp_delete_integer(model) clp_integer_information(model)clp_set_integer(model, is_integer) clp_delete_integer(model) clp_integer_information(model)
model |
A |
is_integer |
Logical vector with one entry per column. |
clp_integer_information() returns a logical vector (empty
when no markers are set); the others return NULL invisibly.
model <- clp_model() clp_load_problem(model, 2, 0, c(0L, 0L, 0L), integer(0), numeric(0)) clp_set_integer(model, c(TRUE, FALSE)) clp_integer_information(model) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 0, c(0L, 0L, 0L), integer(0), numeric(0)) clp_set_integer(model, c(TRUE, FALSE)) clp_integer_information(model) clp_free(model)
Builds a Clp model from ordinary R objects, solves it and returns the solution. The model is freed before the function returns.
clp_solve( objective, constraints = NULL, dir = "<=", rhs = NULL, row_lower = NULL, row_upper = NULL, lower = 0, upper = Inf, max = FALSE, control = clp_control(), col_names = NULL, row_names = NULL )clp_solve( objective, constraints = NULL, dir = "<=", rhs = NULL, row_lower = NULL, row_upper = NULL, lower = 0, upper = Inf, max = FALSE, control = clp_control(), col_names = NULL, row_names = NULL )
objective |
Numeric vector of objective coefficients, one per variable. |
constraints |
Constraint matrix, or |
dir |
Character vector of constraint directions, recycled over the
rows: |
rhs |
Numeric right hand side, one entry per row. |
row_lower, row_upper
|
Row bounds, as an alternative to
|
lower, upper
|
Variable bounds, scalars or one entry per variable. The default lower bound is 0, as in most LP formulations. |
max |
Maximise instead of minimise. |
control |
A list from |
col_names, row_names
|
Optional names, used for the returned vectors. |
Constraints are given either by dir and rhs, the usual
one-sided form, or by row_lower and row_upper, which also
covers ranged constraints (2 <= x + y <= 5). Infinite bounds are
written as Inf and -Inf.
constraints may be a dense matrix, a sparse matrix from the
Matrix package, a simple_triplet_matrix from slam, or a
list of triplets with components i, j, v plus
nrow and ncol.
An object of class "clp_solution": a list with
objvalthe objective value at the solution
solutionthe primal solution
statusClp's status code, see clp_status
status_messagethat code as text
optimalTRUE when Clp proved optimality
dualsdual values (shadow prices) for the rows
reduced_costsreduced costs for the columns
row_activitythe value of each row at the solution
iterationssimplex iterations used
clp_model and clp_load_problem for
building a model that you keep, modify and re-solve.
# maximise 143x + 60y subject to # 120x + 210y <= 15000 # 110x + 30y <= 4000 # x + y <= 75 A <- rbind(c(120, 210), c(110, 30), c(1, 1)) res <- clp_solve(c(143, 60), A, "<=", c(15000, 4000, 75), max = TRUE) res$objval res$solution# maximise 143x + 60y subject to # 120x + 210y <= 15000 # 110x + 30y <= 4000 # x + y <= 75 A <- rbind(c(120, 210), c(110, 30), c(1, 1)) res <- clp_solve(c(143, 60), A, "<=", c(15000, 4000, 75), max = TRUE) res$objval res$solution
clp_status() returns Clp's problem status: 0 optimal, 1 primal
infeasible, 2 dual infeasible (unbounded), 3 stopped on a limit,
4 stopped because of errors, and -1 when the problem has not been solved.
clp_status_message() turns such a code into a short description.
clp_status(model) clp_set_status(model, value) clp_secondary_status(model) clp_set_secondary_status(model, value) clp_status_message(status)clp_status(model) clp_set_status(model, value) clp_secondary_status(model) clp_set_secondary_status(model, value) clp_status_message(status)
model |
A |
value |
A new status code. |
status |
An integer status code. |
clp_status() and clp_secondary_status() return an
integer, clp_status_message() a character string, the setters
NULL invisibly.
model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowlb = 1) clp_initial_solve(model) clp_status_message(clp_status(model)) clp_free(model)model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowlb = 1) clp_initial_solve(model) clp_status_message(clp_status(model)) clp_free(model)
clp_status_array() returns Clp's packed basis, rows first, which can
be handed back to a model of the same size with
clp_copyin_status() to warm start it. The per-variable accessors
use Clp's codes: 0 free, 1 basic, 2 at upper bound, 3 at lower bound,
4 superbasic, 5 fixed.
clp_status_exists(model) clp_status_array(model) clp_copyin_status(model, status) clp_row_status(model, index) clp_col_status(model, index) clp_set_row_status(model, index, value) clp_set_col_status(model, index, value)clp_status_exists(model) clp_status_array(model) clp_copyin_status(model, status) clp_row_status(model, index) clp_col_status(model, index) clp_set_row_status(model, index, value) clp_set_col_status(model, index, value)
model |
A |
status |
A raw vector previously returned by |
index |
0-based row or column position. |
value |
New status code. |
clp_status_exists() a logical, clp_status_array() a
raw vector, the accessors an integer status code, the setters
NULL invisibly.
model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(-1, -1), rowub = 1) clp_initial_solve(model) basis <- clp_status_array(model) clp_copyin_status(model, basis) clp_free(model)model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(-1, -1), rowub = 1) clp_initial_solve(model) basis <- clp_status_array(model) clp_copyin_status(model, basis) clp_free(model)
Infeasibility measures
clp_sum_primal_infeasibilities(model) clp_sum_dual_infeasibilities(model) clp_num_primal_infeasibilities(model) clp_num_dual_infeasibilities(model) clp_check_solution(model)clp_sum_primal_infeasibilities(model) clp_sum_dual_infeasibilities(model) clp_num_primal_infeasibilities(model) clp_num_dual_infeasibilities(model) clp_check_solution(model)
model |
A |
A number of violations, or the sum of their sizes.
model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowlb = 1) clp_initial_solve(model) clp_sum_primal_infeasibilities(model) clp_free(model)model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = 1, rowlb = 1) clp_initial_solve(model) clp_sum_primal_infeasibilities(model) clp_free(model)
Rays certifying unboundedness or infeasibility
clp_unbounded_ray(model) clp_infeasibility_ray(model)clp_unbounded_ray(model) clp_infeasibility_ray(model)
model |
A |
A numeric vector, empty when Clp holds no such ray.
model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = -1, rowub = clp_inf()) clp_initial_solve(model) clp_unbounded_ray(model) clp_free(model)model <- clp_model() clp_load_problem(model, 1, 1, c(0L, 1L), 0L, 1, obj = -1, rowub = clp_inf()) clp_initial_solve(model) clp_unbounded_ray(model) clp_free(model)
Version of the Clp library in use
clp_version() clp_features()clp_version() clp_features()
clp_version() returns a list with the version string and its
major, minor and release components. clp_features() returns a
named logical vector saying which optional entry points this build of
Clp provides.
clp_version() clp_features()clp_version() clp_features()
Writes the model in MPS format. Clp gained Clp_writeMps in its C
API after the 1.17 series, so where that entry point is missing (see
clp_features) this falls back to an MPS writer implemented
in R, which writes the same problem in fixed-column MPS format.
clp_write_mps( model, file, format_type = 0L, number_across = 2L, obj_sense = 1, force_r = FALSE )clp_write_mps( model, file, format_type = 0L, number_across = 2L, obj_sense = 1, force_r = FALSE )
model |
A |
file |
Path of the file to write. |
format_type |
Passed to Clp: 0 normal, 1 extra accuracy, 2 IEEE hex. Ignored by the R fallback, which always writes full precision. |
number_across |
Passed to Clp: 1 or 2 pairs of entries per line. |
obj_sense |
1 to write the objective as it stands, -1 to negate it so that a reader minimising the file maximises the original objective. |
force_r |
Use the R writer even when Clp provides its own. |
A row that is unbounded on both sides is written as a second N row. The format has no other way to say so, and readers, Clp's included, keep only the first N row as the objective and drop the rest.
The path written, invisibly.
model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(1, 2), rowub = 4) path <- tempfile(fileext = ".mps") clp_write_mps(model, path) readLines(path)[1:3] clp_free(model) unlink(path)model <- clp_model() clp_load_problem(model, 2, 1, c(0L, 1L, 2L), c(0L, 0L), c(1, 1), obj = c(1, 2), rowub = 4) path <- tempfile(fileext = ".mps") clp_write_mps(model, path) readLines(path)[1:3] clp_free(model) unlink(path)
Accessors for clpPtr objects
clpPointer(object) clpPtrType(object) clpPtrType(object) <- value isNULLpointerCLP(object) isCLPpointer(object)clpPointer(object) clpPtrType(object) clpPtrType(object) <- value isNULLpointerCLP(object) isCLPpointer(object)
object |
A |
value |
A replacement value. |
clpPointer() the external pointer, clpPtrType() a
string, isNULLpointerCLP() and isCLPpointer() a logical.
lp <- initProbCLP() clpPtrType(lp) delProbCLP(lp)lp <- initProbCLP() clpPtrType(lp) delProbCLP(lp)
An S4 class with the same shape as the clpPtr class of the archived
clpAPI package, so that code written against that package keeps
working. initProbCLP creates one.
clpPtrTypeA string describing the pointer, "clp_prob".
clpPointerThe external pointer to the Clp model.
lp <- initProbCLP() isCLPpointer(lp) delProbCLP(lp)lp <- initProbCLP() isCLPpointer(lp) delProbCLP(lp)
Names and files, clpAPI style
copyNamesCLP(lp, cnames, rnames) dropNamesCLP(lp) lengthNamesCLP(lp) probNameCLP(lp, pname) setRowNameCLP(lp, i, rname) setColNameCLP(lp, j, cname) printModelCLP(lp, prefix = "CLPmodel") readMPSCLP(lp, fname, keepNames = TRUE, ignoreErrors = FALSE) writeMPSCLP(lp, fname, formatType = 0, numberAcross = 1, objSense = 1) saveModelCLP(lp, fname) restoreModelCLP(lp, fname) modifyCoefficientCLP(lp, i, j, el, keepZero = TRUE) isAvailableFuncCLP(funcname)copyNamesCLP(lp, cnames, rnames) dropNamesCLP(lp) lengthNamesCLP(lp) probNameCLP(lp, pname) setRowNameCLP(lp, i, rname) setColNameCLP(lp, j, cname) printModelCLP(lp, prefix = "CLPmodel") readMPSCLP(lp, fname, keepNames = TRUE, ignoreErrors = FALSE) writeMPSCLP(lp, fname, formatType = 0, numberAcross = 1, objSense = 1) saveModelCLP(lp, fname) restoreModelCLP(lp, fname) modifyCoefficientCLP(lp, i, j, el, keepZero = TRUE) isAvailableFuncCLP(funcname)
lp |
A |
cnames, rnames
|
Character vectors of column and row names. |
pname |
A problem name. |
i, j
|
0-based row and column positions. |
rname, cname
|
A single name. |
prefix |
A prefix for |
fname |
A file name. |
keepNames |
Keep the names found in an MPS file. |
ignoreErrors |
Carry on after errors in an MPS file. |
formatType, numberAcross, objSense
|
Passed on to the MPS writer. |
el |
A new matrix coefficient. |
keepZero |
Keep zero entries in the sparse structure. |
funcname |
Name of an optional Clp entry point. |
Character or integer values as in clpAPI; the setters return
NULL invisibly.
lp <- initProbCLP() loadMatrixCLP(lp, 2, 1, c(0, 1, 2), c(0, 0), c(1, 1)) copyNamesCLP(lp, c("x", "y"), "budget") lengthNamesCLP(lp) delProbCLP(lp)lp <- initProbCLP() loadMatrixCLP(lp, 2, 1, c(0, 1, 2), c(0, 0), c(1, 1)) copyNamesCLP(lp, c("x", "y"), "budget") lengthNamesCLP(lp) delProbCLP(lp)
Problem data, clpAPI style
getNumRowsCLP(lp) getNumColsCLP(lp) getNumNnzCLP(lp) getObjCoefsCLP(lp) chgObjCoefsCLP(lp, objCoef) getColLowerCLP(lp) chgColLowerCLP(lp, lb) getColUpperCLP(lp) chgColUpperCLP(lp, ub) getRowLowerCLP(lp) chgRowLowerCLP(lp, rlb) getRowUpperCLP(lp) chgRowUpperCLP(lp, rub) getVecStartCLP(lp) getVecLenCLP(lp) getIndCLP(lp) getNnzCLP(lp)getNumRowsCLP(lp) getNumColsCLP(lp) getNumNnzCLP(lp) getObjCoefsCLP(lp) chgObjCoefsCLP(lp, objCoef) getColLowerCLP(lp) chgColLowerCLP(lp, lb) getColUpperCLP(lp) chgColUpperCLP(lp, ub) getRowLowerCLP(lp) chgRowLowerCLP(lp, rlb) getRowUpperCLP(lp) chgRowUpperCLP(lp, rub) getVecStartCLP(lp) getVecLenCLP(lp) getIndCLP(lp) getNnzCLP(lp)
lp |
A |
objCoef |
Objective coefficients. |
lb, ub
|
Column bounds. |
rlb, rub
|
Row bounds. |
The getters return numeric or integer vectors; the setters
NULL invisibly.
lp <- initProbCLP() loadMatrixCLP(lp, 2, 0, c(0, 0, 0), integer(0), numeric(0)) chgObjCoefsCLP(lp, c(1, 2)) getObjCoefsCLP(lp) delProbCLP(lp)lp <- initProbCLP() loadMatrixCLP(lp, 2, 0, c(0, 0, 0), integer(0), numeric(0)) chgObjCoefsCLP(lp, c(1, 2)) getObjCoefsCLP(lp) delProbCLP(lp)
Solutions and status, clpAPI style
getSolStatusCLP(lp) getObjValCLP(lp) getColPrimCLP(lp) getColDualCLP(lp) getRowPrimCLP(lp) getRowDualCLP(lp) status_codeCLP(code) return_codeCLP(code)getSolStatusCLP(lp) getObjValCLP(lp) getColPrimCLP(lp) getColDualCLP(lp) getRowPrimCLP(lp) getRowDualCLP(lp) status_codeCLP(code) return_codeCLP(code)
lp |
A |
code |
A status or return code. |
Numeric vectors for the solution accessors, an integer for
getSolStatusCLP(), a string for the code descriptions.
lp <- initProbCLP() loadProblemCLP(lp, 1, 1, c(0, 1), 0, 1, obj_coef = -1, rlb = -1e30, rub = 2) setLogLevelCLP(lp, 0) solveInitialCLP(lp) status_codeCLP(getSolStatusCLP(lp)) delProbCLP(lp)lp <- initProbCLP() loadProblemCLP(lp, 1, 1, c(0, 1), 0, 1, obj_coef = -1, rlb = -1e30, rub = 2) setLogLevelCLP(lp, 0) solveInitialCLP(lp) status_codeCLP(getSolStatusCLP(lp)) delProbCLP(lp)
As in clp_model, a new problem starts with Clp's message
level at 0; setLogLevelCLP() turns the solver's reporting on.
initProbCLP(ptrtype = "clp_prob") delProbCLP(lp)initProbCLP(ptrtype = "clp_prob") delProbCLP(lp)
ptrtype |
A string stored in the returned object. |
lp |
A |
initProbCLP() returns a clpPtr;
delProbCLP() returns NULL invisibly.
lp <- initProbCLP() setLogLevelCLP(lp, 0) delProbCLP(lp)lp <- initProbCLP() setLogLevelCLP(lp, 0) delProbCLP(lp)
Column-major, 0-based arguments, exactly as in clpAPI:
ia holds the column starts, ja the row indices and
ra the matrix entries.
loadProblemCLP( lp, ncols, nrows, ia, ja, ra, lb = NULL, ub = NULL, obj_coef = NULL, rlb = NULL, rub = NULL ) loadMatrixCLP(lp, ncols, nrows, ia, ja, ra)loadProblemCLP( lp, ncols, nrows, ia, ja, ra, lb = NULL, ub = NULL, obj_coef = NULL, rlb = NULL, rub = NULL ) loadMatrixCLP(lp, ncols, nrows, ia, ja, ra)
lp |
A |
ncols, nrows
|
Problem dimensions. |
ia |
Integer vector of column starts, length |
ja |
Integer vector of 0-based row indices. |
ra |
Numeric vector of matrix entries. |
lb, ub
|
Column bounds, or |
obj_coef |
Objective coefficients, or |
rlb, rub
|
Row bounds, or |
NULL, invisibly.
lp <- initProbCLP() loadProblemCLP(lp, 2, 1, c(0, 1, 2), c(0, 0), c(1, 1), lb = c(0, 0), ub = c(1e30, 1e30), obj_coef = c(-1, -2), rlb = -1e30, rub = 3) solveInitialCLP(lp) getObjValCLP(lp) delProbCLP(lp)lp <- initProbCLP() loadProblemCLP(lp, 2, 1, c(0, 1, 2), c(0, 0), c(1, 1), lb = c(0, 0), ub = c(1e30, 1e30), obj_coef = c(-1, -2), rlb = -1e30, rub = 3) solveInitialCLP(lp) getObjValCLP(lp) delProbCLP(lp)
Change the size of a problem, clpAPI style
resizeCLP(lp, nrows, ncols)resizeCLP(lp, nrows, ncols)
lp |
A |
nrows, ncols
|
New dimensions. |
NULL, invisibly.
lp <- initProbCLP() resizeCLP(lp, 2, 2) getNumRowsCLP(lp) delProbCLP(lp)lp <- initProbCLP() resizeCLP(lp, 2, 2) getNumRowsCLP(lp) delProbCLP(lp)
Solver settings, clpAPI style
setObjDirCLP(lp, lpdir) getObjDirCLP(lp) setLogLevelCLP(lp, amount) getLogLevelCLP(lp) scaleModelCLP(lp, mode) getScaleFlagCLP(lp) setNumberIterationsCLP(lp, iterations) setMaximumIterationsCLP(lp, iterations) getMaximumIterationsCLP(lp) getHitMaximumIterationsCLP(lp) setMaximumSecondsCLP(lp, seconds) getMaximumSecondsCLP(lp)setObjDirCLP(lp, lpdir) getObjDirCLP(lp) setLogLevelCLP(lp, amount) getLogLevelCLP(lp) scaleModelCLP(lp, mode) getScaleFlagCLP(lp) setNumberIterationsCLP(lp, iterations) setMaximumIterationsCLP(lp, iterations) getMaximumIterationsCLP(lp) getHitMaximumIterationsCLP(lp) setMaximumSecondsCLP(lp, seconds) getMaximumSecondsCLP(lp)
lp |
A |
lpdir |
1 to minimise, -1 to maximise. |
amount |
Log level, 0 to 4. |
mode |
Scaling mode. |
iterations |
Iteration count or limit. |
seconds |
Time limit in seconds. |
The getters return a number; the setters NULL invisibly.
lp <- initProbCLP() setObjDirCLP(lp, -1) getObjDirCLP(lp) delProbCLP(lp)lp <- initProbCLP() setObjDirCLP(lp, -1) getObjDirCLP(lp) delProbCLP(lp)
Solve a problem, clpAPI style
solveInitialCLP(lp) solveInitialDualCLP(lp) solveInitialPrimalCLP(lp) solveInitialBarrierCLP(lp) solveInitialBarrierNoCrossCLP(lp) primalCLP(lp, ifValP = 0) dualCLP(lp, ifValP = 0) idiotCLP(lp, thd = 0)solveInitialCLP(lp) solveInitialDualCLP(lp) solveInitialPrimalCLP(lp) solveInitialBarrierCLP(lp) solveInitialBarrierNoCrossCLP(lp) primalCLP(lp, ifValP = 0) dualCLP(lp, ifValP = 0) idiotCLP(lp, thd = 0)
lp |
A |
ifValP |
Pass 1 for a values pass, 0 otherwise. |
thd |
Effort level for the idiot crash. |
An integer return code from Clp; idiotCLP() returns
NULL invisibly.
lp <- initProbCLP() loadProblemCLP(lp, 1, 1, c(0, 1), 0, 1, obj_coef = -1, rlb = -1e30, rub = 2) setLogLevelCLP(lp, 0) solveInitialCLP(lp) getColPrimCLP(lp) delProbCLP(lp)lp <- initProbCLP() loadProblemCLP(lp, 1, 1, c(0, 1), 0, 1, obj_coef = -1, rlb = -1e30, rub = 2) setLogLevelCLP(lp, 0) solveInitialCLP(lp) getColPrimCLP(lp) delProbCLP(lp)
The Clp version, clpAPI style
versionCLP()versionCLP()
The version of the Clp library as a string.
versionCLP()versionCLP()