Skip to content

Budget allocation

Spread a budget of r units across advertising channels so that the expected number of customers reached is as large as possible. Each unit on channel `s` reaches customer `t` independently with probability `p_st`. The objective `f(x) = Σ_t 1 − Π_s (1 − p_st)^\{x_s\}` is monotone and DR-submodular on the integer lattice: a channel's next unit is worth less as more units are spent, but a second unit on one channel can still be the best move. This private workload compares full-scan greedy, lazy greedy over an injected `knotkit/heap` max-heap, and stochastic greedy over injected `knotkit/prng` randomness. It checks them against the exact optimum, enumerated on small instances, and measures how far they are from optimal with an upper bound from the objective's concave relaxation and a branch-and-bound search built on it.

Spread a budget of r units across advertising channels so that the expected number of customers reached is as large as possible. Each unit on channel s reaches customer t independently with probability p_st. The objective f(x) = Σ_t 1 − Π_s (1 − p_st)^\{x_s\} is monotone and DR-submodular on the integer lattice: a channel’s next unit is worth less as more units are spent, but a second unit on one channel can still be the best move. This private workload compares full-scan greedy, lazy greedy over an injected knotkit/heap max-heap, and stochastic greedy over injected knotkit/prng randomness. It checks them against the exact optimum, enumerated on small instances, and measures how far they are from optimal with an upper bound from the objective’s concave relaxation and a branch-and-bound search built on it.

