Hello!

I have a curious problem, which I cannot solve.
With my code I solve thousands of small linear programs with the package 
lpSolve automatically.
But R crashes sometimes (~always, but always on different linear programs) in a 
strange way.
For illustration, I tried to prepare a simple example, which shows the nature 
of the problem.
The function aaa (see below) declares some constants (only in this special 
example) and in the end it solves the linear program.

aaa(1)
      [,1] [,2]
 [1,]    0    0
 [2,]    0    0
 [3,]    0    0
 [4,]    0    0
 [5,]   52    0
 [6,]    2    2
 [7,]    0    0
 [8,]    2    0
 [9,]    0    0
[10,]    0    0
[11,]    0    0
[12,]    0    0
[13,]   54    0

Works fine.
Now I make the *same* calculation, say 1000 times:
aaa(1000)
R (I have tried it with R2.0.1, 2.0.0, 1.9.1, 2.1.0dev) crashes completly - 
without warning and error message under Windows XP, Intel Pentium 3 with 256 MB 
RAM
Under Linux SuSe 8.2 R (2.0.1) it crashes again, but in this case I get the 
following message:
Calloc of 40004 bytes failed on line 114 of file lpkit.c
...
Calloc of 80008 bytes failed on line 113 of file lpkit.c
Error: cannot allocate vector of size 3 Kb

Now I�m completly lost. Solving the linear program one time makes no problem. 
Solving it twice in the same way makes no problem either. Running the same 
calculation, say 1000 times, causes a crash. Why should there be a problem with 
memory?

For any hint, I would be really happy. 
Thank you,
Matthias


### ---------- function aaa ------------

aaa <- function(amount=1){
f.obj <- rep(0,33)

w <- c(3,4,5,6,11,13,17,22,25,26,27,28,33)

m <- 
matrix(c(0,0,1,1,1,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

              
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,

              
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,0,0,0,0,1,

              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

              0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

              
0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,

              
0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,

              
0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,

              
0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,

              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

              0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

              
0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,1

              ),ncol=33,byrow=TRUE)

f.dir <- c("=","=","=","=","=","=","=","=","=","=","=",
"=","=","=","=","=","=","=","=","=","=","=","=",
"=","=","=","=","=","=","=","=","=","=")

f.rhs <- c(-52,0,54,0,2,0,0,0,0,0,0,0,0,0)

lp.out <- matrix( ncol = 2, nrow = 13 )

for(ii in 1:amount){ # - simple iterate the same

for( i in 1:13 ){

        f.obj[ w[i] ] <- 1

        lp.out[ i, 1 ] <- lp("min", f.obj, m, f.dir, f.rhs)$objval

        lp.out[ i, 2 ] <- lp("max", f.obj, m, f.dir, f.rhs)$objval

        f.obj <- rep( 0, 33 )

}

}
lp.out

}

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to