/// <summary> /// creates the new incidence matrix based on the SCCs. SCCs are clustered in the new DSM in a single row. /// </summary> /// <param name="IM"></param> /// <param name="clusters"></param> /// <returns></returns> private static IncidenceMatrix CreateUpMatrix(IncidenceMatrix IM, List <Cluster> clusters) { IncidenceMatrix imMatrixU = IncidenceMatrix.Build.Dense(clusters.Count, IM.ColumnCount); for (int r = 0; r < clusters.Count; r++) { Cluster cluster = clusters[r]; if (cluster.Count == 1) { imMatrixU.SetRow(r, IM.Row(cluster[0])); } else { IncidenceMatrix imMatrixT = IncidenceMatrix.Build.Dense(cluster.Count, IM.ColumnCount); int nvC = 0; foreach (int nRow in cluster) { imMatrixT.SetRow(nvC, IM.Row(nRow)); nvC++; } for (int c = 0; c < IM.ColumnCount; c++) { Vector <double> column = imMatrixT.Column(c); int Nin = column.FindValue(IN); int Nout = column.FindValue(OUT); if (Nin > 0 && Nout > 0) { imMatrixU[r, c] = OUT; } else if (Nout > 0) { imMatrixU[r, c] = OUT; } else if (Nin > 0) { imMatrixU[r, c] = IN; } else { imMatrixU[r, c] = NOTHING; } } } } return(imMatrixU); }