Does sum_expr work with vectors? #74
Unanswered
alexcharn5
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Quick answer: it is not vectorized. You could do something like |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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))
Beta Was this translation helpful? Give feedback.
All reactions