簡體   English   中英

在 R 中的 ompr package 中,是什么導致“問題太大”錯誤?

[英]In the ompr package in R, what causes the "problem too large" error?

I am trying to learn to fit a linear integer programming optimization model in R using the ompr package that a colleague had previously fit using CPLEX/GAMS (specifically, the one described here: Haight et al. 2021 ). 我正在我大學的 Linux 超級計算服務器上運行我的實現,該服務器有 248gb 的 memory,我認為這足以完成這項工作。

這是我的代碼和來自服務器的故障報告中的 output:

#Read in the necessary pre-generated data and packages

library(pacman); library(dplyr); library(ROI); library(ompr); library(ompr.roi)
n.ij = readRDS(file="nij1.rds") #An indexing vector.
B = 10 #Budget constraint--inspect only 10 lakes maximum

#Initialize model prior to setting the objective.
mod1 = MILPModel() %>% 
add_variable(u[i, j], type = "binary", i = 1:n.ij, j = 1:n.ij) %>%
add_variable(x[i], type = "binary", i = 1:n.ij) %>% 
add_variable(x[j], type = "binary", j = 1:n.ij) %>% 
add_constraint(x[i] + x[j] >= u[i,j], i = 1:n.ij, j = 1:n.ij) %>% 
add_constraint(sum_expr(x[i], i = 1:n.ij) <= B)
 
#Read in the relevant adjacency matrix of boat movements between every pair of lakes.
boats.n.ij = readRDS(file="boatsnij1.rds")

#Some system and object size info.
system(paste0("cat /proc/",Sys.getpid(),"/status | grep VmSize"))
VmSize: 13017708 kB
object.size(mod1)
6798778288 bytes

#Now, set objective with this specific boats.n.ij file.
mod1.full = mod1 %>% 
set_objective(sum_expr(u[i,j] * boats.n.ij[i, j], i = 1:n.ij, j = 1:n.ij))

Error in subCsp_ij(x, i, j, drop = drop) : 
  Cholmod error 'problem too large' at file ../Core/cholmod_sparse.c, line 89
Calls: %>% ... [ -> callGeneric -> eval -> eval -> [ -> [ -> subCsp_ij
Execution halted

為了創建可重現的示例,可以按如下方式生成n.ijboats.n.ij的模擬版本:

library(Matrix)

boats = rpois(7940*7940, 2)
keep = sample(c(0,1), 7940*7940, replace=T, prob = c(0.8, 0.2))
boat.dat = boats*keep

boats.n.ij = matrix(boat.dat, nrow=7940, ncol=7940)
diag(boats.n.ij) = 0
boats.n.ij = Matrix(boats.n.ij, sparse = T)

boats.n.ij[1:10, 1:10]

n.ij = 1:7940

為什么我無法將目標添加到我的 model? 僅僅是我在暗示存在三個非常大的矩陣(決策矩陣uboats.n.ij矩陣和它們的乘積矩陣)嗎? 是不是因為model已經是6.8gb左右的文件了? 我遇到的 R 對 memory 或 object 大小是否有上限? 這些功能是否無法考慮具有這么多決策點的目標?

我可以確認我已經能夠在一個很小的boats.n.ij 子集上運行boats.n.ij的縮小版本,優化得很好,所以我認為這不是我的 model 規范的問題,但我可能是錯的......我也應該明確地 state 我對不涉及在 R 中解決此 model 的解決方案不感興趣,因為這是這里的明確目標。 但是,如果有更強大的包可用,我願意使用其他包(盡管我喜歡這個包)。

注意:與我引用的論文不同,我不再需要我的同事使用的名為b.ij的向量,所以這不是這里的問題。

一次嘗試:

require(slam)
boatsSTM<-as.simple_triplet_matrix(boats.n.ij)
...

#setting the objective function
set_objective(sum_expr(u[boatsSTM$i[k], boatsSTM$j[k]] * boatsSTM$v[k], k = 1:length(boatsSTM$i)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM