RecursiveBudgeting: 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
RecursiveBudgeting(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 vec and keys arguments are split into two. The sum of the first half of vec is compared to the budget. If it is less then all keys are selected, otherwise, the argument is split in half again and checked, and so on. Afterwards, the second half is checked if there are still monies to spend.

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/Blockbuster-2 documentation built on May 26, 2019, 7:23 a.m.