New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in t.default(const.mat) : argument is not a matrix #3
Comments
Hi. Unfortunately lp() does not recognize the sparse matrix type Matrix. You can create your own three-column array of constraints, where a value of (i, j, k) says that in the ith constraint, the value of j is k. Then you can pass that into lp() using the denst.cont argument. I hope this helps. |
Hi Buttrey, |
Hi. Sure. The easy way is to make use of the which() command with the arr.ind = T argument. This returns a two-column matrix giving the rows and columns in which particular entries (in this case, non-zero ones) are found. All we need to do to construct our three-column matrix is to add the non-zero entries to that two-column matrix returned from which(). Here’s an example. I’m going to make up a small matrix that’s mostly zeros. This is not a real problem; it’s just an example.
Now let’s create the matrix where each row gives the row number, column number, and value of a non-zero entry. In this case we expect a 5x3 matrix since A has 5 non-zero entries.
Does that help? |
Hi Hi Buttrey, |
Hi. I need more information. What is dim(A)? What are the commands you used, exactly? Also, you don't want to pass in both types of constraints. Is constr.dirthu the original set of constraints? Or are those the directions? |
Hi, My command is as follows: for (j in (2K+1):(2K+n)) { for (i in 1:K) { f.con<-cbind(which(f.con!=0,T), f.con[f.con!=0]) f.dir<-c(rep("=",K+1)) rhs<-c(rep(0,K),1) prod.trans<-lp("min", f.obj, , f.con, rhs, dense.const =f.con) |
Hi buttrey, |
Hi Buttrey, for (j in (2K+1):(2K+n)) { for (i in 1:K) { |
Hi. What you sent me wasn't valid R code, because you say things like nK instead of n*K, and (2K+1):(2K + n), and so on.
But when I did this, it seemed to work fine. What happened when you tried that?
K<-30000
n<-7
A<-matrix(round(runif(n * K, min=0, max=1),4), K)
f.obj<-c(rep(1,2 * K),rep(0,n),0)
f.con <- matrix (0,K+1, 2*K+n+1) # modified
for (j in (2 * K+1):(2* K+n)) {
f.con[K+1, j]<- 1
}
for (i in 1:K) {
f.con[i, 2*(i-1)+1]<- -1
f.con[i, 2*(i-1)+2]<- 1
f.con[i,2 * K+n+1]<- -1
for (j in 1: n) {
f.con[i, 2* K+j]<-A[i,j]
}
}
newBig <- cbind (which (f.con != 0, T), f.con[f.con != 0]) # seems to work fine
…________________________________
From: chuongask <notifications@github.com>
Sent: Thursday, May 14, 2020 6:57 PM
To: gaborcsardi/lpSolve <lpSolve@noreply.github.com>
Cc: Buttrey, Samuel (Sam) (CIV) <buttrey@nps.edu>; Comment <comment@noreply.github.com>
Subject: Re: [gaborcsardi/lpSolve] Error in t.default(const.mat) : argument is not a matrix (#3)
Hi Buttrey,
Can I create a three-column as you said above from beginning for the following matrix?
K<-30000
n<-7
A<-matrix(round(runif(nK, min=0, max=1),4), K)
f.obj<-c(rep(1,2K),rep(0,n),0)
f.con <- matrix (0,K+1, 2*K+n+1)
for (j in (2K+1):(2K+n)) {
f.con[K+1, j]<- 1
}
for (i in 1:K) {
f.con[i, 2*(i-1)+1]<- -1
f.con[i, 2*(i-1)+2]<- 1
f.con[i,2K+n+1]<- -1
for (j in 1: n) {
f.con[i, 2K+j]<-A[i,j]
}
}
Thanks.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#3 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACNKVNNCD3EYRSUEAYX2UEDRRSOPLANCNFSM4M6XVLLA>.
|
Hi buttrey, for (j in (2 * K+1):(2* K+n)) { for (i in 1:K) { |
Hi. Sorry, I don't understand the question. Once you have your f.con (that's the "sparse" matrix") set up, that's when you create your new "dense" matrix using the strategy we've been talking about. You should end up with a three-column matrix that has perhaps 300,000 rows. Does that work? Or not? |
Hi Buttrey, |
Yes, you can set up your dense constraint matrix directly. But I'm sorry to say, you'll have to write your own code to do this.
I'm surprised that you get errors about 13 GB. That doesn't seem like a lot to me. Can you find another platform for your work?
…________________________________
From: chuongask <notifications@github.com>
Sent: Thursday, May 14, 2020 9:03 PM
To: gaborcsardi/lpSolve <lpSolve@noreply.github.com>
Cc: Buttrey, Samuel (Sam) (CIV) <buttrey@nps.edu>; Comment <comment@noreply.github.com>
Subject: Re: [gaborcsardi/lpSolve] Error in t.default(const.mat) : argument is not a matrix (#3)
Hi Buttrey,
My question is that I could not set up successfully the matrix f.con=matrix (0,K+1, 2K+n+1) before reaching to set up the sparse matrix newBig when increasing bigger K and n. I am wondering if I can set up a sparse three-column matrix (f.con) by insert directly entries: for (j in (2 * K+1):(2 K+n)) {
f.con[K+1, j]<- 1 and so on.
Thanks.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#3 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACNKVNNZDREQU5NAWTYMFN3RRS5JBANCNFSM4M6XVLLA>.
|
Thanks Buttrey, |
Hi. I ran your code above, and produced an f.con matrix that is 30,0001 x 60,008. Then I ran this line: newBig <- cbind (which (f.con != 0, T), f.con[f.con != 0]) That created a matrix that is 299,998 x 3. Now run lp(), but instead of passing in f.con as the "const.mat" argument, pass newBig as the "dense.const" argument. Does that work? |
Hi buttrey, for (j in (2 * K+1):(2* K+n)) { for (i in 1:K) { |
Following lpSolveAPI. Original error: ``` > ### Name: lp > ### Title: Linear and Integer Programming > ### Aliases: lp > ### Keywords: optimize > > ### ** Examples > > # > # Set up problem: maximize > # x1 + 9 x2 + x3 subject to > # x1 + 2 x2 + 3 x3 <= 9 > # 3 x1 + 2 x2 + 2 x3 <= 15 > # > f.obj <- c(1, 9, 1) > f.con <- matrix (c(1, 2, 3, 3, 2, 2), nrow=2, byrow=TRUE) > f.dir <- c("<=", "<=") > f.rhs <- c(9, 15) > # > # Now run. > # > lp ("max", f.obj, f.con, f.dir, f.rhs) lp_presolve.c:193:34: runtime error: applying non-zero offset 16 to null pointer #0 0x7f9ffc9213db in presolve_rebuildUndo /data/gannet/ripley/R/packages/tests-clang-SAN/lpSolve/src/lp_presolve.c:193:34 #1 0x7f9ffc988821 in postsolve /data/gannet/ripley/R/packages/tests-clang-SAN/lpSolve/src/lp_presolve.c:5620:5 #2 0x7f9ffc9fcbff in spx_solve /data/gannet/ripley/R/packages/tests-clang-SAN/lpSolve/src/lp_simplex.c:2062:9 #3 0x7f9ffc9fe260 in lin_solve /data/gannet/ripley/R/packages/tests-clang-SAN/lpSolve/src/lp_simplex.c:2154:12 #4 0x7f9ffca13511 in lpslink /data/gannet/ripley/R/packages/tests-clang-SAN/lpSolve/src/lpslink56.c:377:25 #5 0x74ef88 in do_dotCode /data/gannet/ripley/R/svn/R-devel/src/main/dotcode.c #6 0x83f0a5 in bcEval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:7126:14 #7 0x829ade in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:748:8 #8 0x891fd3 in R_execClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c #9 0x88dc7f in Rf_applyClosure /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:1844:16 #10 0x82a518 in Rf_eval /data/gannet/ripley/R/svn/R-devel/src/main/eval.c:871:12 #11 0x95ade6 in Rf_ReplIteration /data/gannet/ripley/R/svn/R-devel/src/main/main.c:264:2 #12 0x95e340 in R_ReplConsole /data/gannet/ripley/R/svn/R-devel/src/main/main.c:316:11 #13 0x95e149 in run_Rmainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1194:5 #14 0x95e482 in Rf_mainloop /data/gannet/ripley/R/svn/R-devel/src/main/main.c:1201:5 #15 0x4f30ba in main /data/gannet/ripley/R/svn/R-devel/src/main/Rmain.c:29:5 #16 0x7fa00c1cab74 in __libc_start_main (/lib64/libc.so.6+0x27b74) (BuildId: 08df60634339b221bb854d4e10b7278cafde70c4) #17 0x43231d in _start (/data/gannet/ripley/R/R-clang-SAN/bin/exec/R+0x43231d) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lp_presolve.c:193:34 in Success: the objective function is 40.5 ```
Hi All,
I am using lpSolve in R to solve a linear program. Since our problem has a big constraint matrix and so I used a sparse matrix for the constraint of the problem as follows:
K<-30000
n<-7
A<-matrix(round(runif(nK, min=0, max=1),4), K)
f.obj<-c(rep(1,2K),rep(0,n),0)
f.con <- matrix (0,K+1, 2*K+n+1)
for (j in (2K+1):(2K+n)) {
f.con[K+1, j]<- 1
}
for (i in 1:K) {
f.con[i, 2*(i-1)+1]<- -1
f.con[i, 2*(i-1)+2]<- 1
f.con[i,2K+n+1]<- -1
for (j in 1: n) {
f.con[i, 2K+j]<-A[i,j]
}
}
f.con<-Matrix(f.con, sparse=TRUE)
f.dir<-c(rep("=",K+1))
rhs<-c(rep(0,K),1)
prod.trans<-lp("min", f.obj, f.con, f.dir, rhs, compute.sens = TRUE)
#LP solution
prod.trans$objval
prod.trans$solution
However, it showed an error "Error in t.default(const.mat) : argument is not a matrix". Could you please show me how I can fix it?
Thank you for your kind help.
The text was updated successfully, but these errors were encountered: