public FitnessEstimator(List<int> R0, List<int> Rb, bool increase, int n, IIntFCACalculator<FluxPattern> fca_solver, LinkedList<FluxPattern> witnesses, FluxPattern max, FluxPattern frev, IIntCoupling coupling) { this.R0 = R0; this.Rb = Rb; this.increase = increase; this.rand = new Random(); this.n = n; this.fca_solver = fca_solver; this.witnesses = witnesses; this.MAX = max; this.FREV = frev; this.coupling = coupling; }
/// <summary> /// Does the FCA for the given network and saves the result in a new IntCoupling object. /// </summary> /// <param name="n">#reactions in the network.</param> /// <param name="calculator">An object that calculates the maximal set of reactions in the metabolic network constrained by disabled reactions.</param> /// <param name="witnesses">A subset of the flux lattice L.</param> /// <param name="max">The maximum of L / the set of all unblocked reactions in the metabolic network.</param> /// <param name="frev">The set of all fully reversible reactions in the metabolic network.</param> /// <param name="R">A set $R \subseteq [n]$ of disabled reactions.</param> /// <param name="coupling">Flux coupling we already know about.</param> /// <param name="start">This constructor calculated the flux coupling sets $C_i$ for $i \geq start$.</param> public IntCoupling(IIntFCACalculator<FluxPattern> calculator, bool show_output, ICollection<FluxPattern> witnesses, out DateTime[] time_reaction, out int[] lps_reaction, out int[] wits_reaction, out int wits_used, FluxPattern max, FluxPattern frev = null, List<int> R = null, IIntCoupling coupling = null, int start = 0) { this.max = max; this.n = max.Length; this.witnesses = new LinkedList<FluxPattern>(); time_reaction = new DateTime[n]; lps_reaction = new int[n]; wits_reaction = new int[n]; int lps_count = calculator.SolverCalls; this.maxima = new FluxPattern[n]; coupled = new LinkedList<int>[n]; for (int i = 0; i < n; ++i) { coupled[i] = new LinkedList<int>(); coupled[i].AddLast(i); } if (R == null) R = new List<int>(); LinkedList<FluxPattern> new_witnesses = new LinkedList<FluxPattern>(witnesses); witnesses = new LinkedList<FluxPattern>(); bool allowed; foreach (FluxPattern w in new_witnesses) { allowed = true; for (int i = 0; allowed && i < R.Count; ++i) allowed = !w[R[i]]; if (allowed) witnesses.Add(w); } wits_used = witnesses.Count; if (coupling == null) coupling = this; FluxPattern opt, calcs; R.Add(-1); ICollection<int> c; for (int i = start; i < n; ++i) if (maxima[i] == null) { if (max[i]) { R[R.Count - 1] = i; opt = calculator.CalculateMax(R, n, witnesses, out new_witnesses, out calcs, max, frev, coupling); lps_reaction[i] = calculator.SolverCalls - lps_count; lps_count = calculator.SolverCalls; c = coupling[i]; foreach (int r in c) if (r >= i && coupling.Max(r) != null && !coupling.Max(r)[i]) { maxima[r] = opt; for (int j = 0; j < n; ++j) if (max[j] && !maxima[r][j] && r != j) coupled[r].AddLast(j); } if (maxima[i] == null) { maxima[i] = opt; if (maxima[i] == null) Console.WriteLine("Fehler!"); else for (int j = 0; j < n; ++j) if (!maxima[i][j] && max[j] && i != j) coupled[i].AddLast(j); } foreach (FluxPattern a in new_witnesses) if (a.Count > 0) { this.witnesses.AddLast(a); witnesses.Add(a); wits_reaction[i]++; } time_reaction[i] = DateTime.Now; if (show_output) Console.WriteLine("({0})\tCoupling {1} from {2} calculated. ({3} LPs solved, {4} kept.)\n", time_reaction[i], i + 1, n, lps_reaction[i], witnesses.Count); } else maxima[i] = max; } R.RemoveAt(R.Count - 1); }
/// <summary> /// Simulates all $\choose n 2$ double reaction knock-outs and creates a new EFCACount object for the results. /// </summary> /// <param name="calculator">An object that calculates the maximal set of reactions in the metabolic network constrained by disabled reactions.</param> /// <param name="witnesses">A subset of the flux lattice L.</param> /// <param name="max">The maximum of L / the set of all unblocked reactions in the metabolic network.</param> /// <param name="frev">The set of all fully reversible reactions in the metabolic network.</param> /// <param name="coupling">A flux coupling for the network</param> public EFCACount(IIntFCACalculator<FluxPattern> calculator, bool keep_witnesses, ICollection<FluxPattern> witnesses, FluxPattern max, FluxPattern frev, out DateTime[] time_reaction, out int[] lps_reaction, out int[] wits_reaction, out int[] wits_usable, IIntCoupling coupling = null, ICollection<int> T = null, bool show_output = true) { this.max = max; this.n = max.Length; time_reaction = new DateTime[n]; lps_reaction = new int[n]; for (int i = 0; i < n; ++i) lps_reaction[i] = -1; wits_reaction = new int[n]; wits_usable = new int[n]; DateTime[] time; int[] lps, wits; int temp_counter = calculator.SolverCalls, temp_wits; if (coupling == null) { coupling = new IntCoupling(calculator, false, witnesses, out time, out lps, out wits, out temp_wits, max, frev); this.witness_counter = coupling.Witnesses.Count; this.lp_counter = calculator.SolverCalls - temp_counter; temp_counter = calculator.SolverCalls; } if (T == null) { this.T = new List<int>(n); for (int i = 0; i < n; ++i) this.T.Add(i); } else this.T = new List<int>(T); LinkedList<FluxPattern> new_witnesses = new LinkedList<FluxPattern>(); witnesses_kept = new LinkedList<FluxPattern>(witnesses); IIntCoupling row; max_size = new int[n, n]; targeted_size = new int[n, n]; for (int i = 0; i < n; ++i) { max_size[i, i] = -1; targeted_size[i, i] = -1; } List<int> R = new List<int>(); ICollection<int> c; int wits_used; R.Add(-1); for (int i = 0; i < n; ++i) if (max[i] && max_size[i, i] < 0) { R[0] = i; if (keep_witnesses) { foreach (FluxPattern a in new_witnesses) if (rand.NextDouble() < ((double)a.Count) / witnesses_kept.Count) witnesses_kept.AddLast(a); } row = new IntCoupling(calculator, false, witnesses_kept, out time, out lps, out wits, out wits_used, max, frev, R, coupling, i); wits_usable[i] = wits_used; if (show_output) Console.WriteLine("({0})\tRow {1} from {2} calculated of EFCA. ({3} LPs solved, {4} kept.)\n", System.DateTime.Now, i + 1, n, calculator.SolverCalls - temp_counter, witnesses_kept.Count); this.lp_counter += calculator.SolverCalls - temp_counter; temp_counter = calculator.SolverCalls; new_witnesses = row.Witnesses; this.witness_counter += row.Witnesses.Count; c = coupling[i]; foreach (int r in c) if (r >= i && !coupling.Max(r)[i]) for (int j = r; j < n; ++j) if (max[j]) { max_size[r, j] = row.Max(j).Count; max_size[j, r] = max_size[r, j]; targeted_size[r, j] = row.Max(j).Values.Intersect(this.T).Count(); targeted_size[j, r] = targeted_size[r, j]; } lps_reaction[i] = lp_counter; wits_reaction[i] = witness_counter; time_reaction[i] = DateTime.Now; } if (show_output) Console.WriteLine("({0})\tEFCA uncompressed.\n", System.DateTime.Now); }