def restrict_available_forage(available_forage, management_threshold):
    """Reduce forage available for grazing.

    The management threshold specifies the biomass that must be left
    after herbivore offtake. Calculate the forage available for offtake by
    herbivores according to its relative availability, restricting it to be
    below the management threshold if necessary.

    Parameters:
        available_forage (list): list of class FeedType, where each FeedType
            is characterized by its standing biomass and biomass available
            to herbivores for offtake
        management_threshold (float): biomass (kg/ha) required to be left
            standing after offtake by herbivores

    Returns:
        modified available_forage, a list of class FeedType
    """
    sum_biomass = 0.
    for feed_type in available_forage:
        sum_biomass += feed_type.biomass

    actually_available = max(sum_biomass - management_threshold, 0)
    for feed_type in available_forage:
        feed_type.biomass_avail = (
            feed_type.rel_availability * actually_available)
    return available_forage