add.constraint: Add Constraint

Description Usage Arguments Details Value Author(s) References Examples

View source: R/add.constraint.q

Description

Add a constraint to an lpSolve linear program model object.

Usage

1
add.constraint(lprec, xt, type = c("<=", "=", ">="), rhs, indices, lhs)

Arguments

lprec

an lpSolve linear program model object.

xt

a numeric vector containing the constraint coefficients (only the nonzero coefficients if indices is also given). The length of xt must be equal to the number of decision variables in lprec unless indices is provided.

type

a numeric or character value from the set {1 = "<=", 2 = ">=", 3 = "="} specifying the type of the constraint.

rhs

a single numeric value specifying the right-hand-side of the constraint.

indices

optional for sparse xt. A numeric vector the same length as xt of unique values from the set {1, ..., n} where n is the number of decision variables in lprec; xt[i] is entered into column indices[i] in the added constraint. The coefficients for the columns not in indices are set to zero. This argument should be omitted when length(xt) == n.

lhs

optional. A single numeric value specifying the left-hand-side of the constraint.

Details

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).

Value

a NULL value is invisibly returned.

Author(s)

Kjell Konis [email protected]

References

http://lpsolve.sourceforge.net/5.5/index.htm

Examples

1
2
3
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))

Example output



lpSolveAPI documentation built on May 30, 2017, 7:12 a.m.