library(MASS) # vertices are extended by the constant 1 dataVertices=read.table("stand-imset4-vertices.txt",header=FALSE,sep=",") # the last coefficient is the negative of the right hand side value of the equality dataEqualities=read.table("stand-imset4-equalities.txt",header=FALSE,sep=",") # 185 x 12 matrix V=data.matrix(dataVertices) # 154 x 12 matrix E=data.matrix(dataEqualities) # 185 x 154 matrix - A[i,j] is 0 if vertex satisfies equality A=V %*% t(E) # 185 x 185 matrix - B[i1,i2]=1 if i1 and i2 are neighbours B=matrix(0,nrow=nrow(A),ncol=nrow(A)) # 185 lists of neighbours NB=vector(mode="list",length=nrow(A)) for (i1 in 1:(nrow(A)-1)){ for (i2 in (i1+1):nrow(A)){ # print(c("i1=",i1,", i2=",i2),quote=FALSE) J=c() for (j in 1:ncol(A)) if ((A[i1,j]==0) & (A[i2,j]==0)) J=append(J,j) # Now, J contains indexes of all inequalities satisfied by both i1 and i2 # print(c("J=",J),quote=FALSE) if (length(J)>1){ I=c() for (i in 1:nrow(A)){ all=TRUE for (j in 1:length(J)){ all=all & (A[i,J[j]]==0) if (!all) break } if (all) I=append(I,i) } # Now, I contains vertices that satisfy all inequalities from J # print(c("I=",I),quote=FALSE) # If there exactly two vertices in I then they are geometric neighbours. if (length(I)==2){ B[i1,i2]=1 B[i2,i1]=1 NB[[i1]]=append(NB[[i1]],i2) NB[[i2]]=append(NB[[i2]],i1) }else{ B[i1,i2]=0 B[i2,i1]=0 } }else{ B[i1,i2]=0 B[i2,i1]=0 } } } # write.matrix(t(E), file="stand-imset4-equalities-transposed.txt", sep = ",") write.matrix(A,file="stand-imset4-vertex-satisfies-equality.txt", sep = ",") write.matrix(B, file = "stand-imset4-neigbourhood-matrix.txt", sep = ",") write.matrix(NB, file = "stand-imset4-neigbourhood-list.txt", sep = ",")