Return exchange definition as YAML dict.

def model_exchange(model):
    """Return exchange definition as YAML dict."""
    # Determine the default flux limits. If the value is already at the
    # default it does not need to be included in the output.
    lower_default, upper_default = None, None
    if model.default_flux_limit is not None:
        lower_default = -model.default_flux_limit
        upper_default = model.default_flux_limit

    compounds = []
    for compound, reaction_id, lower, upper in sorted(
            itervalues(model.exchange)):
        d = OrderedDict([('id', compound.name)])
        if reaction_id is not None:
            d['reaction'] = reaction_id

        lower = _get_output_limit(lower, lower_default)
        upper = _get_output_limit(upper, upper_default)
        d.update(_generate_limit_items(lower, upper))

        compounds.append(d)

    return OrderedDict([('compounds', compounds)])