简体   繁体   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 ). 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 ). I am running my implementation on a Linux Supercomputing server at my University that has 248gb of memory, which I'd think would be sufficient for the job.我正在我大学的 Linux 超级计算服务器上运行我的实现,该服务器有 248gb 的 memory,我认为这足以完成这项工作。

Here is my code and output from the failure report from the server:这是我的代码和来自服务器的故障报告中的 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

For the purposes of creating a reproducible example, mock versions of n.ij and boats.n.ij can be generated as follows:为了创建可重现的示例,可以按如下方式生成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

Why am I failing to add the objective to my model?为什么我无法将目标添加到我的 model? Is it just that I am implying the existence of three very large matrices (the decision matrix u , the boats.n.ij matrix, and their product matrix)?仅仅是我在暗示存在三个非常大的矩阵(决策矩阵uboats.n.ij矩阵和它们的乘积矩阵)吗? Is it because the model is already a file that is about 6.8gb?是不是因为model已经是6.8gb左右的文件了? Is there a cap on memory or object size imposed by R I am running into?我遇到的 R 对 memory 或 object 大小是否有上限? Are these functions just not capable of considering an objective with this many decision points?这些功能是否无法考虑具有这么多决策点的目标?

I can confirm that I have been able to run a scaled-down version of the model on a very small subset of boats.n.ij that optimizes just fine, so I don't think it's an issue with my model specification, but I could be wrong...I should also state explicitly I am not interested in solutions that do not involve solving this model in R, as that is the express objective here.我可以确认我已经能够在一个很小的boats.n.ij 子集上运行boats.n.ij的缩小版本,优化得很好,所以我认为这不是我的 model 规范的问题,但我可能是错的......我也应该明确地 state 我对不涉及在 R 中解决此 model 的解决方案不感兴趣,因为这是这里的明确目标。 I am open, however, to using other packages if there's a more robust one available (although I like this one otherwise).但是,如果有更强大的包可用,我愿意使用其他包(尽管我喜欢这个包)。

Note: Unlike in the paper I've cited, I have eliminated the need for a vector called b.ij that my colleague does use, so that isn't the issue here.注意:与我引用的论文不同,我不再需要我的同事使用的名为b.ij的向量,所以这不是这里的问题。

An attempt:一次尝试:

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