Dispatch
Dispatch(demand, capacity, resources, active, minimum, increment)
Given a total «demand» (such as MW of power) and index «resources» each of which has available «capacity» (e.g. maximum MW it can provide) , it allocates capacity in order of «resources» index just sufficient to meet the demand. It returns an array indexed by «resources» specifying the amount of capacity consumed allocated for each resource as a number between zero and its available «capacity». The sum of the result over «resources» will equal «demand» provided that there is sufficient capacity to fulfill the demand. Assuming all elements have a positive «capacity», the result will contain values equal to the «capacity» for the first n elements, the next element may be less than its «capacity» if sufficient to meet the remaining «demand», and remaining elements will be zero. (If the «demand» is greater than sum of «capacity» over «resources», all elements will be equal to their «capacity», but the result will not meet the demand.)
The optional «active» flag, if specified, is also indexed by «Resource» and is true when the indicated «Resource» can be used to fill the demand, false if it cannot be applied to the demand. This is useful if some elements are unavailable. It is also useful if you want to apply dispatch for a number of regions, in which resources in each region may only supply the demand in that region. (See the Electric power example below.)
The optional parameter «minimum» specifies that the resource, if dispatched at all must be at least «minimum» capacity/ The optional parameter «increment» specifies that the resource must be dispatched with an integral number of increments of capacity. Parameters «minimum» and «increment» may be indexed by «resources» to specify a different minimum or increment for each resource. If «minimum» (or «increment») has the same value as «capacity», it means that that resource must be allocated fully or not at all. A Null or zero values for «increment» (or «minimum») for a resource specifies that there is no minimum increment or minimum. Preceding resources take precedence, so the amount of remaining demand carried forward is only the demand that could not be allocated to the previous resource, either because there wasn't enough to meet the «minimum», was more than «capacity», or wasn't enough to complete an «increment». Even if «minimum» is not a multiple of «increment», the result will always be a multiple of «increment». Thus, with positive «increment» or «minimum» values, it is possible that the total capacity dispatched will be greater than the demand.
Null values in capacity are passed through as Null values in the result.
Example Uses
Electrical power dispatch
A certain region has a set of electrical power plants (the Resources). Each power plant has a maximum amount of power that it can supply (its capacity), and supplies its power at a given marginal cost per KWh. The region must satisfy a certain known electric power demand, dispatching first from those plants with the lowest marginal cost. Plants have already been sorted by ascending marginal cost, then Dispatch is used to compute how much power to utilize from each plant.
Dispatch( Demand, Plant_Capacity, Plants )
In a variation on this problem, the region is divided into counties. Each county has its own demand (so Demand_by_county is indexed by County), and each county can only consume power from plants located in that county. Plant_county is indexed by Plant and evaluates to the county that the Plant is located in.
Dispatch( Demand_by_county, Plant_Capacity, Plants, active: Plant_County=County )
Investment Allocation
An investor creates a model that ranks possible investment by quality (perhaps MIrr, for example). He has a fixed budget to invest, and has limits on the maximum amount that can be allocated to any given investment (the maximum varies by investment). He's already sorted his investments by ascending quality. He uses Dispatch to determine how much money to place in each investment.
Dispatch( investment_amount, allocation_maximum, Investments )
Project Budgeting
A company has a set of potential projects, sorted by expected ROI. They have a fixed budget to invest. Each project undertaken must be funded at a minimum level, or not at all. However, once funded, a project with a better ROI should receive as much funding as possible, up to the full project_cost.
Dispatch( Budget, Project_cost, Project, minimum:Project_minimum )
Dispatching in reverse
In come cases, you may want to dispatch from the end of the «Resource» index first, just because of how you defined your index. For example, you want to may dispatch the oldest along an Age index, where index Age is in increasing order. This is facilitated by creating a reverse index mapping.
- Variable ReverseAge :=
Slice(Age, size(Age)+1-@Age)
Each parameter that uses an array indexed by «Resource» is then reversed, and the final result of Dispatch is reversed.
Dispatch( Consumption, Inventory[Age=ReverseAge], Age, isActive[Age=ReverseAge] )[ Age = ReverseAge ]
Notice that you have to reverse the «capacity», «active», «minimum» and «increment» parameter.
Enable comment auto-refresher