Title: | R Interface to 'lp_solve' Version 5.5.2.0 |
---|---|
Description: | The lpSolveAPI package provides an R interface to 'lp_solve', a Mixed Integer Linear Programming (MILP) solver with support for pure linear, (mixed) integer/binary, semi-continuous and special ordered sets (SOS) models. |
Authors: | lp_solve <https://lpsolve.sourceforge.net/> [aut], Kjell Konis [aut], Florian Schwendinger [aut, cre], Kurt Hornik [ctb] |
Maintainer: | Florian Schwendinger <[email protected]> |
License: | LGPL-2 |
Version: | 5.5.2.0-17.12 |
Built: | 2024-12-17 06:49:52 UTC |
Source: | CRAN |
Add a column to an lpSolve linear program model object.
add.column(lprec, x, indices)
add.column(lprec, x, indices)
lprec |
an lpSolve linear program model object. |
x |
a numeric vector containing the elements (only the nonzero elements if the |
indices |
optional for sparse |
This function adds an additional column to an lpSolve linear program model object. If multiple columns are to be added, performance can be improved by calling resize.lp
before adding the columns.
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 0) add.column(lps.model, c(6,2,4,9)) add.column(lps.model, c(3,1,5), indices = c(1,2,4))
lps.model <- make.lp(4, 0) add.column(lps.model, c(6,2,4,9)) add.column(lps.model, c(3,1,5), indices = c(1,2,4))
Add a constraint to an lpSolve linear program model object.
add.constraint(lprec, xt, type = c("<=", "=", ">="), rhs, indices, lhs)
add.constraint(lprec, xt, type = c("<=", "=", ">="), rhs, indices, lhs)
lprec |
an lpSolve linear program model object. |
xt |
a numeric vector containing the constraint coefficients (only the nonzero coefficients if |
type |
a numeric or character value from the set |
rhs |
a single numeric value specifying the right-hand-side of the constraint. |
indices |
optional for sparse |
lhs |
optional. A single numeric value specifying the left-hand-side of the constraint. |
Specifying the objective function before adding constraints will improve the performance of this function.
The use of this function should be avoided when possible. Building a model column-by-column rather than row-by-row will be on the order of 50 times faster (building the model - not solving the model).
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 4) set.objfn(lps.model, rep(1, 4)) add.constraint(lps.model, c(6,2,4,9), "<=", 50) add.constraint(lps.model, c(3,1,5), 2, 75, indices = c(1,2,4))
lps.model <- make.lp(0, 4) set.objfn(lps.model, rep(1, 4)) add.constraint(lps.model, c(6,2,4,9), "<=", 50) add.constraint(lps.model, c(3,1,5), 2, 75, indices = c(1,2,4))
Add a Special Ordered Set (SOS) constraint to an lpSolve linear program model object.
add.SOS(lprec, name, type, priority, columns, weights)
add.SOS(lprec, name, type, priority, columns, weights)
lprec |
an lpSolve linear program model object. |
name |
a character string specifying a name for the SOS constraint. |
type |
a positive integer specifying the type of the SOS constraint. |
priority |
an integer specifying the priority of the SOS constraint. |
columns |
a numeric vector of unique values from the set |
weights |
a numeric vector the same length as |
If the operation was successful: a single integer value containing the list index of the new special ordered set. A return value of 0
indicates an error.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Delete a column from an lpSolve linear program model object.
delete.column(lprec, columns)
delete.column(lprec, columns)
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector of unique values from the set |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) delete.column(lps.model, 1)
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) delete.column(lps.model, 1)
Delete a constraint from an lpSolve linear program model object.
delete.constraint(lprec, constraints)
delete.constraint(lprec, constraints)
lprec |
an lpSolve linear program model object. |
constraints |
a numeric vector of unique values from the set |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 4) set.objfn(lps.model, rep(1, 4)) xt <- c(6,2,4,9) add.constraint(lps.model, xt, "<=", 50) yt <- c(3,1,5) ind <- c(1,2,4) add.constraint(lps.model, yt, 2, 75, ind) delete.constraint(lps.model, 1)
lps.model <- make.lp(0, 4) set.objfn(lps.model, rep(1, 4)) xt <- c(6,2,4,9) add.constraint(lps.model, xt, "<=", 50) yt <- c(3,1,5) ind <- c(1,2,4) add.constraint(lps.model, yt, 2, 75, ind) delete.constraint(lps.model, 1)
Free all the resources used by an lpSolve linear program model object and set the value of the external pointer to NULL
.
delete.lp(lprec)
delete.lp(lprec)
lprec |
an lpSolve linear program model object. |
This function is used as a finalizer for lpSolve linear program model objects.
lprec
is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Retrieve the dimension (number of rows and columns) from an lpSolve linear program model object.
## S3 method for class 'lpExtPtr' dim(x) ## S3 replacement method for class 'lpExtPtr' dim(x) <- value
## S3 method for class 'lpExtPtr' dim(x) ## S3 replacement method for class 'lpExtPtr' dim(x) <- value
x |
an lpSolve linear program model object. |
value |
assignment is not supported. |
Setting the number of rows/columns is not supported. See resize.lp
.
an integer vector of length two containing the number of rows and the number of columns in the lpSolve linear program model object.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) dim(lps.model)
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) dim(lps.model)
Retrieve or set the dimnames in an lpSolve linear program model object.
## S3 method for class 'lpExtPtr' dimnames(x) ## S3 replacement method for class 'lpExtPtr' dimnames(x) <- value
## S3 method for class 'lpExtPtr' dimnames(x) ## S3 replacement method for class 'lpExtPtr' dimnames(x) <- value
x |
an lpSolve linear program model object. |
value |
a list containing two character vectors of lengths |
a list of two character vectors containing the row names and the column names in the lpSolve linear program model object.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) dimnames(lps.model) <- list(c("alpha", "bravo", "charlie", "delta"), c("whiskey", "tango"))
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) dimnames(lps.model) <- list(c("alpha", "bravo", "charlie", "delta"), c("whiskey", "tango"))
Retrieve the basis from a solved lpSolve linear program model object.
get.basis(lprec, nonbasic = FALSE)
get.basis(lprec, nonbasic = FALSE)
lprec |
an lpSolve linear program model object. |
nonbasic |
a logical value. If |
an integer vector containing the indices of the basic (and nonbasic if requested) variables. If an error occurs (for instance when calling get.basis
on a model that has not yet been solved) a NULL
value is returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(3, 3) ## build and solve model ## get.basis(lps.model)
lps.model <- make.lp(3, 3) ## build and solve model ## get.basis(lps.model)
Retrieve the bounds on the decision variables from an lpSolve linear program model object.
get.bounds(lprec, columns = 1:n)
get.bounds(lprec, columns = 1:n)
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector of unique values from the set |
a list with components lower
and upper
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(3, 3) get.bounds(lps.model)
lps.model <- make.lp(3, 3) get.bounds(lps.model)
Retrieve the branch mode for one or more decision variables from an lpSolve linear program model object.
get.branch.mode(lprec, columns = 1:n, as.char = TRUE)
get.branch.mode(lprec, columns = 1:n, as.char = TRUE)
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector of unique values from the set |
as.char |
a logical value. If |
either a character vector or an integer vector containing the branch modes for the decision variables specified in columns
. The possibilities are: 0 = "ceiling"
, 1 = "floor"
and 2 = "auto"
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(3, 3) get.branch.mode(lps.model)
lps.model <- make.lp(3, 3) get.branch.mode(lps.model)
Retrieve a column from an lpSolve linear program model object.
get.column(lprec, column)
get.column(lprec, column)
lprec |
an lpSolve linear program model object. |
column |
a single numeric value from the set |
a list with elements column
and nzrow
such that column[i]
contains the constraint coefficient in row nzrow[i]
. Rows not present in nzrow
have coefficient zero in column
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) get.column(lps.model, 2)
lps.model <- make.lp(4, 0) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind) get.column(lps.model, 2)
Retrieve constraint types from an lpSolve linear program model object.
get.constr.type(lprec, constraints = 1:m, as.char = TRUE)
get.constr.type(lprec, constraints = 1:m, as.char = TRUE)
lprec |
an lpSolve linear program model object. |
constraints |
a numeric vector of unique values from the set |
as.char |
a logical value. If |
either a character vector or an integer vector containing the types of the constraints specified in constraints
. The possibilities are: 0 = "free"
, 1 = "<="
, 2 = ">="
and 3 = "="
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 15) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 15) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) get.constr.type(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 15) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 15) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) get.constr.type(lps.model)
Retrieve constraint values from an lpSolve linear program model object.
get.constr.value(lprec, side = c("rhs", "lhs"), constraints = 1:m)
get.constr.value(lprec, side = c("rhs", "lhs"), constraints = 1:m)
lprec |
an lpSolve linear program model object. |
side |
either |
constraints |
a numeric vector of unique values from the set |
a numeric vector containing the constraint values.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Retrieve the values of the constraints from a successfully solved lpSolve linear program model object.
get.constraints(lprec)
get.constraints(lprec)
lprec |
an lpSolve linear program model object. |
a numeric vector containing the values of the constraints.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.constraints(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.constraints(lps.model)
Retrieve the values of the dual variables (the reduced costs) from a successfully solved lpSolve linear program model object.
get.dual.solution(lprec)
get.dual.solution(lprec)
lprec |
an lpSolve linear program model object. |
a numeric vector containing the values of the dual variables. If an error occurs (for instance lprec
has not been successfully solved) a NULL
value is returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.dual.solution(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.dual.solution(lps.model)
Retrieve the kind of a decision variable from an lpSolve linear program model object.
get.kind(lprec, columns = 1:n)
get.kind(lprec, columns = 1:n)
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector of unique values from the set |
Decision variables have both a type and a kind. The type is either real
or integer
and indicates the type of values the decision variable may take. The kind is one of {standard, semi-continuous, SOS}
. Semi-continuous decision variables can take allowed values between their upper and lower bound as well as zero. Please see the link in the references for a discussion of special ordered set (SOS) constraints.
a character vector containing the kind of each decision variable specified in columns
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) get.kind(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) get.kind(lps.model)
Retrieve a single element from the matrix of constraints.
get.mat(lprec, i, j)
get.mat(lprec, i, j)
lprec |
an lpSolve linear program model object. |
i |
a single numeric value from the set {1, ..., m} (where |
j |
a single numeric value from the set {1, ..., n} (where |
a single numeric value.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) get.mat(lps.model, 2, 2)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) get.mat(lps.model, 2, 2)
Retrieve the value of the objective function from a successfully solved lpSolve linear program model object.
get.objective(lprec)
get.objective(lprec)
lprec |
an lpSolve linear program model object. |
a single numeric value containing the value of the objective function.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.objective(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.objective(lps.model)
Retrieve the values of the primal variables from a successfully solved lpSolve linear program model object.
get.primal.solution(lprec, orig = FALSE)
get.primal.solution(lprec, orig = FALSE)
lprec |
an lpSolve linear program model object. |
orig |
a logical value. When presolve is active, the size of the lp may decrease during solve. By default, the answer to this reduced problem is returned. Set this argument to |
a numeric vector containing the values of the primal variables. If an error occurs (for instance lprec
has not been successfully solved) a NULL
value is returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.primal.solution(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.primal.solution(lps.model)
Retrieve right-hand-side values from an lpSolve linear program model object.
get.rhs(lprec, constraints = 1:m)
get.rhs(lprec, constraints = 1:m)
lprec |
an lpSolve linear program model object. |
constraints |
a numeric vector of unique values from the set |
a numeric vector containing the right-hand-side values specified by constraints
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) get.rhs(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) get.rhs(lps.model)
Retrieve the sensitivity of the objective function from a successfully solved lpSolve linear program model object.
get.sensitivity.obj(lprec)
get.sensitivity.obj(lprec)
lprec |
an lpSolve linear program model object. |
a list with components
objfrom |
a numeric vector of length |
objtill |
a numeric vector of length |
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.sensitivity.obj(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.sensitivity.obj(lps.model)
Retrieve the sensitivity of the objective function from a successfully solved lpSolve linear program model object.
get.sensitivity.objex(lprec)
get.sensitivity.objex(lprec)
lprec |
an lpSolve linear program model object. |
a list with components
objfrom |
a numeric vector of length |
objtill |
a numeric vector of length |
objfromvalue |
a numeric vector of length |
objtillvalue |
not used in this version of lpSolve. |
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.sensitivity.objex(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.sensitivity.objex(lps.model)
Retrieve the sensitivity of the constraints from a successfully solved lpSolve linear program model object.
get.sensitivity.rhs(lprec)
get.sensitivity.rhs(lprec)
lprec |
an lpSolve linear program model object. |
a list with components
duals |
a numeric vector of length |
dualsfrom |
a numeric vector of length |
dualstill |
a numeric vector of length |
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.sensitivity.rhs(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.sensitivity.rhs(lps.model)
Computes the number of equal solutions in a successfully solved lpSolve linear program model object. This is only valid if there are integer, semi-continuous or SOS variables in the model so that the branch-and-bound algorithm is used. This count gives the number of solutions with the same optimal objective value.
get.solutioncount(lprec)
get.solutioncount(lprec)
lprec |
an lpSolve linear program model object. |
a single integer value giving the number of solutions attaining the optimal objective value.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Retrieves the total number of iterations from a successfully solved lpSolve linear program model object.
get.total.iter(lprec)
get.total.iter(lprec)
lprec |
an lpSolve linear program model object. |
If lprec
contains integer variables then this function returns the number of iterations to find a relaxed solution plus the number of iterations in the B&B process. If lprec
contains no integer variables then this function returns the number of iterations to find a solution.
a single integer value giving the total number of iterations.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Retrieves the total number of nodes processed in the branch-and-bound algorithm from a successfully solved lpSolve linear program model object.
get.total.nodes(lprec)
get.total.nodes(lprec)
lprec |
an lpSolve linear program model object. |
The output of this function is only applicable for models containing integer variables.
a single integer value giving the total number of nodes processed.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Retrieve the type of a decision variable from an lpSolve linear program model object.
get.type(lprec, columns = 1:n, as.char = TRUE)
get.type(lprec, columns = 1:n, as.char = TRUE)
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector of unique values from the set |
as.char |
a logical value. If |
The function set.type
can be used to set a decision variable as binary. A binary decision variable is simply an integer decision with an upper bound of one and a lower bound of zero - hence this function will report the type as integer.
either a character vector with elements from the set {"real", "integer"}
indicating the type of each decision variable specified in columns
or (if as.char = FALSE
) a logical vector with TRUE
elements corresponding to the integer decision variables specified in columns
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) set.type(lps.model, 2, "binary") xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.type(lps.model, 3, "integer") set.objfn(lps.model, c(-3,-4,-3)) get.type(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) set.type(lps.model, 2, "binary") xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.type(lps.model, 3, "integer") set.objfn(lps.model, c(-3,-4,-3)) get.type(lps.model)
Retrieve the values of the decision variables from a successfully solved lpSolve linear program model object.
get.variables(lprec)
get.variables(lprec)
lprec |
an lpSolve linear program model object. |
a numeric vector containing the values of the decision variables corresponding to the optimal solution.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.variables(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model) get.variables(lps.model)
Attempt to find a feasible basis corresponding to a user provided feasible point.
guess.basis(lprec, guess)
guess.basis(lprec, guess)
lprec |
an lpSolve linear program model object. |
guess |
a numeric vector of length |
if successful, a numeric vector containing the indices of a starting basis. This vector is suitable for use with the set.basis
function.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Set control parameters in an lpSolve linear program model object.
lp.control(lprec, ..., reset = FALSE)
lp.control(lprec, ..., reset = FALSE)
lprec |
an lpSolve linear program model object. |
... |
control arguments to bet set in |
reset |
a logical value. If |
a list containing all of the control parameters as set internally in lprec
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
A description of the various control options that can be set in an lpSolve linear program model object using the lp.control
function.
a character vector containing one or more of the following options. If any element is "none" then no anti-degeneracy handling is used.
"none" : |
No anti-degeneracy handling. |
"fixedvars" : |
Check if there are equality slacks in the basis and try to drive them out in order to reduce chance of degeneracy in Phase 1. |
"columncheck" : |
|
"stalling" : |
|
"numfailure" : |
|
"lostfeas" : |
|
"infeasible" : |
|
"dynamic" : |
|
"duringbb" : |
|
"rhsperturb" : |
Perturbation of the working RHS at refactorization |
"boundflip" : |
Limit bound flips that can sometimes contribute to degeneracy in some models. |
The default is c("infeasible", "stalling", "fixedvars")
.
a character string specifying the basis crash mode to use. When no basis crash is done the initial basis from which lpSolve starts is the basis containing all slack or artificial variables. When basis crash is enabled, a heuristic crash procedure is executed before the first simplex iteration to quickly choose a basis matrix that has fewer artificial variables. This procedure tends to reduce the number of iterations required by the solver. The choices for this option are given in the following table.
"none" : |
No basis crash. |
"mostfeasible" : |
Most feasible basis. |
"leastdegenerate" : |
Construct a basis that is in some sense the least degenerate. |
The default is "none"
.
a single integer value specifying the maximum branch-and-bound depth. A positive value means that the depth limit is absolute. A negative value means a relative branch-and-bound depth limit. The order of an MIP problem is defined to be 2 times the number of binary variables plus the number of semi-continuous (SC) and special-ordered-sets (SOS) variables. A relative value of -x
results in a maximum depth of x
times the order of the MIP problem.
This control option only applies if there are integer, SC or SOS variables in the model (i.e., when the branch-and-bound algorithm is used). The branch-and-bound algorithm will not go deeper than this level. Limiting the depth speeds up the solving time but there is a chance that the solution obtained is sub-optimal. Be aware of this. Another possible consequence is that no solution will be found.
The default value is -50
; a value of zero implies no limit to the depth.
a character string from among the following choices specifying which branch to take first in the branch-and-bound algorithm.
"ceiling" : |
Take ceiling branch first. |
"floor" : |
Take floor branch first. |
"auto" : |
lpSolve decides which branch to take first. |
The value of this option can influence solving times considerably. However, the real-world performance will be model dependent. The default is "auto"
.
a character vector specifying the branch-and-bound rule. The first element must be chosen from the following table.
"first" : |
Select the lowest indexed non-integer column. |
"gap" : |
Selection based on the distance from the current bounds. |
"range" : |
Selection based on the largest current bound. |
"fraction" : |
Selection based on the largest fractional value. |
"pseudocost" : |
Simple, unweighted pseudo-cost of a variable. |
"pseudononint" : |
An extended pseudo-costing strategy based on minimizing the number of integer infeasibilities. |
"pseudoratio" : |
An extended pseudo-costing strategy based on maximizing the normal pseudo-cost divided by the number of infeasibilities. Effectively, it is similar to (the reciprocal of) a cost/benefit ratio. |
Additional modes (if any) may be appended to augment the rule specified in the first element of bb.rule
.
"weightreverse" : |
Select by criterion minimum (worst), rather than by criterion maximum (best). |
"branchreverse" : |
When bb.floorfirst is "auto" , select the direction (lower/upper branch) opposite to that chosen by lpSolve. |
"greedy" : |
|
"pseudocost" : |
Toggle between weighting based on pseudocost or objective function value. |
"depthfirst" : |
Select the node that has been selected before the most number of times. |
"randomize" : |
Add a randomization factor to the score for all the node candidates. |
"gub" : |
This option is still in development and should not be used at this time. |
"dynamic" : |
When "depthfirst" is selected, switch it off once the first solution is found. |
"restart" : |
Regularly restart the pseudocost value calculations. |
"breadthfirst" : |
Select the node that has been selected the fewest number of times (or not at all). |
"autoorder" : |
Create an optimal branch-and-bound variable ordering. Can speed up branch-and-bound algorithm. |
"rcostfixing" : |
Do bound tightening during branch-and-bound based on the reduced cost information. |
"stronginit" : |
Initialize pseudo-costs by strong branching. |
The value of this rule can influence solving times considerably. However, the real-world performance will be model dependent. The default value is c("pseudononint", "greedy", "dynamic", "rcostfixing")
.
a logical value. If TRUE
then the branch-and-bound algorithm stops at the first solution found. The default (FALSE
) is to continue until an optimal solution is found.
a numeric value. The branch-and-bound algorithm stops if the objective function becomes better than this value. The default (infinity) is to continue until an optimal value is found.
a character string providing a simplified way of specifying multiple tolerance thresholds in a logically consistent way. The following values are set: epsel
, epsb
, epsd
, epspivot
, epsint
and mip.gap
.
"tight" : |
Use tight tolerance values. |
"medium" : |
Use medium tolerance values. |
"loose" : |
Use loose tolerance values. |
"baggy" : |
Use very loose tolerance values. |
The default is "tight"
.
a single positive numeric value specifying the tolerance used to determine whether a right-hand-side value should be considered zero. Rounding error in floating-point calculations may result in a loss of precision. A very small value (for example, 1e-99) could be the result of such errors and should be considered zero by the solver. If the absolute value of a right-hand-side value is less than epsb
then it is treated as zero by the solver. The default value is 1.0e-10
.
a single positive numeric value specifying the tolerance used to determine whether a computed reduced cost should be considered zero. Rounding error in floating-point calculations may result in a loss of precision. A very small value (for example, 1e-99) could be the result of such errors and should be considered zero by the solver. If the absolute value of a computed reduced cost is less than epsd
then it is treated as zero by the solver. The default value is 1.0e-9
.
a single positive numeric value specifying the tolerance used for rounding values to zero. Rounding error in floating-point calculations may result in a loss of precision. A very small value (for example, 1e-99) could be the result of such errors and should be considered zero by the solver. If the absolute value of a computed value is less than epsel
then it is rounded to zero by the solver. The default value is 1.0e-12
. This parameter is used in situations where none of epsint
, epsb
, epsd
, epspivot
norepsperturb
apply.
a single positive numeric value specifying the tolerance used to determine whether a floating-point number is an integer. This parameter only applies when there is at least one integer variable so that the branch and bound algorithm is used. Integer variables are internally stored as floating-point. A tolerance is therefore needed to determine whether a value should be considered an integer. If the absolute value of the variable minus the closest integer is less than epsint
then it is considered an integer. The default value is 1.0e-7
.
a single positive numeric value specifying the perturbation scalar for degenerate problems. The default is 1.0e-5
.
a single positive numeric value specifying the tolerance used to determine whether a pivot element is zero. Rounding error in floating-point calculations may result in a loss of precision. A very small value (for example, 1e-99) could be the result of such errors and should be considered zero by the solver. If the absolute value of a computed pivot element is less than epspivot
then it is treated as zero by the solver. Pivots will be performed on elements smaller (in absolute terms) than epspivot
when no other larger pivot element can be found. The default value is 2.0e-7
.
a character vector specifying the iterative improvement level. The possible values are given in the following table.
"none" : |
None. |
"solution" : |
Running accuracy measurement of solved equations based on (primal simplex), remedy is refactorization. |
"dualfeas" : |
Improve initial dual feasibility by bound flips (highly recommended). |
"thetagap" : |
Low-cost accuracy monitoring in the dual, remedy is refactorization. |
"bbsimplex" : |
By default there is a check for primal/dual feasibility at the optimum only for the relaxed problem, this also activates the test at the node level. |
The default is c("dualfeas", "thetagap")
.
a positive numeric value specifying the practical value for infinity. This value is used for very large numbers, for example the upper bound of a variable without an upper bound. The default is 1.0e30
.
a positive integer value specifying the maximum number of pivots between re-inversion of the matrix. For stability, lpSolve periodically re-inverts the matrix. However, the more often this is done, the slower the solver becomes. The default is 250
.
a numeric vector of length two specifying respectively the absolute and relative MIP gaps used in the branch-and-bound algorithm. This tolerance is the difference between the best-found solution yet and the current solution. If the difference is smaller than this tolerance then the solution (and all the sub-solutions) is rejected. This can result in faster solving times, but results in a solution which is not the perfect solution. The default is 1.0e-11
.
a nonpositive numeric value below which variables are split into negative and positive parts. The default is -1.0e6
.
a logical value specifying whether the objective function is stored in the matrix. The default is to store the objective function in the top row of the constraint matrix. If FALSE
then the objective function is moved to separate storage. When the objective function is not stored in the basis the computation of reduced costs is somewhat slower. In the later versions of v5.5 there is the option to calculate reduced cost in the textbook way: completely independently of the basis.
a character vector specifying the pivot rule (the rule for selecting row and column entering/leaving) and mode. The first element of this vector must be one of the four pivot rules listed in the first table. Remaining elements (if any) specify modes that modify this rule. The rule/mode can influence solving times considerably.
"firstindex" : |
Select first. |
"dantzig" : |
Select according to Dantzig. |
"devex" : |
Devex pricing from Paula Harris. |
"steepestedge" : |
Steepest edge. |
"primalfallback" : |
When using the steepest edge rule, fall back to "devex" in the primal. |
"multiple" : |
A preliminary implementation of the multiple pricing scheme. Attractive candidate columns from one iteration may be used in subsequent iterations thus avoiding full updating of reduced costs. In the current implementation, lpSolve only reuses the second best entering column alternative. |
"partial" : |
Enables partial pricing. |
"adaptive" : |
Temporarily use an alternative strategy if cycling is detected. |
"randomize" : |
Adds a small randomization effect to the selected pricer. |
"autopartial" : |
Indicates automatic detection of segmented/staged/blocked models. It refers to partial pricing rather than full pricing. With full pricing, all non-basic columns are scanned, but with partial pricing only a subset is scanned for every iteration. This can speed up several models. |
"loopleft" : |
Scan entering/leaving columns left rather than right. |
"loopalternate" : |
Scan entering/leaving columns alternating left/right. |
"harristwopass" : |
Use Harris' primal pivot logic rather than the default. |
"truenorminit" : |
Use true norms for Devex and steepest edge initializations. |
The default is c("devex", "adaptive")
.
a character vector specifying presolve steps to be carried out before solving. Presolve looks at the model and tries to simplify it so that solving times are shorter. For example a constraint on only one variable is converted to a bound on this variable (and the constraint is deleted) - the model dimensions can change because of this. Both rows and columns can be deleted by the presolve. Also, note that the "lindep"
presolve option can result in the deletion of rows (the linear dependent ones). The get.constraints
function will then return only the values of the rows that are kept.
The presolve options are given in the following table. If any element of presolve
is "none"
then no presolving is done.
"none" : |
No presolve. |
"rows" : |
Presolve rows. |
"cols" : |
Presolve columns. |
"lindep" : |
Eliminate linearly dependent rows. |
"sos" : |
Convert constraints to special ordered sets (SOS), only SOS1 is handled. |
"reducemip" : |
Constraints found redundant in phase 1 are deleted. This is no longer active since it is rarely effective and also because it adds code complications and delayed presolve effects that are not captured properly. |
"knapsack" : |
Simplification of knapsack-type constraints through the addition of an extra variable. This also helps bound the objective function. |
"elimeq2" : |
Direct substitution of one variable in 2-element equality constraints; this requires changes to the constraint matrix. |
"impliedfree" : |
Identify implied free variables (releasing their explicit bounds). |
"reducegcd" : |
Reduce (tighten) coefficients in integer models based on GCD argument. |
"probefix" : |
Attempt to fix binary variables at one of their bounds. |
"probereduce" : |
Attempt to reduce coefficients in binary models. |
"rowdominate" : |
Identify and delete qualifying constraints that are dominated by others, also fixes variables at a bound. |
"coldominate" : |
Delete variables (mainly binary) that are dominated by others (only one can be non-zero). |
"mergerows" : |
Merges neighboring >= or <= constraints when the vectors are otherwise relatively identical into a single ranged constraint. |
"impliedslk" : |
Converts qualifying equalities to inequalities by converting a column singleton variable to a slack variable. The routine also detects implicit duplicate slacks from inequality constraints and fixes and removes the redundant variable. This removal also tends to reduce the risk of degeneracy. The combined function of this option can have a dramatic simplifying effect on some models. |
"colfixdual" : |
Variable fixing and removal based on the signs of the associated dual constraint. |
"bounds" : |
Bound tightening based on full-row constraint information. This can assist in tightening the objective function bound, eliminate variables and constraints. At the end of presolve, it is checked if any variables can be deemed free, thereby reducing any chance that degeneracy is introduced via this presolve option. |
"duals" : |
Calculate duals. |
"sensduals" : |
Calculate sensitivity if there are integer variables. |
The default is c("none")
.
a numeric value specifying the relative scaling convergence criterion for the active scaling mode; the integer part specifies the maximum number of iterations. The default is 5
.
a character vector specifying the scaling algorithm used and zero or more augmentations. The first element must be one of the scaling algorithms given in the following table.
"none" : |
No scaling (not advised). |
"extreme" : |
Scale to convergence using largest absolute value. |
"range" : |
Scale based on the simple numerical range. |
"mean" : |
Numerical range-based scaling. |
"geometric" : |
Geometric scaling. |
"curtisreid" : |
Curtis-Reid scaling. |
Additional elements (if any) from the following table can be included to augment the scaling algorithm.
"quadratic" : |
|
"logarithmic" : |
Scale to convergence using logarithmic mean of all values. |
"power2" : |
Power scaling. |
"equilibrate" : |
Make sure that no scaled number is above 1 . |
"integers" : |
Scale integer variables. |
"dynupdate" : |
Recompute scale factors when resolving the model. |
"rowsonly" : |
Only scale rows. |
"colsonly" : |
Only scale columns. |
By default, lpSolve computes scale factors once for the original model. If a solve is done again (most probably after changing some data in the model), the scaling factors are not recomputed. Instead, the scale factors from the original model are used. This is not always desirable, especially if the data has changed considerably. Including "dynupdate"
among the scale algorithm augmentations instructs lpSolve to recompute the scale factors each time solve
is called. Note that the scaling done by "dynupdate"
is incremental and the resulting scale factors are typically different from those computed from scratch.
The default is c("geometric", "equilibrate", "integers")
.
one of "max"
or "min"
specifying whether the model is a maximization or a minimization problem.
a character vector of length one or two composed of "primal"
and "dual"
. If length two then the first element describes the simplex type used in phase 1 and the second element the simplex type used in phase 2. If length one then that simplex type is used for both phases. The default is c("dual", "primal")
.
a positive integer value specifying the number of seconds after which a timeout will occur. If zero, then no timeout will occur.
a character string controlling the severity of messages reported by lp_solve
. The possible choices are given in the table below. All errors/warnings in lp_solve
have a particular severiy: for example, specifying a wrong row or column index is considered a severe error. All messages equal to and below the set level are reported (in the console).
"neutral" : |
No reporting. |
"critical" : |
Only critical messages are reported. Hard errors like instability, out of memory, etc. |
"severe" : |
Only severe messages are reported. Errors. |
"important" : |
Only important messages are reported. Warnings and Errors. |
"normal" : |
Normal messages are reported. |
"detailed" : |
Detailed messages are reported. Like model size, continuing B&B improvements, etc. |
"full" : |
All messages are reported. Useful for debugging purposes and small models. |
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Create a new lpSolve linear program model object.
make.lp(nrow = 0, ncol = 0, verbose = "neutral")
make.lp(nrow = 0, ncol = 0, verbose = "neutral")
nrow |
a nonnegative integer value specifying the number of constaints in the linear program. |
ncol |
a nonnegative integer value specifying the number of decision variables in the linear program. |
verbose |
a character string controlling the level of error reporting. The default value |
an lpSolve linear program model object. Specifically an R external pointer with class lpExtPtr
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 3)
lps.model <- make.lp(4, 3)
Set or retrieve the name of an lpSolve linear program model object.
name.lp(lprec, name)
name.lp(lprec, name)
lprec |
an lpSolve linear program model object. |
name |
an optional character string giving a new name for |
If name
is provided then this function sets the name of the lpSolve linear program model object. If name
is missing then this function retrieves the name from lprec
.
there is no return value if the name
argument is given. Otherwise a character string containing the name of the lpSolve linear program model object.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) name.lp(lps.model, "Simple LP") name.lp(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) name.lp(lps.model, "Simple LP") name.lp(lps.model)
Plots the feasible set of a simple linear program with two decision variables. The decision variables must be real, nonnegative and must not have a finite upper bound. Only inequality constraints are supported.
## S3 method for class 'lpExtPtr' plot(x, y, ...)
## S3 method for class 'lpExtPtr' plot(x, y, ...)
x |
an lpSolve linear program model object. |
y |
this argument is ignored. |
... |
additional arguments are ignored. |
Kjell Konis [email protected]
Display an lpSolve linear program model object in the console.
## S3 method for class 'lpExtPtr' print(x, ...)
## S3 method for class 'lpExtPtr' print(x, ...)
x |
an lpSolve linear program model object. |
... |
additional arguments are ignored. |
x
is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Read an lpSolve linear program model object from a file.
read.lp(filename, type = c("lp", "mps", "freemps"), verbose = "neutral", options)
read.lp(filename, type = c("lp", "mps", "freemps"), verbose = "neutral", options)
filename |
a character string giving the name of the file which the linear programming model is to be read from. |
type |
the type of file provided in |
verbose |
a character string controlling the level of error reporting. The default value |
options |
a character vector of options for the (free)mps parser. Possible values are
|
an lpSolve linear program model object.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Resize the data structures in an lpSolve linear program model object.
resize.lp(lprec, nrow, ncol)
resize.lp(lprec, nrow, ncol)
lprec |
an lpSolve linear program model object. |
nrow |
a single nonnegative integer value specifying the new number of rows for the lpSolve linear program model object. |
ncol |
a single nonnegative integer value specifying the new number of rows for the lpSolve linear program model object. |
If the new size of the model is smaller than the size of the current model, the excess rows and/or columns are deleted. If the new size is larger, no change will be immediately apparent. However, the internal structures of lprec
will have been adjusted to accommodate the larger model. Efficiency of model building can be improved by calling this function before adding additional columns (for example).
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 0) resize.lp(lps.model, 4, 2) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind)
lps.model <- make.lp(4, 0) resize.lp(lps.model, 4, 2) x <- c(6,2,4,9) add.column(lps.model, x) y <- c(3,1,5) ind <- c(1,2,4) add.column(lps.model, y, ind)
Switch to row entry mode.
row.add.mode(lprec, state)
row.add.mode(lprec, state)
lprec |
an lpSolve linear program model object. |
state |
optional: either |
The best way to build a linear program model in lpSolve is column by column, hence row entry mode is turned off by default. If the model must be built by adding constraints, the performance of the add.constraint
function can be greatly improved by turning row entry mode on.
There are several caveats associated with row entry mode. First, only use this function on lpSolve linear program models created by make.lp
. Do not use this function on models read from a file. Second, add the objective function before adding the constraints. Third, do not call any other API functions while in row entry mode; no other data matrix access is allowed. After adding all the contraints, turn row entry mode off. Once turned off, you cannot switch back to row entry mode.
"on"
if row entry mode is on in lprec
; otherwise "off"
.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Select which solution is returned by the lpSolve accessor methods.
select.solution(lprec, solution)
select.solution(lprec, solution)
lprec |
an lpSolve linear program model object. |
solution |
optional. An integer between |
When the branch and bound algorithm is used (i.e., when there are integer, semi-continuous or SOS variables in the model) there may be multiple optimal solutions.
a single integer value: the number of optimal solutions.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Set the initial basis in an lpSolve linear program model object.
set.basis(lprec, basis, nonbasic = FALSE, default = FALSE)
set.basis(lprec, basis, nonbasic = FALSE, default = FALSE)
lprec |
an lpSolve linear program model object. |
basis |
a numeric vector of unique values from the set |
nonbasic |
a logical value. If |
default |
a logical value. If |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Set bounds on the decision variables in an lpSolve linear program model object.
set.bounds(lprec, lower = NULL, upper = NULL, columns = 1:n)
set.bounds(lprec, lower = NULL, upper = NULL, columns = 1:n)
lprec |
an lpSolve linear program model object. |
lower |
a numeric vector of lower bounds to be set on the decision variables specified in |
upper |
a numeric vector of upper bounds to be set on the decision variables specified in |
columns |
a numeric vector of values from the set |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 4) set.bounds(lps.model, lower = rep(-1.0, 4)) set.bounds(lps.model, upper = 1:4) set.bounds(lps.model, lower = rep(0.0, 4), upper = rep(1.0, 4))
lps.model <- make.lp(0, 4) set.bounds(lps.model, lower = rep(-1.0, 4)) set.bounds(lps.model, upper = 1:4) set.bounds(lps.model, lower = rep(0.0, 4), upper = rep(1.0, 4))
Specify which branch to take first in the branch-and-bound algorithm for decision variables in an lpSolve linear program model object.
set.branch.mode(lprec, columns, modes)
set.branch.mode(lprec, columns, modes)
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector containing values from the set |
modes |
a character vector composed of the strings |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Set weights on the variables in an lpSolve linear program model object.
set.branch.weights(lprec, weights)
set.branch.weights(lprec, weights)
lprec |
an lpSolve linear program model object. |
weights |
a numeric vector with |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Set a column in an lpSolve linear program model object.
set.column(lprec, column, x, indices)
set.column(lprec, column, x, indices)
lprec |
an lpSolve linear program model object. |
column |
a single numeric value from the set |
x |
a numeric vector containing the elements (only the nonzero elements if |
indices |
optional for sparse |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 2) set.column(lps.model, 2, c(6,2,4,9)) set.column(lps.model, 1, c(3,1,5), indices = c(1,2,4))
lps.model <- make.lp(4, 2) set.column(lps.model, 2, c(6,2,4,9)) set.column(lps.model, 1, c(3,1,5), indices = c(1,2,4))
Set constraint types in an lpSolve linear program model object.
set.constr.type(lprec, types, constraints = 1:m)
set.constr.type(lprec, types, constraints = 1:m)
lprec |
an lpSolve linear program model object. |
types |
either a numeric vector or a character vector containing elements from the set |
constraints |
a numeric vector of unique values from the set {1, ..., m} (where m is the number of constraints in |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 2) x <- c(6,2,4,9) set.column(lps.model, 2, x) y <- c(3,1,5) ind <- c(1,2,4) set.column(lps.model, 1, y, ind) set.constr.type(lps.model, rep("<=", 4))
lps.model <- make.lp(4, 2) x <- c(6,2,4,9) set.column(lps.model, 2, x) y <- c(3,1,5) ind <- c(1,2,4) set.column(lps.model, 1, y, ind) set.constr.type(lps.model, rep("<=", 4))
Set constraint values in an lpSolve linear program model object.
set.constr.value(lprec, rhs = NULL, lhs = NULL, constraints = 1:m)
set.constr.value(lprec, rhs = NULL, lhs = NULL, constraints = 1:m)
lprec |
an lpSolve linear program model object. |
rhs |
a numeric vector the same length as |
lhs |
a numeric vector the same length as |
constraints |
a numeric vector of unique values from the set {1, ..., m} (where m is the number of constraints in |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Set the value of a single matrix element in an lpSolve linear program model object.
set.mat(lprec, i, j, value)
set.mat(lprec, i, j, value)
lprec |
an lpSolve linear program model object. |
i |
a single numeric value from the set |
j |
a single numeric value from the set |
value |
a single numeric value. |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 2) x <- c(6,2,4,9) set.column(lps.model, 2, x) y <- c(3,1,5) ind <- c(1,2,4) set.column(lps.model, 1, y, ind) set.constr.type(lps.model, rep("<=", 4)) set.mat(lps.model, 3, 2, 4.5)
lps.model <- make.lp(4, 2) x <- c(6,2,4,9) set.column(lps.model, 2, x) y <- c(3,1,5) ind <- c(1,2,4) set.column(lps.model, 1, y, ind) set.constr.type(lps.model, rep("<=", 4)) set.mat(lps.model, 3, 2, 4.5)
Set the objective function in an lpSolve linear program model object.
set.objfn(lprec, obj, indices)
set.objfn(lprec, obj, indices)
lprec |
an lpSolve linear program model object. |
obj |
a numeric vector of length |
indices |
optional for sparse |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(2, 4) set.objfn(lps.model, c(1,2,3,4)) set.objfn(lps.model, c(5,7,6), indices = c(1,2,4))
lps.model <- make.lp(2, 4) set.objfn(lps.model, c(1,2,3,4)) set.objfn(lps.model, c(5,7,6), indices = c(1,2,4))
Set elements on the right-hand-side of an lpSolve linear program model object.
set.rhs(lprec, b, constraints = 1:m)
set.rhs(lprec, b, constraints = 1:m)
lprec |
an lpSolve linear program model object. |
b |
a numeric vector of length |
constraints |
a numeric vector containing unique elements from the set {1, ..., m} (where m is the number of constraints in |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(4, 2) x <- c(6,2,4,9) set.column(lps.model, 2, x) y <- c(3,1,5) ind <- c(1,2,4) set.column(lps.model, 1, y, ind) set.rhs(lps.model, c(10, 20, 40, 80))
lps.model <- make.lp(4, 2) x <- c(6,2,4,9) set.column(lps.model, 2, x) y <- c(3,1,5) ind <- c(1,2,4) set.column(lps.model, 1, y, ind) set.rhs(lps.model, c(10, 20, 40, 80))
Set a column in an lpSolve linear program model object.
set.row(lprec, row, xt, indices)
set.row(lprec, row, xt, indices)
lprec |
an lpSolve linear program model object. |
row |
a single numeric value from the set |
xt |
a numeric vector containing the constraint coefficients (only the nonzero coefficients if |
indices |
optional for sparse |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(2, 4) set.row(lps.model, 2, c(6,2,4,9)) set.row(lps.model, 1, c(3,1,5), indices = c(1,2,4))
lps.model <- make.lp(2, 4) set.row(lps.model, 2, c(6,2,4,9)) set.row(lps.model, 1, c(3,1,5), indices = c(1,2,4))
Set a decision variable as semicontinuous in an lpSolve linear program model object.
set.semicont(lprec, columns, sc = TRUE)
set.semicont(lprec, columns, sc = TRUE)
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector of unique values from the set |
sc |
a logical value. If |
Decision variables have both a type and a kind. The type is either real
or integer
and indicates the type of values the decision variable may take. The kind is one of {standard, semi-continuous, SOS}
. Semi-continuous decision variables can take allowed values between their upper and lower bound as well as zero. Please see the link in the references for further details.
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
Set the type of a decision variable in an lpSolve linear program model object.
set.type(lprec, columns, type = c("integer", "binary", "real"))
set.type(lprec, columns, type = c("integer", "binary", "real"))
lprec |
an lpSolve linear program model object. |
columns |
a numeric vector of unique values from the set |
type |
either |
A binary decision variable is simply an integer decision with an upper bound of one and a lower bound of zero. When type = "binary"
the type of the decision variable will be set to "integer"
and the bounds will be set to zero and one respectively.
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) set.type(lps.model, 2, "binary") xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.type(lps.model, 3, "integer") set.objfn(lps.model, c(-3,-4,-3)) get.type(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) set.type(lps.model, 2, "binary") xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.type(lps.model, 3, "integer") set.objfn(lps.model, c(-3,-4,-3)) get.type(lps.model)
Attempt to compute the optimal solution of an lpSolve linear program model object.
## S3 method for class 'lpExtPtr' solve(a, b, ...)
## S3 method for class 'lpExtPtr' solve(a, b, ...)
a |
an lpSolve linear program model object. |
b |
this argument is ignored. |
... |
additional arguments are ignored. |
a single integer value containing the status code.
0: | "optimal solution found" |
1: | "the model is sub-optimal" |
2: | "the model is infeasible" |
3: | "the model is unbounded" |
4: | "the model is degenerate" |
5: | "numerical failure encountered" |
6: | "process aborted" |
7: | "timeout" |
9: | "the model was solved by presolve" |
10: | "the branch and bound routine failed" |
11: | "the branch and bound was stopped because of a break-at-first or break-at-value" |
12: | "a feasible branch and bound solution was found" |
13: | "no feasible branch and bound solution was found" |
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model)
lps.model <- make.lp(0, 3) xt <- c(6,2,4) add.constraint(lps.model, xt, "<=", 150) xt <- c(1,1,6) add.constraint(lps.model, xt, ">=", 0) xt <- c(4,5,4) add.constraint(lps.model, xt, "=", 40) set.objfn(lps.model, c(-3,-4,-3)) solve(lps.model)
Write an lpSolve linear program model object to a file.
write.lp(lprec, filename, type = c("lp", "mps", "freemps"), use.names = c(TRUE, TRUE))
write.lp(lprec, filename, type = c("lp", "mps", "freemps"), use.names = c(TRUE, TRUE))
lprec |
an lpSolve linear program model object. |
filename |
a character string containing the name of the output file. |
type |
either |
use.names |
a logical vector of length two specifying repectively whether row and column names should be written into the file. If |
a NULL
value is invisibly returned.
Kjell Konis [email protected]
https://lpsolve.sourceforge.net/5.5/index.htm