--------------- # Aufgabe 1 # --------------- # 1a) n = 40 m = 200 c = rep(1,n) # 1b) a = runif(n*m) A = matrix(a,ncol=n,nrow=m) b = runif(m,min=n/2-sqrt(n),max=n/2+sqrt(n)) # 1c) require(linprog) res = solveLP(c,b,A,TRUE) res # 1d) names(res) res\$opt # maxF res\$iter2 # numbers of iterations # in Simplex Algorithm res\$solution # x_max such that F(x_max) = maxF # 1e) calctimes = rep(0,100) iterations = rep(0,100) maxF = rep(0,100) for(i in 1:100) { calctime = Sys.time() a = runif(n*m) A = matrix(a,ncol=n,nrow=m) b = runif(m,min=n/2-sqrt(n),max=n/2+sqrt(n)) res = solveLP(c,b,A,TRUE) calctimes[i] = Sys.time() - calctime iterations[i] = res\$iter2 maxF[i] = res\$opt } plot(calctimes,ylim=c(0,1)) plot(iterations, ylim=c(0,100)) plot(iterations,calctimes,main="n = 40, m = 200") plot(maxF,ylim=c(0,60),main="n = 40, m = 200") # 1f) nn = seq(from=10,to=100,by=10) nn mm = seq(from=200,to=400,by=20) mm calctimes = matrix(0,ncol=10,nrow=11) iterations = matrix(0,ncol=10,nrow=11) maxF = matrix(0,ncol=10,nrow=11) bincoeff = matrix(0,ncol=10,nrow=11) totaltime = Sys.time() for(n in nn) { for(m in mm) { calctime = Sys.time() a = runif(n*m) A = matrix(a,ncol=n,nrow=m) b = runif(m,min=n/2-sqrt(n),max=n/2+sqrt(n)) c = rep(1,n) res = solveLP(c,b,A,TRUE) i = m/20 - 9 j = n/10 calctimes[i,j] = Sys.time() - calctime iterations[i,j] = res\$iter2 maxF[i,j] = res\$opt bincoeff[i,j] = choose(n+m,m) } } totaltime = Sys.time() - totaltime totaltime # let's take a quick look: calctimes iterations bincoeff # plots: require(plot3D) persp3D(mm,nn,calctimes) persp3D(mm,nn,calctimes,xlab="m",ylab="n",zlab="calctimes") persp3D(mm,nn,iterations) persp3D(mm,nn,iterations,xlab="m",ylab="n",zlab="iterations") persp3D(mm,nn,maxF) persp3D(mm,nn,maxF,xlab="m",ylab="n",zlab="maxF") persp3D(mm,nn,bincoeff) # we want to write the pictures into a png-file which will be # automatically created in the working directory. The working # directory can be set with this command: setwd("C:/Users/detlef/HSRM/Vorlesungen/SS2017/LinOpt") # if the following command is executed, pictures will be sent # to a file and are not shown on the screen: png() # now invoke plot-commands to generate the pictures; # once this has been done, type dev.off() # then the pictures can be found as Rplot001.png, Rplot002.png, ... # in your working directory