# 和:グラフ代数

• 直和
• 結び
• 有向結び
• 和の法則
• ,
• ,
• ,
• ,
X <- matrix(c(0,1,1,1,0,0,1,0,0),byrow=TRUE,3,3)
Y <- matrix(c(0,1,1,1,0,1,1,1,0),byrow=TRUE,3,3)
sum.graph <- function(X,Y){
dimX <- dim(X)
dimY <- dim(Y)
Z <- matrix(0,dimX[1]+dimY[1],dimX[2]+dimY[2])
Z[1:dimX[1],1:dimX[2]] <- X
Z[(1+dimX[1]):dim(Z)[1],(1+dimX[2]):dim(Z)[2]] <- Y
Z
}
sum.graph(X,Y)
join.graph <- function(X,Y,directed = TRUE){
dimX <- dim(X)
dimY <- dim(Y)
Z <- matrix(1,dimX[1]+dimY[1],dimX[2]+dimY[2])
if(directed){
Z[!upper.tri(Z)] <- 0
}

Z[1:dimX[1],1:dimX[2]] <- X
Z[(1+dimX[1]):dim(Z)[1],(1+dimX[2]):dim(Z)[2]] <- Y

Z

}

join.graph(X,Y)
join.graph(X,Y,directed = FALSE)

> sum.graph(X,Y)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    1    1    0    0    0
[2,]    1    0    0    0    0    0
[3,]    1    0    0    0    0    0
[4,]    0    0    0    0    1    1
[5,]    0    0    0    1    0    1
[6,]    0    0    0    1    1    0

> join.graph(X,Y)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    1    1    1    1    1
[2,]    1    0    0    1    1    1
[3,]    1    0    0    1    1    1
[4,]    0    0    0    0    1    1
[5,]    0    0    0    1    0    1
[6,]    0    0    0    1    1    0
> join.graph(X,Y,directed = FALSE)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    1    1    1    1    1
[2,]    1    0    0    1    1    1
[3,]    1    0    0    1    1    1
[4,]    1    1    1    0    1    1
[5,]    1    1    1    1    0    1
[6,]    1    1    1    1    1    0