I am familiar with how to use
ompr::MIPModel but I am trying to learn how to use
MILPModel to take advantage of the model build speed. A simplified version of my model is below. I have two decision variables,
y, binary and of equal length. I have constraints on the sum of all the
x decision variables, and the sum of all the
y decision variables. So far so good with
MILPModel, I can build the model and solve it fast.
The problem is when I try to use the next constraint. The LHS of this constraint multiplies the
x binary decision variables by a numeric column in a dataframe of the same length, then multiplies that by a matrix where the rows are equal to the length of
x. Similar story in the RHS with the
y variable. I then iterate this constraint 20 times to represent all the columns of the matrix.
I've used constraints similar to this many times using
MIPModel, but now when I try this I get an error message,
non-numeric argument to binary operator. I assume this has something to do with the
colwise function, but I am completely lost on how to approach this, even after reading up on the ompr github site. Thanks in advance for any help.
add_variable(x[i], i=1:10, type='binary') %>% add_variable(y[i], i=1:10, type='binary') %>% add_constraint(sum_expr(x[i],i=1:10) <= 5) %>% add_constraint(sum_expr(y[i],i=1:10) <= 3) %>% #model builds and solves until this point... add_constraint( sum_expr( x[i]* df$numeric_column[i] * matrix_a[i,j],i=1:10) <= sum_expr( 2* y[i]* df$numeric_column[i] * df$other_numeric_column[i] * matrix_a[i,j],i=1:10), j=1:20)