/// <summary> /// This funnction returns all possible workflows in an incidence matrix format, given the foundation matrix /// as well as the vIndep vector which represent the independent variables. /// This function is the top level function which performs the incidence matrix method. /// </summary> /// <param name="IMf"></param> /// <param name="independent"></param> /// <returns></returns> private static IncidenceMatrix[] AllWorkflows(IncidenceMatrix IMf, int[] independent) { IncidenceMatrix IMi = IncidenceMatrix.Build.DenseOfMatrix(IMf); // Number of outputs per row (affect model r) IMi.ReplaceAlltoOne(); // valrf & valcf in [1] double[] Noutvalr = new double[IMf.RowCount]; for (int model = 0; model < IMf.RowCount; model++) { int NOutputs = IMf.NOutputs(model); int NVariables = IMi.NVariables(model); // Number of variables affecting model r int NInputs = (NVariables - NOutputs); Noutvalr[model] = ValRow(NOutputs, NInputs); } double[] Noutvalc = new double[IMf.ColumnCount]; for (int c = 0; c < IMf.ColumnCount; c++) { int NModels = IMi.Column(c).FindValue(ANY); // Number of models related to variable c int NInputs = (NModels - 1); Noutvalc[c] = ValColumn(NInputs); } // Assign user defined inputs/outputs for (int variable = 0; variable < IMi.ColumnCount; variable++) { if (independent[variable] == MARKED_IN) { IMi.SetInput(variable); // Asign variable as input in IMi } else if (independent[variable] == MARKED_OUT) { IMi.SetOutput(variable, IMf); } } List <int> notAssigned = FindNotAssignedModels(IMi, IMf); if (notAssigned.Count == 0) { return(new IncidenceMatrix[1] { IMf }); } IncidenceMatrixFirstStep(IMi, Noutvalr, Noutvalc, true); FillAsInput(IMi, Noutvalr, Noutvalc); IncidenceMatrixFirstStep(IMi, Noutvalr, Noutvalc, true); //////////////////////// List <int> reversed = FindReversedModels(IMi, IMf); bool reversedModelsInSCC = false; List <int> modelsInScc = ModelsInSCCFromIMM(IMi); foreach (int model in modelsInScc) { if (FindValueInArray(reversed, model)) // if ith model is in SCC and reversed then break { reversedModelsInSCC = true; break; } } if (!reversedModelsInSCC) //i.e. no models in SCC are modified/reversed { if (IMi.FindLocations(ANY).Count != 0) { // copy default SCC inputs and outputs to new incidence matrix, imMatrixi IMi.CopyDefaultInputs(IMf, modelsInScc); } return(new IncidenceMatrix[1] { IMi }); } else { // When clicking 'edit' then get incidence before it has been modified or if creating new object, then get default incidence DesignStructureMatrix DSM = IMMtoDSM(IMf); modelsInScc.Clear(); List <Cluster> clusters = Decompose(DSM); foreach (Cluster cluster in clusters) { if (cluster.Count > 1) { modelsInScc.AddRange(cluster); } } reversedModelsInSCC = false; foreach (int model in modelsInScc) { // foreach model in SCC is any model... if (FindValueInArray(reversed, model)) // if ith model is in SCC and reversed then break { reversedModelsInSCC = true; break; } } if (!reversedModelsInSCC) //i.e. copy existing SCC configurations { IMi.CopyDefaultInputs(IMf, modelsInScc); } } //////////////////// if (IMi.FindLocations(ANY).Count > 0) { return(IncidenceExplore(IMi, IMf, Noutvalr, Noutvalc)); //incmset=uniqueincmset(incmset);Unque object has to be added here.... } else { return(new IncidenceMatrix[1] { IMi }); } throw new ArgumentException(NoIMsFoundErrorMessage); }