问题
Hello everyone and thanks in advance! I've had a bit of an interesting journey with this problem. Here I figured out how to create a file-backed big matrix using the bigmemory
package. This 7062 row by 364520 column matrix is the constraint matrix in a linear programming problem I'm trying to solve using the Rsymphony
package. The code is below and the constraint matrix is called mat
:
Rsymph <- Rsymphony_solve_LP(obj
,mat[1:nrow(mat),1:ncol(mat)]
,dir
,rhs
,types="B",max=F, write_lp=T)
Unfortunately when I run this, Rsymphony
tries bringing the file-backed matrix into memory and I don't have enough RAM. The only reason why I even created the big matrix with bigmemory
in the first place was to use as little RAM as possible. Is there any way I can with this code or using another linear programming function complete this with the amount of memory I have available? Thanks.
回答1:
This was my concern before. By running mat[...]
you are converting the big.matrix
in to a regular matrix
. The function will need to be rewritten so it is compatible with big.matrix
objects. If you look at the source code for R_symphony_solve_LP
you will find the following call:
out <- .C("R_symphony_solve",
as.integer(nc),
as.integer(nr),
as.integer(mat$matbeg),
as.integer(mat$matind),
as.double(mat$values),
as.double(col_lb),
as.double(col_ub),
as.integer(int),
if(max) as.double(-obj) else as.double(obj),
obj2 = double(nc),
as.character(paste(row_sense, collapse = "")),
as.double(rhs),
double(),
objval = double(1L),
solution = double(nc),
status = integer(1L),
verbosity = as.integer(verbosity),
time_limit = as.integer(time_limit),
node_limit = as.integer(node_limit),
gap_limit = as.double(gap_limit),
first_feasible = as.integer(first_feasible),
write_lp = as.integer(write_lp),
write_mps = as.integer(write_mps))
This C function will need to be rewritten for it to be compatible with big.matrix
objects. If the use of this function is critically important to you, there are some examples of how to access big.matrix
objects on the Rcpp Gallery website using Rcpp and RcppArmadillo. I am sorry to say there is no easy solution beyond this right now. You either need to get more RAM or start writing some more code.
来源:https://stackoverflow.com/questions/28841813/linear-programming-with-big-matrix-still-having-memory-problems