1

I am getting out of memory while building the model. Is there any way, to reduce the model while building it using existing functions?

Details: Assume I have the following model (from the docs here section Presolve. The real code also uses sparse matrices, so this is just to figure out what can be done further):

min 2*x1 - 5*x2 + 3*x3 + 10*x4
s.t.
x1 + x2 + x3 = 15 (1)
x1 <= 7           (2)
x2 <= 3           (3)
x3 <= 5           (4)
x4 > 1            (5)

Clearly the only way that all of these constraints can be satisfied is if x1 = 7, x2 = 3, and x3 = 5. My goal is to reduce dimensions "on the fly" if possible. In pseudo-code:

model <- build_model(objective_function,
                     restrictions (1) to (4))
model1 <- presolve_model(model)
model2 <- build_model(objective_function1,
                     restrictions model1 and (5))
result <- gurobi::gurobi(model2)

Where model1 only consists of the variable x4 as x1 = 7, x2 = 3, and x3 = 5 (presolved). Is this possible?

Comments:

  • In Gurobi's Python interface you can perhaps use presolve.model()? See here but I have no clue how that is done. I also didn't find a possibility to return the presolved model from gurobi::gurobi(). However, the last two lines in the reprducible example return the model as a file - but NOT the presolved, as can be seen from the example.
  • Gurobi does presolving, as can be seen from the parameter Presolve.
  • Experts might want to have a look at this package.
  • Maybe it is related to the vbasis and cbasis argument from Gurobi? The docs state

Finally, if the final solution is a basic solution (computed by simplex), then vbasis and cbasis will be present.

Reproducible example:

model <- list()
model$A          <- matrix(c(1, 1, 1, 0, 
                             1, 0, 0, 0, 
                             0, 1, 0, 0, 
                             0, 0, 1, 0, 
                             0, 0, 0, 1), nrow = 5, ncol = 4, byrow = T)
model$obj        <- c(2, -5, 3, 10)
model$modelsense <- "min"
model$rhs        <- c(15, 7, 3, 5, 1)
model$sense      <- c('=', '<=', '<=', '<=', '>')
model$vtype      <- 'I'
params <- list(OutputFlag = 1, Presolve = 2, TimeLimit = 3600)

result <- gurobi::gurobi(model, params) # optimize

# gurobi::gurobi_write(model, 'mymodel.mps') # output to file
# gurobi::gurobi_write(model, 'mymodel.lp') # output to file
14
  • Sorry not clear... are you trying to get the pre-solved problem or solve the original problem exploiting pre-solve ? If it's the latter, I think that gurobi default presolve should be able to do as much as possible, if you're getting out-of-memory then your problem is really too big and you should think to change the formulation
    – digEmAll
    Apr 9, 2018 at 14:09
  • @digEmAll In your words, I tried to get the pre-solved problem (in order to reduce the problem while building).
    – Christoph
    Apr 9, 2018 at 14:16
  • Oh I got it, so you're getting out-of-memory error while building the problem... mmh unfortunately the package you posted doesn't seem to expose presolve.model() function
    – digEmAll
    Apr 9, 2018 at 14:54
  • @digEmAll That's true! That's the reason for my question... I thought I'd better ask here before I start to develop a function for the next weeks / months ;-) Do you think my idea is good? I googled quite some time and it seems nobody goes along that line...
    – Christoph
    Apr 9, 2018 at 15:05
  • Makes sense...well, it depends on the memory you will save by presolving... is your problem supposed to have a lot of variables with implied bounds, useless constraints etc ? In this case it makes sense, otherwise you're just going to postpone the out-of-memory error ;)
    – digEmAll
    Apr 9, 2018 at 15:29

1 Answer 1

0

It is not possible with v8.0. As @GregGlockner stated:

As stated in this stackoverflow questions "Gurobi lets you access the presolved model, but only from the Python API"

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.