Repository navigation
Replies: 8 comments
|
I don't think you need the last |
|
Thanks! I tried that, but then I get the error: |
|
You have to load in a library that contains the piping function, e.g., You could also create a .Rprofile file in an R Project folder for your optimization models: |
|
Thanks! The updated code is: mymodel <- MILPModel() %>% |
|
First examine the verbose outputs to see if the column and row dimensions are what you expect. You can then write out your model in standard form and visually inspect it to see if your formulation is giving you what you want: You can add that code block after the formulation and before the solve function. The code will write out your model to a model.txt file in your working directory. The file will be accessible in the Files tab of the Files, Plots... pane of RStudio. Click on the model.txt file and it will open in a tab in the Source pane. View the tab to see the contents. The variable names are fixed and only linearly indexed, but you should be able to figure out if you are getting what you want. You can then iterate by adjusting your model and re-creating the model.txt file. |
|
I know where it goes wrong. I get the message "non-numeric argument to binary operator" for my first constraint. There is a matrix multiplication in there (matrix*vector) and I already read that this gives problems. I do not know how to solve this. Can anybody help me? Propose a way to do this multiplication while the package accepts this? I would really appreciate it! code: |
|
Doing matrix operations with the I and others have not figured out a way to formulate sparse constraint matrices using |
|
I convert that to discussions. |
Uh oh!
There was an error while loading. Please reload this page.
I'm an ompr beginner, new also to MIP in general, so this may be trivial. I want to run the maximum expected covering location problem. But if I run it with in the end "solution <- solve_model(mymodel, withROI(solver="glpk",verbose=TRUE))", it always gives an error "object 'mymodel' not found" and if I run it with in the end "solution <-solve_model(withROI(solver="glpk",verbose=TRUE))", it gives an error "no applicable method for 'solve_model' applied to an object of class "function"". I wonder what is wrong with my code. Thanks! Lotte
mymodel <- MILPModel() %>%
add_variable(x[p], p=1:185,type="integer") %>%
add_variable(y[p,r], p=1:185,r=1:12, type="binary") %>%
set_objective(sum_expr(sum_expr((demand[p]*(1-0.45)*0.45^(r-1))*y[p,r],r = 1:12),p=1:185)) %>%
add_constraint(sum_expr(as.numeric(covers[q,p])*x[p],p=1:185) >= sum_expr(y[q,r], r=1:12),q=1:185) %>%
add_constraint(sum_expr(x[p],p=1:185) <= 12) %>%
solution <- solve_model(mymodel, with_ROI(solver="glpk",verbose=TRUE))
All reactions