Closed justlebeau closed 2 years ago
Error in
[.OmprLinearVariableCollection(y, i, j) : object 'i' not found
Given the error in i
reported, I am guessing that it doesn't like the totalcost(i)
term in:
add_constraint(totalcost(i)<=capacity[i],i=1:nmodels)
Without knowing exactly what your intended constraint intent is, suggest substituting the totalcost
term with the ompr sum_over
function and explicitly indexing over j
. The ompr documentation has 2 dimensional examples of sum_over
.
BTW, also suggest installing and using the latest development version of ompr:
remotes::install_github("dirkschumacher/ompr")
remotes::install_github("dirkschumacher/ompr.roi")
It has better performance, additional functionality and behaves properly. Note the ompr documentation has not yet been updated to reflect Dirk's package updates. The sum_expr
term has been deprecated and replaced by sum_over
.
Thanks for the tips!
The intent is to have 2 matrices: x and y. X providing the allocation amount for df and y the schedule (1,0) allowing only 1 per week. I'm wanting to constrain the sum of the product of the rows of df, x, and y to each capacity[I]
The problem is in the objective function:
# this uses the base R sum function
set_objective(sum(y[i,j],i = 1:nmodels,j=1:nproducts),sense="max")
# but you have to use sum_over
set_objective(sum_over(y[i,j],i = 1:nmodels,j=1:nproducts),sense="max")
Also checkout reprex. this helps creating reproducible examples. But nothing wrong with your code, just a suggestion 😊
BTW, also suggest installing and using the latest development version of ompr:
CRAN and development should be nearly identical ATM. At least I hope 😅
For tips/help on modelling please use the Discussion
section.
Hi,
I am new to the package but it seems the choice of anyone looking at OR problems.
I have the following allocation/scheduling problem:
I'm wanting to allocate the values in df as percentages and then have a schedule associated with the allocation. This seems relatively straight forward but I am new to setting these up so any help/direction is appreciated.