| Title: | 'HiGHS' Optimization Solver |
|---|---|
| Description: | R interface to 'HiGHS', an optimization solver for solving mixed integer optimization problems with quadratic or linear objective and linear constraints. |
| Authors: | Florian Schwendinger [aut, cre], Dirk Schumacher [aut], Julian Hall [cph], Ivet Galabova [cph], Leona Gottwald [cph], Michael Feldmeier [cph] |
| Maintainer: | Florian Schwendinger <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.12.0-3 |
| Built: | 2026-05-09 07:33:35 UTC |
| Source: | https://github.com/cran/highs |
Creates example optimization models for different problem types: - Linear Programming (LP) - Mixed Integer Linear Programming (MILP) - Quadratic Programming (QP)
example_model(op_type = c("LP", "MILP", "QP"))example_model(op_type = c("LP", "MILP", "QP"))
op_type |
Character string specifying the type of optimization model. Must be one of "LP", "MILP", or "QP". |
A HiGHS model object configured according to the specified type: - LP: Maximization problem with 3 variables and 3 constraints - MILP: Maximization problem with mixed integer and continuous variables - QP: Problem with quadratic objective function
model <- example_model("LP") model <- example_model("MILP") model <- example_model("QP")model <- example_model("LP") model <- example_model("MILP") model <- example_model("QP")
Creates and solves an example optimization model using the HiGHS solver. This is a convenience wrapper that combines model creation and solving in a single function call.
example_solver(op_type = c("LP", "MILP", "QP"))example_solver(op_type = c("LP", "MILP", "QP"))
op_type |
Character string specifying the type of optimization model. Must be one of "LP", "MILP", or "QP". |
An object of class "highs_solver".
solver <- example_solver("LP") solver <- example_solver("MILP") solver <- example_solver("QP")solver <- example_solver("LP") solver <- example_solver("MILP") solver <- example_solver("QP")
This function retrieves the number of constraints in a given 'highs_model' object.
hi_model_get_ncons(model)hi_model_get_ncons(model)
model |
A 'highs_model' object. The model from which to get the number of variables. |
An integer representing the number of constraints in the model.
model <- hi_new_model() hi_model_get_ncons(model)model <- hi_new_model() hi_model_get_ncons(model)
This function retrieves the number of variables in a given Highs model.
hi_model_get_nvars(model)hi_model_get_nvars(model)
model |
A 'highs_model' object. The model from which to get the number of variables. |
An integer representing the number of variables in the model.
model <- hi_new_model() hi_model_get_nvars(model)model <- hi_new_model() hi_model_get_nvars(model)
This function sets the constraint matrix for a given Highs model.
hi_model_set_constraint_matrix(model, matrix)hi_model_set_constraint_matrix(model, matrix)
model |
an object of class |
matrix |
a matrix giving the Hessian matrix.
Allowed matrix classes are |
NULL
model <- hi_new_model() matrix <- matrix(c(1, 0, 0, 1), nrow = 2) hi_model_set_constraint_matrix(model, matrix)model <- hi_new_model() matrix <- matrix(c(1, 0, 0, 1), nrow = 2) hi_model_set_constraint_matrix(model, matrix)
This function sets the Hessian matrix for a given Highs model.
hi_model_set_hessian(model, matrix)hi_model_set_hessian(model, matrix)
model |
an object of class |
matrix |
a matrix giving the Hessian matrix.
Allowed matrix classes are |
NULL
model <- hi_new_model() hessian_matrix <- matrix(c(1, 0, 0, 1), nrow = 2) hi_model_set_hessian(model, hessian_matrix)model <- hi_new_model() hessian_matrix <- matrix(c(1, 0, 0, 1), nrow = 2) hi_model_set_hessian(model, hessian_matrix)
This function sets the left hand side for a given Highs model.
hi_model_set_lhs(model, lhs)hi_model_set_lhs(model, lhs)
model |
an object of class |
lhs |
a numeric vector giving the left hand side values. |
NULL
model <- hi_new_model() model <- hi_model_set_lhs(model, c(0, 1, 2))model <- hi_new_model() model <- hi_model_set_lhs(model, c(0, 1, 2))
This function sets the lower bounds for a given Highs model.
hi_model_set_lower(model, lower)hi_model_set_lower(model, lower)
model |
an object of class |
lower |
a numeric vector giving the lower bounds. |
NULL
model <- hi_new_model() lower_bounds <- c(0, 1, 2) hi_model_set_lower(model, lower_bounds)model <- hi_new_model() lower_bounds <- c(0, 1, 2) hi_model_set_lower(model, lower_bounds)
This function sets the number of columns in the given model.
hi_model_set_ncol(model, ncol)hi_model_set_ncol(model, ncol)
model |
an object of class |
ncol |
an integer giving the number of columns (variables) to set in the model |
NULL
model <- hi_new_model() hi_model_set_ncol(model, 10L) # Sets the model to have 10 columnsmodel <- hi_new_model() hi_model_set_ncol(model, 10L) # Sets the model to have 10 columns
This function sets the number of rows in the given model.
hi_model_set_nrow(model, nrow)hi_model_set_nrow(model, nrow)
model |
an object of class |
nrow |
an integer giving the number of rows (variables) to set in the model |
NULL
model <- hi_new_model() hi_model_set_nrow(model, 5L) # Sets the model to have 5 rowsmodel <- hi_new_model() hi_model_set_nrow(model, 5L) # Sets the model to have 5 rows
This function sets the objective for a given Highs model.
hi_model_set_objective(model, objective)hi_model_set_objective(model, objective)
model |
an object of class |
objective |
a numeric vector giving the objective values to be set for the model. |
NULL
model <- hi_new_model() objective <- c(1, 2, 3) hi_model_set_objective(model, objective)model <- hi_new_model() objective <- c(1, 2, 3) hi_model_set_objective(model, objective)
This function sets the offset for a given Highs model.
hi_model_set_offset(model, offset)hi_model_set_offset(model, offset)
model |
an object of class |
offset |
a numeric value of length 1. The offset value to be set for the model. |
NULL
model <- hi_new_model() hi_model_set_offset(model, 10)model <- hi_new_model() hi_model_set_offset(model, 10)
This function sets the left hand side for a given Highs model.
hi_model_set_rhs(model, rhs)hi_model_set_rhs(model, rhs)
model |
an object of class |
rhs |
a numeric vector giving the left hand side values. |
NULL
model <- hi_new_model() model <- hi_model_set_rhs(model, c(0, 1, 2))model <- hi_new_model() model <- hi_model_set_rhs(model, c(0, 1, 2))
This function sets the sense of the optimization model to either maximization or minimization.
hi_model_set_sense(model, maximum)hi_model_set_sense(model, maximum)
model |
an object of class |
maximum |
a boolean value indicating whether the model should be set to maximization ('TRUE') or minimization ('FALSE'). |
NULL
model <- hi_new_model() hi_model_set_sense(model, TRUE) # Set the model to maximization hi_model_set_sense(model, FALSE) # Set the model to minimizationmodel <- hi_new_model() hi_model_set_sense(model, TRUE) # Set the model to maximization hi_model_set_sense(model, FALSE) # Set the model to minimization
This function sets the upper bounds for a given Highs model.
hi_model_set_upper(model, upper)hi_model_set_upper(model, upper)
model |
an object of class |
upper |
a numeric vector giving the upper bounds. |
NULL
model <- hi_new_model() upper_bounds <- c(10, 20, 30) hi_model_set_upper(model, upper_bounds)model <- hi_new_model() upper_bounds <- c(10, 20, 30) hi_model_set_upper(model, upper_bounds)
This function sets the variable types in a given Highs model.
hi_model_set_vartype(model, types)hi_model_set_vartype(model, types)
model |
an object of class |
types |
an integer vector specifying the types of the variables. |
The function does not return a value. It modifies the 'model' object in place.
model <- hi_new_model() types <- c(1, 2, 1, 0) hi_model_set_vartype(model, types)model <- hi_new_model() types <- c(1, 2, 1, 0) hi_model_set_vartype(model, types)
Create a new highs model object.
hi_new_model()hi_new_model()
an object of class "highs_model".
model <- hi_new_model()model <- hi_new_model()
This function initializes a new Highs solver instance using the provided model pointer.
hi_new_solver(model)hi_new_solver(model)
model |
an object of class |
A new solver instance.
model <- example_model() solver <- hi_new_solver(model)model <- example_model() solver <- hi_new_solver(model)
This function resets the global scheduler used by the solver.
hi_reset_global_scheduler(blocking)hi_reset_global_scheduler(blocking)
blocking |
A logical value indicating whether to wait for completion. |
Invisible NULL.
hi_reset_global_scheduler(TRUE)hi_reset_global_scheduler(TRUE)
This function adds new variables (columns) to the optimization model.
hi_solver_add_cols(solver, costs, lower, upper, start, index, value)hi_solver_add_cols(solver, costs, lower, upper, start, index, value)
solver |
An object of class "highs_solver". |
costs |
A numeric vector of objective coefficients. |
lower |
A numeric vector giving the lower bounds of the new variables. |
upper |
A numeric vector giving the upper bounds of the new variables. |
start |
An integer vector of starting positions in the sparse matrix. |
index |
An integer vector of row indices. |
value |
A numeric vector of coefficient values. |
The solver instance with new variables added.
solver <- example_solver() hi_solver_add_cols(solver, c(1), c(0), c(10), c(0, 1), c(0), c(2))solver <- example_solver() hi_solver_add_cols(solver, c(1), c(0), c(10), c(0, 1), c(0), c(2))
This function adds new constraints (rows) to the optimization model.
hi_solver_add_rows(solver, lhs, rhs, start, index, value)hi_solver_add_rows(solver, lhs, rhs, start, index, value)
solver |
An object of class "highs_solver". |
lhs |
A numeric vector of left-hand side bounds. |
rhs |
A numeric vector of right-hand side bounds. |
start |
An integer vector of starting positions in the sparse matrix. |
index |
An integer vector of column indices. |
value |
A numeric vector of coefficient values. |
The solver instance with new constraints added.
solver <- example_solver() hi_solver_add_rows(solver, c(-Inf), c(10), c(0, 2), c(0, 1), c(1, 2))solver <- example_solver() hi_solver_add_rows(solver, c(-Inf), c(10), c(0, 2), c(0, 1), c(1, 2))
This function adds new variables to the solver with specified bounds.
hi_solver_add_vars(solver, lower, upper)hi_solver_add_vars(solver, lower, upper)
solver |
An object of class "highs_solver". |
lower |
A numeric vector of lower bounds for the new variables. |
upper |
A numeric vector of upper bounds for the new variables. |
The solver instance with the new variables added.
solver <- example_solver() hi_solver_add_vars(solver, lower = c(0, 0, 0), upper = c(10, 10, 10))solver <- example_solver() hi_solver_add_vars(solver, lower = c(0, 0, 0), upper = c(10, 10, 10))
This function updates the bounds of an existing constraint in the model.
hi_solver_change_constraint_bounds(solver, idx, lhs, rhs)hi_solver_change_constraint_bounds(solver, idx, lhs, rhs)
solver |
An object of class "highs_solver". |
idx |
An integer vector specifying the constraint indices. |
lhs |
The new left-hand side bound. |
rhs |
The new right-hand side bound. |
The solver instance with updated constraint bounds.
solver <- example_solver() hi_solver_change_constraint_bounds(solver, 1, -Inf, 100)solver <- example_solver() hi_solver_change_constraint_bounds(solver, 1, -Inf, 100)
This function updates the bounds of an existing variable in the model.
hi_solver_change_variable_bounds(solver, idx, lower, upper)hi_solver_change_variable_bounds(solver, idx, lower, upper)
solver |
An object of class "highs_solver". |
idx |
An integer specifying the variable index. |
lower |
The new lower bound. |
upper |
The new upper bound. |
The solver instance with updated bounds.
solver <- example_solver() hi_solver_change_variable_bounds(solver, 1, 0, 10)solver <- example_solver() hi_solver_change_variable_bounds(solver, 1, 0, 10)
This function clears all data from the solver instance, including the model and solution.
hi_solver_clear(solver)hi_solver_clear(solver)
solver |
An object of class "highs_solver". |
The cleared solver instance.
solver <- example_solver() hi_solver_clear(solver)solver <- example_solver() hi_solver_clear(solver)
This function clears only the model data from the solver instance.
hi_solver_clear_model(solver)hi_solver_clear_model(solver)
solver |
An object of class "highs_solver". |
The solver instance with cleared model data.
solver <- example_solver() hi_solver_clear_model(solver)solver <- example_solver() hi_solver_clear_model(solver)
This function clears the internal solver state while preserving the model.
hi_solver_clear_solver(solver)hi_solver_clear_solver(solver)
solver |
An object of class "highs_solver". |
The solver instance with cleared solver state.
solver <- example_solver() hi_solver_clear_solver(solver)solver <- example_solver() hi_solver_clear_solver(solver)
This function retrieves the value of a boolean solver option.
hi_solver_get_bool_option(solver, key)hi_solver_get_bool_option(solver, key)
solver |
An object of class "highs_solver". |
key |
A character string specifying the option name. |
A logical value.
solver <- example_solver() value <- hi_solver_get_bool_option(solver, "mip_detect_symmetry")solver <- example_solver() value <- hi_solver_get_bool_option(solver, "mip_detect_symmetry")
This function retrieves the bounds for all constraints in the model.
hi_solver_get_constraint_bounds(solver)hi_solver_get_constraint_bounds(solver)
solver |
An object of class "highs_solver". |
A list containing lower and upper bounds for all constraints.
solver <- example_solver() bounds <- hi_solver_get_constraint_bounds(solver)solver <- example_solver() bounds <- hi_solver_get_constraint_bounds(solver)
This function retrieves the constraint matrix of the optimization model.
hi_solver_get_constraint_matrix(solver)hi_solver_get_constraint_matrix(solver)
solver |
An object of class "highs_solver". |
A sparse matrix representing the constraints.
solver <- example_solver() matrix <- hi_solver_get_constraint_matrix(solver)solver <- example_solver() matrix <- hi_solver_get_constraint_matrix(solver)
This function retrieves the value of a double precision solver option.
hi_solver_get_dbl_option(solver, key)hi_solver_get_dbl_option(solver, key)
solver |
An object of class "highs_solver". |
key |
A character string specifying the option name. |
A numeric value.
solver <- example_solver() value <- hi_solver_get_dbl_option(solver, "time_limit")solver <- example_solver() value <- hi_solver_get_dbl_option(solver, "time_limit")
This function retrieves the value of an integer solver option.
hi_solver_get_int_option(solver, key)hi_solver_get_int_option(solver, key)
solver |
An object of class "highs_solver". |
key |
A character string specifying the option name. |
An integer value.
solver <- example_solver() value <- hi_solver_get_int_option(solver, "log_dev_level")solver <- example_solver() value <- hi_solver_get_int_option(solver, "log_dev_level")
This function retrieves the objective coefficients of the linear program.
hi_solver_get_lp_costs(solver)hi_solver_get_lp_costs(solver)
solver |
An object of class "highs_solver". |
A numeric vector of objective coefficients.
solver <- example_solver() costs <- hi_solver_get_lp_costs(solver)solver <- example_solver() costs <- hi_solver_get_lp_costs(solver)
This function returns the number of variables (columns) in the optimization model.
hi_solver_get_num_col(solver)hi_solver_get_num_col(solver)
solver |
An object of class "highs_solver". |
An integer representing the number of variables.
solver <- example_solver() n_vars <- hi_solver_get_num_col(solver)solver <- example_solver() n_vars <- hi_solver_get_num_col(solver)
This function returns the number of constraints (rows) in the optimization model.
hi_solver_get_num_row(solver)hi_solver_get_num_row(solver)
solver |
An object of class "highs_solver". |
An integer representing the number of constraints.
solver <- example_solver() n_constraints <- hi_solver_get_num_row(solver)solver <- example_solver() n_constraints <- hi_solver_get_num_row(solver)
Retrieves the value of a specific option from a HiGHS solver instance.
hi_solver_get_option( solver, key, type = c("auto", "bool", "integer", "double", "string") )hi_solver_get_option( solver, key, type = c("auto", "bool", "integer", "double", "string") )
solver |
A HiGHS solver object of class |
key |
A character string specifying the option name to retrieve. |
type |
Type of the option. Can be one of "auto", "bool", "integer", "double", or "string". When set to "auto" (default), the function will attempt to determine the type from the available options list. Specify a type directly if the option is valid but not listed in the available options. |
The value of the specified option with the appropriate type.
solver <- example_solver() hi_solver_get_option(solver, "output_flag") hi_solver_get_option(solver, "solver", type = "string")solver <- example_solver() hi_solver_get_option(solver, "output_flag") hi_solver_get_option(solver, "solver", type = "string")
Retrieves the values of multiple options from a HiGHS solver instance.
hi_solver_get_options(solver, keys = NULL)hi_solver_get_options(solver, keys = NULL)
solver |
A HiGHS solver object of class |
keys |
A character vector of option names to retrieve. |
A named list of option values with the appropriate types.
solver <- example_solver() hi_solver_get_options(solver, c("output_flag", "solver"))solver <- example_solver() hi_solver_get_options(solver, c("output_flag", "solver"))
This function returns the optimization sense (e.g., minimization or maximization) of the provided solver instance.
hi_solver_get_sense(solver)hi_solver_get_sense(solver)
solver |
An object of class "highs_solver" representing the solver instance. |
The optimization sense of the solver instance.
solver <- example_solver() hi_solver_get_sense(solver)solver <- example_solver() hi_solver_get_sense(solver)
This function retrieves the solution from the solver after optimization.
hi_solver_get_solution(solver)hi_solver_get_solution(solver)
solver |
An object of class "highs_solver". |
A list containing the solution information.
solver <- example_solver() hi_solver_run(solver) solution <- hi_solver_get_solution(solver)solver <- example_solver() hi_solver_run(solver) solution <- hi_solver_get_solution(solver)
This function retrieves the value of a string solver option.
hi_solver_get_str_option(solver, key)hi_solver_get_str_option(solver, key)
solver |
An object of class "highs_solver". |
key |
A character string specifying the option name. |
A character string.
solver <- example_solver() value <- hi_solver_get_str_option(solver, "solver")solver <- example_solver() value <- hi_solver_get_str_option(solver, "solver")
This function retrieves the bounds for all variables in the model.
hi_solver_get_variable_bounds(solver)hi_solver_get_variable_bounds(solver)
solver |
An object of class "highs_solver". |
A list containing lower and upper bounds for all variables.
solver <- example_solver() bounds <- hi_solver_get_variable_bounds(solver)solver <- example_solver() bounds <- hi_solver_get_variable_bounds(solver)
This function retrieves the type (continuous, integer, etc.) of all variables.
hi_solver_get_vartype(solver)hi_solver_get_vartype(solver)
solver |
An object of class "highs_solver". |
A character vector of variable types.
solver <- example_solver() types <- hi_solver_get_vartype(solver)solver <- example_solver() types <- hi_solver_get_vartype(solver)
This function returns the value that the solver uses to represent infinity.
hi_solver_infinity()hi_solver_infinity()
A numeric value representing infinity in the solver.
inf <- hi_solver_infinity()inf <- hi_solver_infinity()
This function retrieves detailed information about the solver's state and performance.
hi_solver_info(solver)hi_solver_info(solver)
solver |
An object of class "highs_solver". |
A list containing solver information.
solver <- example_solver() info <- hi_solver_info(solver)solver <- example_solver() info <- hi_solver_info(solver)
This function executes the optimization solver on the current model.
hi_solver_run(solver)hi_solver_run(solver)
solver |
An object of class "highs_solver". |
The solver instance after optimization.
solver <- example_solver() hi_solver_run(solver)solver <- example_solver() hi_solver_run(solver)
This function assigns a coefficient value to a specific entry in the constraint matrix.
hi_solver_set_coeff(solver, row, col, val)hi_solver_set_coeff(solver, row, col, val)
solver |
An object of class "highs_solver". |
row |
The row index. |
col |
The column index. |
val |
The coefficient value. |
The solver instance with the updated coefficient.
solver <- example_solver() hi_solver_set_coeff(solver, 1, 1, 4.2)solver <- example_solver() hi_solver_set_coeff(solver, 1, 1, 4.2)
This function sets the lower and upper bounds for a specific constraint.
hi_solver_set_constraint_bounds(solver, index, lower, upper)hi_solver_set_constraint_bounds(solver, index, lower, upper)
solver |
An object of class "highs_solver". |
index |
The constraint index. |
lower |
The lower bound. |
upper |
The upper bound. |
The solver instance with updated constraint bounds.
solver <- example_solver() hi_solver_set_constraint_bounds(solver, 1, -Inf, 100)solver <- example_solver() hi_solver_set_constraint_bounds(solver, 1, -Inf, 100)
This function defines whether a variable is categorized as integral or continuous.
hi_solver_set_integrality(solver, index, type)hi_solver_set_integrality(solver, index, type)
solver |
An object of class "highs_solver". |
index |
An integer vector specifying the variable index. |
type |
An integer vector representing the integrality type. |
The solver instance with updated integrality settings.
solver <- example_solver() hi_solver_set_integrality(solver, 1, 1)solver <- example_solver() hi_solver_set_integrality(solver, 1, 1)
This function assigns a coefficient to a variable in the objective function.
hi_solver_set_objective(solver, index, coeff)hi_solver_set_objective(solver, index, coeff)
solver |
An object of class "highs_solver". |
index |
The variable index. |
coeff |
A numeric value representing the objective coefficient. |
The solver instance with the updated objective.
solver <- example_solver() hi_solver_set_objective(solver, 2, 3.5)solver <- example_solver() hi_solver_set_objective(solver, 2, 3.5)
This function sets the objective offset in the solver instance.
hi_solver_set_offset(solver, ext_offset)hi_solver_set_offset(solver, ext_offset)
solver |
An object of class "highs_solver". |
ext_offset |
A numeric value representing the offset. |
The solver instance with the updated offset.
solver <- example_solver() hi_solver_set_offset(solver, 5.0)solver <- example_solver() hi_solver_set_offset(solver, 5.0)
Sets the value of a specific option for a HiGHS solver instance.
hi_solver_set_option( solver, key, value, type = c("auto", "bool", "integer", "double", "string") )hi_solver_set_option( solver, key, value, type = c("auto", "bool", "integer", "double", "string") )
solver |
A HiGHS solver object of class |
key |
A character string specifying the option name to set. |
value |
The value to set for the specified option. Will be coerced to the appropriate type. |
type |
Type of the option. Can be one of "auto", "bool", "integer", "double", or "string". When set to "auto" (default), the function will attempt to determine the type from the available options list. Specify a type directly if the option is valid but not listed in the available options. |
Invisibly returns NULL.
solver <- example_solver() hi_solver_set_option(solver, "output_flag", "FALSE") hi_solver_set_option(solver, "solver", "simplex", type = "string")solver <- example_solver() hi_solver_set_option(solver, "output_flag", "FALSE") hi_solver_set_option(solver, "solver", "simplex", type = "string")
Sets multiple options for a HiGHS solver instance at once.
hi_solver_set_options(solver, control = list())hi_solver_set_options(solver, control = list())
solver |
A HiGHS solver object of class |
control |
A named list of options to set. Names should be valid option names and values will be coerced to the appropriate types. |
Invisibly returns NULL.
solver <- example_solver() hi_solver_set_options(solver, list(output_flag = FALSE, solver = "simplex")) control <- list( presolve = "on", solver = "simplex", parallel = "on", ranging = "off", time_limit = 100.0, primal_feasibility_tolerance = 1e-7, dual_feasibility_tolerance = 1e-7, random_seed = 1234, threads = 4, output_flag = TRUE, log_to_console = TRUE, run_crossover = "on", allow_unbounded_or_infeasible = FALSE, mip_detect_symmetry = TRUE, mip_max_nodes = 10000, mip_max_leaves = 5000, mip_feasibility_tolerance = 1e-6 ) hi_solver_set_options(solver, control)solver <- example_solver() hi_solver_set_options(solver, list(output_flag = FALSE, solver = "simplex")) control <- list( presolve = "on", solver = "simplex", parallel = "on", ranging = "off", time_limit = 100.0, primal_feasibility_tolerance = 1e-7, dual_feasibility_tolerance = 1e-7, random_seed = 1234, threads = 4, output_flag = TRUE, log_to_console = TRUE, run_crossover = "on", allow_unbounded_or_infeasible = FALSE, mip_detect_symmetry = TRUE, mip_max_nodes = 10000, mip_max_leaves = 5000, mip_feasibility_tolerance = 1e-6 ) hi_solver_set_options(solver, control)
This function updates the optimization sense for the given solver instance. Use TRUE for maximization and FALSE for minimization.
hi_solver_set_sense(solver, maximum)hi_solver_set_sense(solver, maximum)
solver |
An object of class "highs_solver". |
maximum |
A boolean indicating whether to set maximization (TRUE) or minimization (FALSE). |
The updated solver instance with the new optimization sense.
solver <- example_solver() hi_solver_set_sense(solver, TRUE)solver <- example_solver() hi_solver_set_sense(solver, TRUE)
This function sets the lower and upper bounds for a set of variables.
hi_solver_set_variable_bounds(solver, index, lower, upper)hi_solver_set_variable_bounds(solver, index, lower, upper)
solver |
An object of class "highs_solver". |
index |
The variable index. |
lower |
The lower bound. |
upper |
The upper bound. |
The solver instance with updated variable bounds.
solver <- example_solver() hi_solver_set_variable_bounds(solver, 2, 0, 10)solver <- example_solver() hi_solver_set_variable_bounds(solver, 2, 0, 10)
This function returns the current status of the solver.
hi_solver_status(solver)hi_solver_status(solver)
solver |
An object of class "highs_solver". |
A status code indicating the solver state.
solver <- example_solver() hi_solver_run(solver) status <- hi_solver_status(solver)solver <- example_solver() hi_solver_run(solver) status <- hi_solver_status(solver)
This function returns a human-readable message describing the current solver status.
hi_solver_status_message(solver)hi_solver_status_message(solver)
solver |
An object of class "highs_solver". |
A character string containing the status message.
solver <- example_solver() hi_solver_run(solver) message <- hi_solver_status_message(solver)solver <- example_solver() hi_solver_run(solver) message <- hi_solver_status_message(solver)
This function writes the current basis information to a file.
hi_solver_write_basis(solver, filename)hi_solver_write_basis(solver, filename)
solver |
An object of class "highs_solver". |
filename |
A character string specifying the output file path. |
Invisible NULL.
solver <- example_solver() basis_file <- tempfile(fileext = ".txt") hi_solver_write_basis(solver, basis_file)solver <- example_solver() basis_file <- tempfile(fileext = ".txt") hi_solver_write_basis(solver, basis_file)
This function writes the current optimization model to a file.
hi_solver_write_model(solver, filename)hi_solver_write_model(solver, filename)
solver |
An object of class "highs_solver". |
filename |
A character string specifying the output file path. |
Invisible NULL.
solver <- example_solver() model_file <- tempfile(fileext = ".mps") hi_solver_write_model(solver, model_file)solver <- example_solver() model_file <- tempfile(fileext = ".mps") hi_solver_write_model(solver, model_file)
Reference for the available solver options.
highs_available_solver_options()highs_available_solver_options()
A data.frame containing the available solver options.
highs_available_solver_options()highs_available_solver_options()
Highs Control
highs_control(threads = 1L, time_limit = Inf, log_to_console = FALSE, ...)highs_control(threads = 1L, time_limit = Inf, log_to_console = FALSE, ...)
threads |
an integer giving the number of threads to be used. |
time_limit |
a double giving the time limit. |
log_to_console |
a logical giving if the output should be shown in the console. |
... |
other arguments supported by the |
control <- highs_control()control <- highs_control()
Solve linear and quadratic mixed integer optimization problems.
highs_model( Q = NULL, L, lower, upper, A = NULL, lhs = NULL, rhs = NULL, types = rep.int(1L, length(L)), maximum = FALSE, offset = 0 )highs_model( Q = NULL, L, lower, upper, A = NULL, lhs = NULL, rhs = NULL, types = rep.int(1L, length(L)), maximum = FALSE, offset = 0 )
Q |
a numeric symmetric matrix giving the quadratic part of the objective. |
L |
a numeric vector giving the linear part of the objective function. |
lower |
a numeric vector giving the lower bounds of the variables. |
upper |
a numeric vector giving the upper bounds of the variables. |
A |
a numeric matrix giving the linear part of the constraints. Rows are constraints, and columns are decision variables. |
lhs |
a numeric vector giving the left hand-side of the linear constraints. |
rhs |
a numeric vector giving the right hand-side of the linear constraints. |
types |
a integer vector or character vector giving the variable types.
|
maximum |
a logical if |
offset |
a numeric value giving the offset (default is |
A an object of class highs_model.
library("highs") # Minimize: # x_0 + x_1 + 3 # Subject to: # x_1 <= 7 # 5 <= x_0 + 2x_1 <= 15 # 6 <= 3x_0 + 2x_1 # 0 <= x_0 <= 4 # 1 <= x_1 A <- rbind(c(0, 1), c(1, 2), c(3, 2)) m <- highs_model(L = c(1.0, 1), lower = c(0, 1), upper = c(4, Inf), A = A, lhs = c(-Inf, 5, 6), rhs = c(7, 15, Inf), offset = 3) m # Minimize: # -x_2 - 3x_3 + (1/2) * (2 x_1^2 - 2 x_1x_3 + 0.2 x_2^2 + 2 x_3^2) # Subject to: # x_1 + x_3 <= 2 # 0 <= x L <- c(0, -1, -3) Q <- rbind(c(2, 0.0, -1), c(0, 0.2, 0), c(-1, 0.0, 2)) A <- cbind(1, 0, 1) m <- highs_model(Q = Q, L = L, lower = 0, A = A, rhs = 2) mlibrary("highs") # Minimize: # x_0 + x_1 + 3 # Subject to: # x_1 <= 7 # 5 <= x_0 + 2x_1 <= 15 # 6 <= 3x_0 + 2x_1 # 0 <= x_0 <= 4 # 1 <= x_1 A <- rbind(c(0, 1), c(1, 2), c(3, 2)) m <- highs_model(L = c(1.0, 1), lower = c(0, 1), upper = c(4, Inf), A = A, lhs = c(-Inf, 5, 6), rhs = c(7, 15, Inf), offset = 3) m # Minimize: # -x_2 - 3x_3 + (1/2) * (2 x_1^2 - 2 x_1x_3 + 0.2 x_2^2 + 2 x_3^2) # Subject to: # x_1 + x_3 <= 2 # 0 <= x L <- c(0, -1, -3) Q <- rbind(c(2, 0.0, -1), c(0, 0.2, 0), c(-1, 0.0, 2)) A <- cbind(1, 0, 1) m <- highs_model(Q = Q, L = L, lower = 0, A = A, rhs = 2) m
Solve linear and quadratic mixed integer optimization problems.
highs_solve( Q = NULL, L, lower, upper, A = NULL, lhs = NULL, rhs = NULL, types = rep.int(1L, length(L)), maximum = FALSE, offset = 0, control = highs_control() )highs_solve( Q = NULL, L, lower, upper, A = NULL, lhs = NULL, rhs = NULL, types = rep.int(1L, length(L)), maximum = FALSE, offset = 0, control = highs_control() )
Q |
a numeric symmetric matrix giving the quadratic part of the objective. |
L |
a numeric vector giving the linear part of the objective function. |
lower |
a numeric vector giving the lower bounds of the variables. |
upper |
a numeric vector giving the upper bounds of the variables. |
A |
a numeric matrix giving the linear part of the constraints. Rows are constraints, and columns are decision variables. |
lhs |
a numeric vector giving the left hand-side of the linear constraints. |
rhs |
a numeric vector giving the right hand-side of the linear constraints. |
types |
a integer vector or character vector giving the variable types.
|
maximum |
a logical if |
offset |
a numeric value giving the offset (default is |
control |
a list giving additional options for the solver,
see highs_available_solver_options or the |
A list containing the result provided by the solver,
containing the following named objects:
primal_solution |
a numeric vector giving the primal solution. |
objective_value |
a numeric giving the objective value. |
status |
an integer giving the status code |
status_message |
a character string giving the status message (explanation of the |
solver_msg |
a list giving the original (not canonicalized) solver message. |
info |
a list giving additional information provided by the solver. |
Additional information on can be found in the README file.
library("highs") # Minimize: # x_0 + x_1 + 3 # Subject to: # x_1 <= 7 # 5 <= x_0 + 2x_1 <= 15 # 6 <= 3x_0 + 2x_1 # 0 <= x_0 <= 4 # 1 <= x_1 A <- rbind(c(0, 1), c(1, 2), c(3, 2)) s <- highs_solve(L = c(1.0, 1), lower = c(0, 1), upper = c(4, Inf), A = A, lhs = c(-Inf, 5, 6), rhs = c(7, 15, Inf), offset = 3) s[["objective_value"]] s[["primal_solution"]] # Minimize: # -x_2 - 3x_3 + (1/2) * (2 x_1^2 - 2 x_1x_3 + 0.2 x_2^2 + 2 x_3^2) # Subject to: # x_1 + x_3 <= 2 # 0 <= x L <- c(0, -1, -3) Q <- rbind(c(2, 0.0, -1), c(0, 0.2, 0), c(-1, 0.0, 2)) A <- cbind(1, 0, 1) s <- highs_solve(Q = Q, L = L, lower = 0, A = A, rhs = 2) s[["objective_value"]] s[["primal_solution"]]library("highs") # Minimize: # x_0 + x_1 + 3 # Subject to: # x_1 <= 7 # 5 <= x_0 + 2x_1 <= 15 # 6 <= 3x_0 + 2x_1 # 0 <= x_0 <= 4 # 1 <= x_1 A <- rbind(c(0, 1), c(1, 2), c(3, 2)) s <- highs_solve(L = c(1.0, 1), lower = c(0, 1), upper = c(4, Inf), A = A, lhs = c(-Inf, 5, 6), rhs = c(7, 15, Inf), offset = 3) s[["objective_value"]] s[["primal_solution"]] # Minimize: # -x_2 - 3x_3 + (1/2) * (2 x_1^2 - 2 x_1x_3 + 0.2 x_2^2 + 2 x_3^2) # Subject to: # x_1 + x_3 <= 2 # 0 <= x L <- c(0, -1, -3) Q <- rbind(c(2, 0.0, -1), c(0, 0.2, 0), c(-1, 0.0, 2)) A <- cbind(1, 0, 1) s <- highs_solve(Q = Q, L = L, lower = 0, A = A, rhs = 2) s[["objective_value"]] s[["primal_solution"]]
Create a wrapper around the HiGHS solver. Manly usefull if one wants
a low level wrapper around highs with hot-start capabilities.
highs_solver(model, control = highs_control())highs_solver(model, control = highs_control())
model |
an object of class |
control |
an object of class |
Methods
The following methods are provided by the "highs_solver" class.
solve(...) method to be called to solve the optimization problem.
Returns an integer giving the status code returned by HiGHS.
status() method to obtain the status from the solver.
status_message() method to obtain the status message from the solver.
solution() method to obtain the solution from the solver.
info() info to obtain addtional information from the solver.
L(i, v) method to get and set the linear part of the objective.
A(i, j, v) method to get and set the constraint matrix coefficients.
cbounds(i, lhs, rhs) method to get and set the constraint bounds
(left hand-side and right hand-side).
types(i, v) method to get and set the variable types.
vbounds(i, lower, upper) method to get and set the variable bounds.
maximum(maximize) method to get and set the sense of the problem.
Method arguments
... optional control arguments, which can be used to alter the options
set via the control argument when initializing the solver.
i a vector of integers giving the index (vector index or row index)
of the coeficcients to be altered.
j a vector of integers giving the index (column index) of the coeficcients to be altered.
v a vector of doubles giving the values of the coeficcients to be altered.
lhs a vector of doubles giving left hand-side.
rhs a vector of doubles giving right hand-side.
lower a vector of doubles giving the lower bounds to be altered.
upper a vector of doubles giving the upper bounds to be altered.
an object of class "highs_solver".
A <- rbind(c(0, 1), c(1, 2), c(3, 2)) m <- highs_model(L = c(1.0, 1), lower = c(0, 1), upper = c(4, Inf), A = A, lhs = c(-Inf, 5, 6), rhs = c(7, 15, Inf), offset = 3) solver <- highs_solver(m)A <- rbind(c(0, 1), c(1, 2), c(3, 2)) m <- highs_model(L = c(1.0, 1), lower = c(0, 1), upper = c(4, Inf), A = A, lhs = c(-Inf, 5, 6), rhs = c(7, 15, Inf), offset = 3) solver <- highs_solver(m)
Write an highs model to file.
highs_write_model(model, file)highs_write_model(model, file)
model |
an object of class |
file |
a character string giving the filename. |
model <- example_model() model_file <- tempfile(fileext = ".mps") highs_write_model(model, model_file)model <- example_model() model_file <- tempfile(fileext = ".mps") highs_write_model(model, model_file)