Distribute target amounts (e.g. wood harvest area) per region and variable over the clusters (weight: their capacity, e.g. forest land), so the totals of the regions with capacity above zero reach their target exactly. A cluster can never physically receive more than its capacity. Each cluster first receives its own share: the region's target distributed over the region's clusters proportional to their capacity. Shares are not capped at the cluster's capacity. A region whose target exceeds its region's total capacity gives its clusters more than their capacity, on purpose, and the caller has to account for the excess. Targets > 0 of regions without any capacity are pooled globally and spread over the remaining room (capacity minus own share) of all clusters, so borrowed amounts never push a cluster past its capacity. If the global room is too small for the whole stranded pool, the remainder is not allocated and has to be accounted for by the caller.
Usage
toolAllocateRegionTotals(
targetRegionAmount,
clusterCapacity,
warnMessage = "Regions with target totals > 0 have receiving capacity"
)