Node property functions

General multiway cores

pDeg <- function(MN,v,cip,C){ 
  OK <- function(e){
    for(j in 2:length(cip)){
      r <- cip[j]; z <- ci[r]
      if(!(MN$links[e,z] %in% C[[r]])) return(FALSE)
    }
    return(TRUE)
  } 
  I <- which(MN$links[[ci[cip[1]]]]==v)
  cnt <- 0
  for(e in I) if(OK(e)) cnt <- cnt+1
  return(cnt)
}
pWsum <- function(MN,v,cip,C,weight="w"){ # ci=ci,cip=cip,C=C
  OK <- function(e){
    for(j in 2:length(cip)){
      r <- cip[j]; z <- ci[r]
      if(!(MN$links[e,z] %in% C[[r]])) return(FALSE)
    }
    return(TRUE)
  } 
  I <- which(MN$links[[ci[cip[1]]]]==v)
  s <- 0
  for(e in I) if(OK(e)) s <- s + MN$links[e,weight]
  return(s)
}
pWmax <- function(MN,v,cip,C,weight="w"){ 
  OK <- function(e){
    for(j in 2:length(cip)){
      r <- cip[j]; z <- ci[r]
      if(!(MN$links[e,z] %in% C[[r]])) return(FALSE)
    }
    return(TRUE)
  } 
  I <- which(MN$links[[ci[cip[1]]]]==v)
  s <- 0
  for(e in I) if(OK(e)) s <- max(s, MN$links[e,weight])
  return(s)
}
pDiv <- function(MN,v,cip,C,way=NULL){ 
  OK <- function(e){
    for(j in 2:length(cip)){
      r <- cip[j]; z <- ci[r]
      if(!(MN$links[e,z] %in% C[[r]])) return(FALSE)
    }
    return(TRUE)
  } 
  I <- which(MN$links[[ci[cip[1]]]]==v)
  return(length(union(NULL,MN$links[[way]][I[unlist(sapply(I,OK))]])))
}
pAttr <- function(MN,v,cip,C,way=NULL,attr=NULL,FUN=sum){ 
  OK <- function(e){
    for(j in 2:length(cip)){
      r <- cip[j]; z <- ci[r]
      if(!(MN$links[e,z] %in% C[[r]])) return(FALSE)
    }
    return(TRUE)
  } 
  I <- which(MN$links[[ci[cip[1]]]]==v)
  U <- union(NULL,MN$links[[way]][I[unlist(sapply(I,OK))]])
  return(FUN(MN$nodes[[way]][[attr]][U]))
}
vlado/work/2m/mwn/nodep.txt · Last modified: 2023/02/18 01:12 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki