def check_compound_consistency(database, solver, exchange=set(),<EOL>zeromass=set()):
<EOL>prob = solver.create_problem()<EOL>compound_set = _non_localized_compounds(database)<EOL>mass_compounds = compound_set.difference(zeromass)<EOL>m = prob.namespace(mass_compounds, lower=<NUM_LIT:0>)<EOL>z = prob.namespace(mass_compounds, lower=<NUM_LIT:0>, upper=<NUM_LIT:1>)<EOL>prob.set_objective(z.sum(mass_compounds))<EOL>prob.add_linear_constraints(m.set(mass_compounds) >= z.set(mass_compounds))<EOL>massbalance_lhs = {reaction_id: <NUM_LIT:0> for reaction_id in database.reactions}<EOL>for (compound, reaction_id), value in iteritems(database.matrix):<EOL><INDENT>if compound not in zeromass:<EOL><INDENT>mass_var = m(compound.in_compartment(None))<EOL>massbalance_lhs[reaction_id] += mass_var * value<EOL><DEDENT><DEDENT>for reaction_id, lhs in iteritems(massbalance_lhs):<EOL><INDENT>if reaction_id not in exchange:<EOL><INDENT>prob.add_linear_constraints(lhs == <NUM_LIT:0>)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>prob.solve(lp.ObjectiveSense.Maximize)<EOL><DEDENT>except lp.SolverError as e:<EOL><INDENT>raise_from(<EOL>MassConsistencyError('<STR_LIT>'.format(<EOL>e)), e)<EOL><DEDENT>for compound in mass_compounds:<EOL><INDENT>yield compound, m.value(compound)<EOL><DEDENT>
Yield each compound in the database with assigned mass

    Each compound will be assigned a mass and the number of compounds having a
    positive mass will be approximately maximized.

    This is an implementation of the solution originally proposed by
    [Gevorgyan08]_  but using the new method proposed by [Thiele14]_ to avoid
    MILP constraints. This is similar to the way Fastcore avoids MILP
    contraints.