I'm trying to set a model objective, and I have a matrix A with the same number of rows as the number of variables, which are binary. And basically I want to take a columnwise average using only the rows that end up being chosen (x = 1). In this example 3 rows will be chosen. My attempt (shown below) at doing this involves using sum_expr on rows of A; the m th row would only contribute to the sum if x[m] = 1. But I get an error. Do you have a suggested way of handling this?
k=3
x <- model$add_variable("x", type="binary", i=1:n_models)
model$set_objective(sum_expr(mean(k/sum_expr(A[m,]x[m],m=1:n_models)A[i,])*x[i],i=1:n_models))
I'm trying to set a model objective, and I have a matrix A with the same number of rows as the number of variables, which are binary. And basically I want to take a columnwise average using only the rows that end up being chosen (x = 1). In this example 3 rows will be chosen. My attempt (shown below) at doing this involves using sum_expr on rows of A; the m th row would only contribute to the sum if x[m] = 1. But I get an error. Do you have a suggested way of handling this?
k=3 x <- model$add_variable("x", type="binary", i=1:n_models) model$set_objective(sum_expr(mean(k/sum_expr(A[m,]x[m],m=1:n_models)A[i,])*x[i],i=1:n_models))