pwOptGrids             package:PathWave             R Documentation

_P_a_t_h_W_a_v_e _r_e_s_u_l_t _f_i_l_e _p_a_r_s_e_r _f_o_r _L_P _s_o_l_v_e_r

_D_e_s_c_r_i_p_t_i_o_n:

     Parses output files that were solved by CPLEX and generates the
     optimal ordered grids. The output files must follow the problem
     structure formulated by function pwLPFiles().

_U_s_a_g_e:

     pwOptGrids(path, adjMatrix, pattern = "\.lp\.log$")

_A_r_g_u_m_e_n_t_s:

    path: Path where the function should search for the output files.

adjMatrix: List of adjacency matrices as returned by pwAdjMatrices()
          and with which the LP problem was derived (via pwLPFiles()).

 pattern: The specific pattern of the file names.

_D_e_t_a_i_l_s:

     The function allows the easy parsing of the solutions returned by
     CPLEX. It searches for lines starting with "x" followed by "_" and
     numbers, e.g. "x_1_1_1" following the formulation of the
     optimisation problems by pwLPFiles(). The found file names are
     split via "." assuming that the pathway ID is the first string in
     the file name.

_V_a_l_u_e:

     A list is returned: 

pathway ID: For every pathway ID a list element M is defined with the
          ordered grid.

_N_o_t_e:

     This parser was written to parse CPLEX results. For using
     different LP solvers changing the code might be necessary.

_A_u_t_h_o_r(_s):

     Gunnar Schramm

_S_e_e _A_l_s_o:

     See Also as 'pwAdjMatrices','pwLPFiles'

_E_x_a_m_p_l_e_s:

     library(e1071)
     #define number of nodes and generate random adjacency matrix
     nNodes=5
     M=dist.matrix=matrix(sample(c(0,1),nNodes^2,replace=TRUE),nrow=nNodes,ncol=nNodes)
     rownames(M)=colnames(M)=paste("R",1:nNodes,sep="")

     #distances
     dist.matrix[dist.matrix==0]=Inf
     dist.matrix=allShortestPaths(dist.matrix)$length 

     #avoid infinity and NAs in this test case
     dist.matrix[is.na(dist.matrix)]=0
     dist.matrix[dist.matrix==Inf]=0

     #set iMax
     iMax=max(dist.matrix)

     #build test list
     test.list=list()
     test.list[["testGraph"]]=list(nNodes=nNodes, iMax=iMax, M=M)

     #Assuming testGraph should have been arranged on a 4x4 grid
     size=4

     #write dummy solution file, CAUTION: the numbering will start with 0!
     cat(paste("start dummy file","\n",sep=""),file="testGraph.lp.log")

     #print dummy distance information - not necessary
     for(i in paste("d",rep(0:(nNodes-1),each=nNodes),rep(0:(nNodes-1),times=nNodes),sep="_")){
       cat(paste(i,as.integer(runif(1)*nNodes),sep="   "),file="testGraph.lp.log",append=TRUE,fill=TRUE)
     }

     #print ordering information for x
     val=abs(rnorm(nNodes*size^2))
     x.names=as.matrix(expand.grid(paste("x",0:(nNodes-1),sep="_"), 0:(size-1),0:(size-1)))
     names(val)=paste(x.names[,1],x.names[,2],x.names[,3],sep="_")

     #set the real nodes to value 1 -> every node should be chosen once and should only occupy one grid element alone!
     val[diag(sapply(X=1:nNodes,seq,to=nNodes*size^2,by=nNodes)[sample(1:((nNodes*size^2)/nNodes),size=5),])]=1

     for(i in 1:length(val)){
       cat(paste(names(val)[i],val[i],sep="   "),file="testGraph.lp.log",append=TRUE,fill=TRUE)         
     }

     #use pwOptGrids
     testOptGrids=pwOptGrids(path=getwd(),adjMatrix=test.list,pattern=".lp.log$")

