I've written the following code. It correctly is deriving the edge list from the matrix but it is by row # and col # instead of row name and column name. My questions are (1) how can I add the row and col names to the edge list instead of the row/col numbers and (2) how can I control the edge list to be directed or undirected as options to be generated?
data = {{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; head = {{S0, S1, S2, S3, S4, S5, S6, S7, S8}, {c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16}}; Join[Transpose[{Join[{""}, head[[1]]]}], Join[head[[{2}]], data], 2] // Grid rownames = {S0, S1, S2, S3, S4, S5, S6, S7, S8}; colnames = {c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16}; edgelist = Rest[Rule @@@ SparseArray[data]["NonzeroPositions"]] 


