RecursiveBudgeting2: Find blocks to rebuild within budget recursively.

Description Usage Arguments Details Value Examples

Description

An efficient recursive algorithm used by Rebuild that outputs the keys corresponding to the unique combination of elements in the ordered vector vec that sum to less than budget.

Usage

1
RecursiveBudgeting2(vec, keys, budget, state = NULL)

Arguments

vec

A numeric vector. When called by Rebuild this contains the cost of rebuilding blocks.

keys

A vector. When called by Rebuild this contains the buildingids associated with the costs in vec.

budget

A number.

state

(optional) This holds the selected keys during recursion.

Details

The cumulative sum of the repair costs are computed and the vector split at the largest amount that does not go over the budgeted amount. The first part is tagged to be fixed, and the second part is fed back into the function with the remaining budget.

Value

A list. .$state holds the selected keys while .$budget holds the unused budget.

Examples

1
2
3
4
5
# Ten buildings have rebuild costs between one to ten. Spend 12 to rebuild
# the first four
blockbuster2:::RecursiveBudgeting(1:10, 1:10, 12)
# If the costs are reversed, the decision changes as the vector is ordered
blockbuster2:::RecursiveBudgeting(10:1, 1:10, 12)

DFE-Capital/blockbuster2 documentation built on May 4, 2019, 1:08 p.m.