a%*%x
subject to the
constraints A1%*%x <= b1<="" code="">, A2%*%x >= b2
, A3%*%x = b3
and
x >= 0
. Either maximization or minimization is possible but the default
is minimization.=>
simplex(a, A1=NULL, b1=NULL, A2=NULL, b2=NULL, A3=NULL,
b3=NULL, maxi=F, n.iter=NULL, eps=1e-06)
n
which gives the coefficients of the objective function.m1
by n
matrix of coefficients for the "m1
giving the right hand side of the "<=" constraints.="" this="" argument="" is="" required if="" A1 is given and ignored otherwise. All values
in b1
must be non-negative.=">
m2
by n
matrix of coefficients for the ">=" type of constraints.m2
giving the right hand side of the ">=" constraints.
This argument is required if A2
is given and ignored otherwise. All values
in b2
must be non-negative. Note that the constraints x >=
m3
by n
matrix of coefficients for the equality constraints.m3
giving the right hand side of equality constraints.
This argument is required if A3
is given and ignored otherwise. All values
in b3
must be non-negative.FALSE
(default) and
maximization otherwise. If maxi
is TRUE
then the maximization problem
is recast as a minimization problem by changing the objective function
coeffn+2*(m1+m2+m3)
."simplex"
.x[i] >= b2[i]
they should be omitted by setting
x[i] = x[i]-b2[i]
, changing all the constraints and the objective function
accordingly and then transforming back after the solution has been found.Press, W.H., Teukolsky, S.A., Vetterling, W.T. and Flannery, B.P. (1992) Numerical Recipes: The Art of Scientific Computing (Second Edition). Cambridge University Press.
# This example is taken from Exercise 7.5 of Gill, Murray,
# and Wright (1991).
enj <- c(200, 6000, 3000, -200)
fat <- c(800, 6000, 1000, 400)
vitx <- c(50, 3, 150, 100)
vity <- c(10, 10, 75, 100)
vitz <- c(150, 35, 75, 5)
simplex(a=enj, A1=fat, b1=13800, A2=rbind(vitx, vity, vitz),
b2=c(600, 300, 550), maxi=T)
Run the code above in your browser using DataLab