Lazy greedy needs 576 gain evaluations against full-scan greedy’s 22,500 at budget 75 on low-overlap (0.267 ms against 4.274 ms)

  • knotkit/heap: Provides binary and k-ary min/max heaps plus indexed priority queues, ordered by caller-supplied comparators
  • knotkit/prng: Generates seeded pseudorandom numbers and unbiased integers for reproducible simulations and tests
  • knotkit/graph: Provides breadth-first search, Dijkstra, topological order, and connected components over integer-vertex graphs, stored as adjacency lists, compressed sparse rows, or an adjacency matrix
  • knotkit/sampling: Draws unbiased subsets, pairs, shuffles, and weighted samples over injected randomness
{"v":1,"box":[67.6059,107.6111,752.7231,547.8349],"x":{"s":"linear","lim":[-0.72,16.72],"inv":false,"g":0,"t":"Budget (ad units)","tk":[[0,"0"],[4,"4"],[8,"8"],[12,"12"],[16,"16"]]},"y":{"s":"linear","lim":[-0.483776665789,11.2343692389],"inv":false,"g":0,"tk":[[0,"0"],[2,"2"],[4,"4"],[6,"6"],[8,"8"],[10.7505925731,"10.8"]]},"ti":"Full-scan greedy and lazy greedy are optimal at all 9 budgets","a":[{"k":"line","c":"#fffff8","s":"x","d":[0,0,2,0,4,0,6,0.690018435607,8,0.612717287705,10,1.50044759115,12,2.17167847198,14,0.342464058595,16,0.306343816531],"p":[95.89,529.66,174.46,529.66,253.03,529.66,331.6,503.74,410.16,506.64,488.73,473.29,567.3,448.08,645.87,516.79,724.44,518.15]},{"k":"line","c":"#0b7f61","s":"x","d":[0,0,2,0,4,0,6,0.690018435607,8,0.612717287705,10,1.50044759115,12,2.17167847198,14,0.342464058595,16,0.306343816531],"p":[95.89,529.66,174.46,529.66,253.03,529.66,331.6,503.74,410.16,506.64,488.73,473.29,567.3,448.08,645.87,516.79,724.44,518.15]},{"k":"line","c":"#fffff8","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[95.89,529.66,174.46,529.66,253.03,529.66,331.6,529.66,410.16,529.66,488.73,529.66,567.3,529.66,645.87,529.66,724.44,529.66]},{"k":"line","c":"#c4501b","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[95.89,529.66,174.46,529.66,253.03,529.66,331.6,529.66,410.16,529.66,488.73,529.66,567.3,529.66,645.87,529.66,724.44,529.66]},{"k":"line","c":"#fffff8","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[95.89,529.66,174.46,529.66,253.03,529.66,331.6,529.66,410.16,529.66,488.73,529.66,567.3,529.66,645.87,529.66,724.44,529.66]},{"k":"line","c":"#1d5fa6","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[95.89,529.66,174.46,529.66,253.03,529.66,331.6,529.66,410.16,529.66,488.73,529.66,567.3,529.66,645.87,529.66,724.44,529.66]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"fill","c":"#0b7f61"},{"k":"annotation","c":"#0b7f61"},{"k":"annotation","c":"#0b7f61"},{"k":"annotation","c":"#5c5c57"}],"lg":[]} 0 4 8 12 16 Budget (ad units) 0 2 4 6 8 10.8 median of 20 seeds worst seed: 10.75% short at 6 units Reach below the certified best (%) Full-scan greedy and lazy greedy are optimal at all 9 budgets {"v":1,"box":[986.8828,107.6111,1672,547.8349],"x":{"s":"log","lim":[0.01,28183.8293126],"inv":false,"g":1,"t":"Median time (ms, log scale)","tk":[[0.01,"0.01"],[0.1,"0.1"],[1,"1"],[10,"10"],[100,"100"],[1000,"1,000"]],"b":10},"y":{"s":"linear","lim":[-0.65,3.65],"inv":false,"g":1,"tk":[[3,"Branch and bound"],[2,"Full-scan greedy"],[1,"Lazy greedy"],[0,"Stochastic greedy"]]},"ti":"Solve time at 16 units","a":[{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#5c5c57","s":"xy","d":[716.0115215,3],"p":[1502.57,174.16],"r":6.09},{"k":"annotation","c":"#2b2b28"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#5c5c57","s":"xy","d":[0.0229169999993,2],"p":[1025.14,276.53],"r":6.09},{"k":"annotation","c":"#2b2b28"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#1d5fa6","s":"xy","d":[0.0138955000002,1],"p":[1002.06,378.91],"r":6.09},{"k":"annotation","c":"#1d5fa6"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#5c5c57","s":"xy","d":[0.0141460000004,0],"p":[1002.88,481.29],"r":6.09},{"k":"annotation","c":"#2b2b28"}],"lg":[]} 0.01 0.1 1 10 100 1,000 Median time (ms, log scale) Branch and bound Full-scan greedy Lazy greedy Stochastic greedy 716 ms 22.9 µs 13.9 µs 14.1 µs Solve time at 16 units
{"v":1,"box":[210.1597,139.8767,680,555.9677],"x":{"s":"linear","lim":[-0.72,16.72],"inv":false,"g":0,"t":"Budget (ad units)","tk":[[0,"0"],[4,"4"],[8,"8"],[12,"12"],[16,"16"]]},"y":{"s":"linear","lim":[-0.483776665789,11.2343692389],"inv":false,"g":0,"tk":[[0,"0"],[2,"2"],[4,"4"],[6,"6"],[8,"8"],[10.7505925731,"10.8"]]},"ti":"Full-scan greedy and lazy greedy are\noptimal at all 9 budgets","a":[{"k":"line","c":"#fffff8","s":"x","d":[0,0,2,0,4,0,6,0.690018435607,8,0.612717287705,10,1.50044759115,12,2.17167847198,14,0.342464058595,16,0.306343816531],"p":[229.56,538.79,283.44,538.79,337.32,538.79,391.2,514.29,445.08,517.03,498.96,485.51,552.84,461.68,606.72,526.63,660.6,527.91]},{"k":"line","c":"#0b7f61","s":"x","d":[0,0,2,0,4,0,6,0.690018435607,8,0.612717287705,10,1.50044759115,12,2.17167847198,14,0.342464058595,16,0.306343816531],"p":[229.56,538.79,283.44,538.79,337.32,538.79,391.2,514.29,445.08,517.03,498.96,485.51,552.84,461.68,606.72,526.63,660.6,527.91]},{"k":"line","c":"#fffff8","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[229.56,538.79,283.44,538.79,337.32,538.79,391.2,538.79,445.08,538.79,498.96,538.79,552.84,538.79,606.72,538.79,660.6,538.79]},{"k":"line","c":"#c4501b","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[229.56,538.79,283.44,538.79,337.32,538.79,391.2,538.79,445.08,538.79,498.96,538.79,552.84,538.79,606.72,538.79,660.6,538.79]},{"k":"line","c":"#fffff8","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[229.56,538.79,283.44,538.79,337.32,538.79,391.2,538.79,445.08,538.79,498.96,538.79,552.84,538.79,606.72,538.79,660.6,538.79]},{"k":"line","c":"#1d5fa6","s":"x","d":[0,0,2,0,4,0,6,0,8,0,10,0,12,0,14,0,16,0],"p":[229.56,538.79,283.44,538.79,337.32,538.79,391.2,538.79,445.08,538.79,498.96,538.79,552.84,538.79,606.72,538.79,660.6,538.79]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"fill","c":"#0b7f61"},{"k":"annotation","c":"#0b7f61"},{"k":"annotation","c":"#0b7f61"},{"k":"annotation","c":"#5c5c57"}],"lg":[]} 0 4 8 12 16 Budget (ad units) 0 2 4 6 8 10.8 median of 20 seeds worst seed: 10.75% short at 6 units Reach below the certified best (%) Full-scan greedy and lazy greedy are optimal at all 9 budgets {"v":1,"box":[210.1597,771.7439,680,1187.8349],"x":{"s":"log","lim":[0.01,28183.8293126],"inv":false,"g":1,"t":"Median time (ms, log scale)","tk":[[0.01,"0.01"],[0.1,"0.1"],[1,"1"],[10,"10"],[100,"100"],[1000,"1,000"]],"b":10},"y":{"s":"linear","lim":[-0.65,3.65],"inv":false,"g":1,"tk":[[3,"Branch and bound"],[2,"Full-scan greedy"],[1,"Lazy greedy"],[0,"Stochastic greedy"]]},"ti":"Solve time at 16 units","a":[{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#5c5c57","s":"xy","d":[716.0115215,3],"p":[563.81,834.64],"r":6.09},{"k":"annotation","c":"#2b2b28"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#5c5c57","s":"xy","d":[0.0229169999993,2],"p":[236.39,931.41],"r":6.09},{"k":"annotation","c":"#2b2b28"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#1d5fa6","s":"xy","d":[0.0138955000002,1],"p":[220.57,1028.17],"r":6.09},{"k":"annotation","c":"#1d5fa6"},{"k":"segments","c":"#8c8c84"},{"k":"scatter","c":"#5c5c57","s":"xy","d":[0.0141460000004,0],"p":[221.13,1124.94],"r":6.09},{"k":"annotation","c":"#2b2b28"}],"lg":[]} 0.01 0.1 1 10 100 1,000 Median time (ms, log scale) Branch and bound Full-scan greedy Lazy greedy Stochastic greedy 716 ms 22.9 µs 13.9 µs 14.1 µs Solve time at 16 units
  • Same best reach (59.37 expected customers), about 52,000× faster with lazy greedy.
  • There are 1,384,623 ways to spend the full budget.
  • Finding the best split is NP-hard. Branch and bound can take exponential time.

Hover or focus a chart for exact values. Drawn by demo.ts at build time, from the fixtures the benchmark uses; it reproduces the README figure.

Terminal window
git clone https://github.com/jkomyno/knotkit.git && cd knotkit && bun install
bun run demo:problem:budget-allocation

problems/budget-allocation/README.md states the fixture, the seed, and the result table.