I'm trying to optimize a function using two variables in R. My concern is that these 2 variables have only specific possible values. I found solution with lower/upper limits using noptr
but I'm not able to "force" the value taken by both variables. An example will be easier to understand using constrOptim
function:
g <- function(x,y) 100*x+150*y
gb <- function(x) g(x[1], x[2])
A <- matrix(c(1,0,0,1,100,150),3,2,byrow=T)
b <- c(0,0,350)
constrOptim(theta=c(2,2), f=gb, grad=NULL, ui=A, ci=b)
Thus, I want x
& y
to take the values 0, 1 or 2. In my example, the constraints are further written as x>=0
,y>=0
and 100x+150y>=350
.
My goal is to minimize 100*x+150*y
respecting 100x+150y>=350
where x
and y
are taking values in c(0,1,2)
only!