问题
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 fromgurobi::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
andcbasis
argument from Gurobi? The docs state
Finally, if the final solution is a basic solution (computed by simplex), then
vbasis
andcbasis
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
回答1:
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"
来源:https://stackoverflow.com/questions/49734762/can-i-presolve-an-ilp-model-before-optimization