Closed sbmack closed 2 years ago
You can use filter functions or simple conditions to restrict the combinations of indexes being generated:
add_constraint(buy[p, t] == 1, p = 1:n, m = 1:n, my_filter(p, m))
would add a constraint only if my_filter(p, m)
is true for the combination of the indexes. But you can also add any type of condition that evaluates to TRUE/FALSE. In the case of the current master
version on Github, my_filter
takes scalar (length 1) values and has to return either TRUE or FALSE.
E.g. add_variable(x[a, b], a = 1:n, b = 1:n, a <= b, a %% 2 == 0)
Does that help?
I am trying to define a "sparse" variable set. I.e., not all multi-index combinations are feasible. E.g.
So that is the exhaustive variable set for
produce
However the plant, machine, product index set is restricted to this data frame:I can reduce the size of the
produce
data_frame with aninner_join
produce <- inner_join(vars, data, by = c('plant', 'machine', 'product'))
The question then is how to declare that sparse variable set to MILPModel/MIPModel?
From a comment in an earlier issue thread: https://github.com/dirkschumacher/ompr/issues/234#issuecomment-427889671
So hugolarzabal refers to a filter function
filter = my_filter(p, m)
Can somebody explain the specifics of what the function is and it's return value? I.e. in my case I would have filter = my_filter(plant, machine, product) and my_filter would be what?Thanks for the assistance. SteveM