Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

constructing absolute paths from network (node/edge) data

fnoahbiro
6 - Meteoroid

I have network data--nodes & edges (to/from)--and would like to construct absolute paths from it. For instance, consider the following data set.

 

FromTo
AB
AC
CD
DE

 

I would like to return the following:

A -> B

A -> C -> D -> E

 

Is there a convenient way to do this in Alteryx?

6 REPLIES 6
JordanB
Alteryx
Alteryx

Hi @fnoahbiro

 

I have attached a workflow which groups the node and edges together. 

 

I assumed the paths start with 'A'.

 

Additional annotations are in the workflow.

 

Best,

 

Jordan Barker

Solutions Consultant

fnoahbiro
6 - Meteoroid

What if the root is unknown? That is, we can't specify starting from A.

JordanB
Alteryx
Alteryx

Hi @fnoahbiro,

 

Not understanding the structure of your data, you will need to think of some logic which decides what is the starting node, or separates the different nodes.

 

 In the attached workflow I assumed the first value in the 'from' column would be repeated and therefore would be the start of a new node.

 

I hope this helps.

 

best,

 

Jordan Barker

Solutions Consultant

JordanB
Alteryx
Alteryx

Hi @fnoahbiro,

 

Not understanding the structure of your data, you will need to think of some logic which decides what is the starting node, or separates the different nodes.

 

 In the attached workflow I assumed the first value in the 'from' column would be repeated and therefore would be the start of a new node.

 

I hope this helps.

 

best,

 

Jordan Barker

Solutions Consultant

fnoahbiro
6 - Meteoroid

Throw this into the R tool and check the output. Note the code is partially sanitized (***).

 

df_all <- read.Alteryx('#1', mode = 'data.frame')

 

# load libraries
library(igraph, quietly = TRUE)

 

# list distinct *** (filepaths)
z <- unique(df_all$filepath)

 

# define data frame for hierarchy data
h <- data.frame(filepath = character(0), hierarchy = character(0))

 

# construct hierarchy for ***
for (i in seq(z)) {


   # subset records for current file
   f <- z[i]
   df <- subset(df_all, df_all$filepath == f)


   # get distinct nodes
   nodes_from <- df[, 1, drop = F]
   colnames(nodes_from) <- c('name')
   nodes_to <- df[, 2, drop = F]
   colnames(nodes_to) <- c('name')
   nodes <- unique(rbind(nodes_from, nodes_to))


   # clean relations
   edges <- df[, c(1, 2)]


   # create graph object
   g <- graph_from_data_frame(edges, vertices = nodes)


   # extract root and leaves
   root <- which(degree(g, v = V(g), mode = "in")==0, useNames = T)
   leaves <- which(degree(g, v = V(g), mode = "out")==0, useNames = T)


   # generate paths
   path_list <- all_simple_paths(g, from = root, to = leaves)


   # convert path list into a data frame
   t <- as.data.frame(cbind(lapply(path_list, function(x) paste(x$name, collapse = '>'))))


   # append filename and update column names
   t <- data.frame(f, t)
   colnames(t) <- c('filepath', 'hierarchy')


   # append records
   h <- rbind(h, t)
}


# output
h[] <- lapply(h, as.character)
AlteryxMessage('Path builder complete.', msg.consts$INFO, priority.consts$LOW )
write.Alteryx(h, 1)

mgrajkumar
7 - Meteor

Hi

Is it possible to share the alteryx workflow?. Iam looking for all possible combinations and also an indicator of the shortest path. 

 

Thanks

R

Labels
Top Solution Authors