public MaxLPSolve(Problem problem, IEnumerable <BoundedVariable> variables = null) { this.problem = problem; if (variables != null) { this.variables = new HashSet <BoundedVariable>(variables).ToArray(); } else { var set = new HashSet <BoundedVariable>(); foreach (Constraint c in problem.constraints) { foreach (BoundedVariable v in c.f.terms.Keys) { set.Add(v); } } this.variables = set.ToArray(); } index_for_var = new Dictionary <BoundedVariable, int>(); for (int i = 0; i < this.variables.Length; ++i) { index_for_var[this.variables[i]] = i; } lp = lpsolve.make_lp(problem.constraints.Count, this.variables.Count()); lpsolve.set_verbose(lp, 3); //lpsolve.set_scaling(lp, lpsolve.lpsolve_scales.SCALE_CURTISREID | lpsolve.lpsolve_scales.SCALE_DYNUPDATE); init = true; int j; int varcount = this.variables.Count(); int rowcount = problem.constraints.Count; for (j = 0; j < rowcount; ++j) { lpsolve.set_constr_type(lp, j + 1, lpsolve.lpsolve_constr_types.EQ); } lpsolve.set_maxim(lp); results = new double[varcount]; results_accessor = new ReadOnlyIndexer <BoundedVariable, double>( (BoundedVariable v) => { return(results[index_for_var[v]]); }, this.variables); }
public static bool Match(this string input, string pattern, [MaybeNullWhen(false), NotNullWhen(true)] out ReadOnlyIndexer <string, string>?groups, RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Compiled) => input.Match(new Regex(pattern, options), out groups);