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 country has a set of electrical power plants (the Resources), each with a maximum power that it can supply, its capacity in Megawatts (MW), to meet the total demand in MW. Each plant has a marginal cost of generation in $/KWh as Marginal_cost. We sort the plants in order of increasing marginal cost. Then the Dispatch function computes compute how much power to dispatch from each plant to minimize the total cost:
Index Plants_ordered := SortIndex(Marginal_cost, Plants) Dispatch(Demand, Plant_Capacity[Plants = Plants_ordered], Plants_ordered)
In a variation on this problem, the country is divided into regions. Each region has its own demand (so Demand_by_region is indexed by Region), and each region can only consume power from plants located in that region. Region_by_plant gives the region in which each Plant is located. We use the optional parameter active to control which plants are available for allocation in each Region
Index Plants_ordered := SortIndex(Marginal_cost, Plants) Dispatch(Demand_by_county, Capacity[Plants = Plants_ordered], Plants_ordered, active: Region_by_plant[Plants = Plants_ordered]=Region)
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