[R-SIG-Finance] Mixed integer programming

Enrico Schumann e@ @end|ng |rom enr|co@chum@nn@net
Tue Feb 19 14:45:51 CET 2019

>>>>> "Hannu" == Hannu Kahra <hkahra using gmail.com> writes:

    Hannu> I have tried to replicate Example 5.1 in Luenberger: Investment Science.
    Hannu> Here is the model
    Hannu> model <- MIPModel() %>%
    Hannu>   add_variable(x[i], i = 1:7, type = "binary") %>%
    Hannu>   set_objective(200*x[1]+30*x[2]+200*x[3]+60*x[4]+50*x[5]+100*x[6]+50*x[7])
    Hannu> %>%

    Hannu> add_constraint(100*x[1]+20*x[2]+150*x[3]+50*x[4]+50*x[5]+150*x[6]+150*x[7]
    Hannu> <= 500)
    Hannu> solve_model(with_ROI("glpk",verbose = TRUE))

    Hannu> I get the following error

    Hannu> Error in UseMethod("solve_model") :
    Hannu>   no applicable method for 'solve_model' applied to an object of class
    Hannu> "function"

    Hannu>  modelMixed integer linear optimization problem
    Hannu> Variables:
    Hannu>   Continuous: 0
    Hannu>   Integer: 0
    Hannu>   Binary: 7
    Hannu> Model sense: maximize
    Hannu> Constraints: 1

    Hannu> What is wrong? Thank you in advance.

    Hannu> -Hannu

If you want people to help you, you need to provide a
reproducible example. Also, please do not post in HTML,
as code examples get scrambled and become unreadable.

(If I had to venture a guess, I'd think you've
 forgotten one of those `%>%` before 'solve_model'.)

Enrico Schumann
Lucerne, Switzerland

More information about the R-SIG-Finance mailing list