public static void Analyze(double[,] matrix, bool[] rev, bool[] trans, LinkedList<FluxPattern> forbidden_combinations, double max_value, double tolerance, bool lp, bool fc, bool do_efca, bool keep_witnesses, bool only_internal, bool show_output, out FluxPattern max, out IIntCoupling coupling, out EFCACount efca, out int reactions_unblocked, out int reactions_frev, out int couples, out ICollection<FluxPattern> circuits, out DateTime time_start, out DateTime time_unblocked, out DateTime time_frev, out DateTime time_couples, out DateTime time_efca, out DateTime[] time_reaction, out int lps_unblocked, out int lps_frev, out int lps_couples, out int lps_efca, out int[] lps_reaction, out int wits_unblocked, out int wits_frev, out int wits_couples, out int wits_efca, out int[] wits_reaction, out int[] wits_distribution, out int[] wits_usable, String name = null) { //initialisation time_start = DateTime.Now; efca = null; wits_usable = null; int n = rev.Length; List<int> irr = new List<int>(); for (int i = 0; i < n; ++i) if (!rev[i]) irr.Add(i); LinkedList<FluxPattern> witnesses = new LinkedList<FluxPattern>(); LinkedList<FluxPattern> blocking_witnesses, frev_witnesses; IIntFCACalculator<FluxPattern> fcacalculator = !lp ? (IIntFCACalculator<FluxPattern>)new MILPIntFCACalculator(matrix, rev, max_value, tolerance) : !fc ? (IIntFCACalculator<FluxPattern>)new LPIntFCACalculator(matrix, rev, max_value, tolerance) : forbidden_combinations == null || forbidden_combinations.Count == 0 ? (IIntFCACalculator<FluxPattern>)new FCIntFCACalculator(matrix, rev, trans, max_value, tolerance) : (IIntFCACalculator<FluxPattern>)new FastFCIntFCACalculator(matrix, rev, forbidden_combinations, max_value, tolerance); circuits = (fc && forbidden_combinations == null) ? ((FCIntFCACalculator) fcacalculator).Circles : null; // calculate blocked reactions FluxPattern calcs; int wits_used; bool[] internal_reactions = new bool[n]; for(int i = 0; i<n; ++i) internal_reactions[i] = !trans[i]; FluxPattern pattern_internal = new FluxPattern(internal_reactions, false); max = fcacalculator.CalculateMax(new List<int>(), n, new LinkedList<FluxPattern>(), out blocking_witnesses, out calcs, only_internal ? pattern_internal : null, null); reactions_unblocked = max.Count; foreach (FluxPattern a in blocking_witnesses) if (a.Count > 0) witnesses.AddLast(a); if (name != null) SaveStatistics(witnesses, n, name + "_max.stats"); time_unblocked = DateTime.Now; lps_unblocked = fcacalculator.SolverCalls; wits_unblocked = witnesses.Count; if (show_output) Console.WriteLine("({0})\tBlocked reactions calculated: {1} of {2} blocked.\n", time_unblocked, n-reactions_unblocked, n); // calculate fully reversible reactions FluxPattern frev = fcacalculator.CalculateMax(irr, n, blocking_witnesses, out frev_witnesses, out calcs, max, null); reactions_frev = frev.Count; foreach (FluxPattern a in frev_witnesses) if (a.Count > 0) witnesses.AddLast(a); if (name != null) SaveStatistics(witnesses, n, name + "_frev.stats"); time_frev = DateTime.Now; lps_frev = fcacalculator.SolverCalls - lps_unblocked; wits_frev = witnesses.Count - wits_unblocked; if (show_output) Console.WriteLine("({0})\tFRev calculated.\n", time_frev); // FCA Console.WriteLine("Witnesses so far:"); foreach (FluxPattern a in witnesses) Console.WriteLine("\t{0}", a); Console.WriteLine("\nStarting FCA.\n"); coupling = new IntCoupling(fcacalculator, show_output, witnesses, out time_reaction, out lps_reaction, out wits_reaction, out wits_used, max, frev); if (name != null) SaveStatistics(coupling.Witnesses, n, name + "_fca.stats"); time_couples = DateTime.Now; wits_couples = coupling.Witnesses.Count - wits_frev - wits_unblocked; lps_couples = 0; wits_couples = 0; for (int i = 0; i < n; ++i) { lps_couples += lps_reaction[i]; wits_couples += wits_reaction[i]; } if (show_output) Console.WriteLine("({0})\tCouples calculated.\n", time_couples); wits_distribution = new int[n + 1]; foreach (FluxPattern a in coupling.Witnesses) wits_distribution[a.Count]++; // EFCA lps_efca = 0; wits_efca = 0; if (do_efca) { efca = new EFCACount(fcacalculator, keep_witnesses, coupling.Witnesses, max, frev, out time_reaction, out lps_reaction, out wits_reaction, out wits_usable, coupling, null, show_output); lps_efca = efca.LPCount; wits_efca = efca.WitnessCount; } time_efca = DateTime.Now; couples = coupling.ToCoupling().Count; }
public static IIntCoupling DoFCA(double[,] matrix, bool[] rev, bool[] trans, LinkedList<FluxPattern> forbidden_combinations, double max_value, double tolerance, bool lp, bool fc, bool do_efca, bool keep_witnesses, bool only_internal, bool show_output, bool save_stats, String name, String model, String method, LinkedList<string> res, LinkedList<string> details, out FluxPattern max, out EFCACount efca, out ICollection<FluxPattern> circuits) { LinkedList<FluxPattern> witnesses; int n_unblocked; FluxPattern frev = null; IIntCoupling coupling = null; DateTime time_start, time_stop; DateTime[] time_reaction; int reactions_unblocked, reactions_frev, couples, lps, lps_unblocked, lps_frev, lps_couples, lps_efca, wits, wits_unblocked, wits_frev, wits_couples, wits_efca; int lps_total, wits_total; int[] lps_reaction, wits_reaction, wits_distribution, wits_usable; DateTime time_unblocked, time_frev, time_couples, time_efca; Analyze(matrix, rev, trans, forbidden_combinations, max_value, tolerance, lp, fc, do_efca, keep_witnesses, only_internal, show_output, out max, out coupling, out efca, out reactions_unblocked, out reactions_frev, out couples, out circuits, out time_start, out time_unblocked, out time_frev, out time_couples, out time_efca, out time_reaction, out lps_unblocked, out lps_frev, out lps_couples, out lps_efca, out lps_reaction, out wits_unblocked, out wits_frev, out wits_couples, out wits_efca, out wits_reaction, out wits_distribution, out wits_usable, save_stats ? name : null); lps = lps_unblocked + lps_frev + lps_couples + lps_efca; wits = wits_unblocked + wits_frev + wits_couples + wits_efca; /*String cellcolor = "\\cellcolor{gray!10}"; res.AddLast("\\midrule\n\\multirowbt{4}{*}{\\Var{" + model.Replace("_", "\\_") + "}}" + String.Format("& {4}Total &{4}{0}&{4}{2}&{4}{3}&{4}{1:0.0}\\\\", rev.Length, (time_efca - time_start).TotalSeconds, lps, wits, "")); res.AddLast(String.Format("\\cmidrule{4} & {5}$1_L$ &{5}{0}&{5}{2}&{5}{3}&{5}{1:0.0}\\\\", reactions_unblocked, (time_unblocked - time_start).TotalSeconds, lps_unblocked, wits_unblocked, "{2-6}", cellcolor)); res.AddLast(String.Format("\\cmidrule{4} & $\\Frev$ &{0}&{2}&{3}&{1:0.0}\\\\", reactions_frev, (time_frev - time_unblocked).TotalSeconds, lps_frev, wits_frev, "{2-6}")); res.AddLast(String.Format("\\cmidrule{4} & {5}$\\Coupling$ &{5}{0}&{5}{2}&{5}{3}&{5}{1:0.0}\\\\", couples, (time_couples - time_frev).TotalSeconds, lps_couples, wits_couples, "{2-6}", cellcolor)); if(do_efca) res.AddLast(String.Format("\\cmidrule{4} & EFCA &{1}&{2}&{3}&{1:0.0}\\\\", efca.Length, (time_efca - time_couples).TotalSeconds, lps_efca, wits_efca, "{2-6}")); */ res.AddLast(String.Format("{0} {1} {2} {3} {4} {5} {6} {7:0.000} {8:0.000} {9:0.000} {10:0.000} {11:0.000} {12} {13} {14} {15} {16} {17} {18} {19} {20} {21}", model, method, matrix.Length / rev.Length, rev.Length, reactions_unblocked, reactions_frev, couples, (time_efca - time_start).TotalSeconds, (time_unblocked - time_start).TotalSeconds, (time_frev - time_unblocked).TotalSeconds, (time_couples - time_frev).TotalSeconds, (time_efca - time_couples).TotalSeconds, lps, lps_unblocked, lps_frev, lps_couples, lps_efca, wits, wits_unblocked, wits_frev, wits_couples, wits_efca)); //unblocked details.AddLast(String.Format("{0} {1} {2} {3} {4} {5} {6} {22:0.000} {23} {24} {25} {26} {27}", model, method, matrix.Length / rev.Length, rev.Length, reactions_unblocked, reactions_frev, couples, (time_efca - time_start).TotalSeconds, (time_unblocked - time_start).TotalSeconds, (time_frev - time_unblocked).TotalSeconds, (time_couples - time_frev).TotalSeconds, (time_efca - time_couples).TotalSeconds, lps, lps_unblocked, lps_frev, lps_couples, lps_efca, wits, wits_unblocked, wits_frev, wits_couples, wits_efca, time_start, -1, lps_unblocked, lps_unblocked, wits_unblocked, wits_unblocked)); //frev details.AddLast(String.Format("{0} {1} {2} {3} {4} {5} {6} {22:0.000} {23} {24} {25} {26} {27}", model, method, matrix.Length / rev.Length, rev.Length, reactions_unblocked, reactions_frev, couples, (time_efca - time_start).TotalSeconds, (time_unblocked - time_start).TotalSeconds, (time_frev - time_unblocked).TotalSeconds, (time_couples - time_frev).TotalSeconds, (time_efca - time_couples).TotalSeconds, lps, lps_unblocked, lps_frev, lps_couples, lps_efca, wits, wits_unblocked, wits_frev, wits_couples, wits_efca, time_start, 0, lps_frev, lps_unblocked + lps_frev, wits_frev, wits_unblocked + wits_frev)); //couples lps_total = lps_unblocked + lps_frev; wits_total = wits_unblocked + wits_frev; int temp_i = 0; for (int i = 0; i < rev.Length; ++i) if (max[i] && lps_reaction[i] > -1) { lps_total += lps_reaction[i]; wits_total += wits_reaction[i]; temp_i = i; details.AddLast(String.Format("{0} {1} {2} {3} {4} {5} {6} {22:0.000} {23} {24} {25} {26} {27} {28} {29}", model, method, matrix.Length / rev.Length, rev.Length, reactions_unblocked, reactions_frev, couples, do_efca ? (time_efca - time_start).TotalSeconds : 0, (time_unblocked - time_start).TotalSeconds, (time_frev - time_unblocked).TotalSeconds, (time_couples - time_frev).TotalSeconds, do_efca ? (time_efca - time_couples).TotalSeconds : 0, lps, lps_unblocked, lps_frev, lps_couples, lps_efca, wits, wits_unblocked, wits_frev, wits_couples, wits_efca, i + 1, (time_reaction[i] - time_start).TotalSeconds, lps_reaction[i], lps_total, wits_reaction[i], wits_total, wits_distribution[i + 1], do_efca ? wits_usable[i] : 0)); } else details.AddLast(String.Format("{0} {1} {2} {3} {4} {5} {6} {22:0.000} {23} {24} {25} {26} {27} {28} {29}", model, method, matrix.Length / rev.Length, rev.Length, reactions_unblocked, reactions_frev, couples, do_efca ? (time_efca - time_start).TotalSeconds : 0, (time_unblocked - time_start).TotalSeconds, (time_frev - time_unblocked).TotalSeconds, (time_couples - time_frev).TotalSeconds, do_efca ? (time_efca - time_couples).TotalSeconds : 0, lps, lps_unblocked, lps_frev, lps_couples, lps_efca, wits, wits_unblocked, wits_frev, wits_couples, wits_efca, i + 1, (time_reaction[temp_i] - time_start).TotalSeconds, 0, lps_total, 0, wits_total, wits_distribution[i + 1], do_efca ? wits_usable[i] : 0)); return coupling; }