我可以在优化前预求解 ILP 模型吗?

Can I presolve an ILP model before optimization?

我在构建模型时内存不足。有没有办法在使用现有函数构建模型的同时减少模型?

详情: 假设我有以下模型(来自文档 here 部分 Presolve。实际代码也使用稀疏矩阵,所以这只是为了弄清楚可以进一步做什么):

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)

显然,满足所有这些约束的唯一方法是 x1 = 7, x2 = 3, and x3 = 5。 我的目标是尽可能减小尺寸 "on the fly"。在伪代码中:

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)

其中 model1 仅包含变量 x4 作为 x1 = 7, x2 = 3, and x3 = 5(预求解)。这可能吗?

评论

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

可重现的例子

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

v8.0 不支持。正如@GregGlockner 所说:

如 Whosebug 中所述 "Gurobi lets you access the presolved model, but only from the Python API"