Expand description
Dynamic programming: classic optimisation problems solved by tabulation, and solvers for Markov decision processes.
The first group (knapsack, coin change, longest common / increasing subsequence, edit distance,
matrix-chain ordering) each return the optimal value together with a reconstruction of one
optimal solution. The second group, FiniteMdp, solves sequential decision problems by
backward induction (finite horizon) or value iteration (discounted, infinite horizon).
See the book entry Dynamic programming.
Structs§
- Finite
Mdp - A finite Markov decision process: in state
s, taking actionayieldsrewards[s][a]and moves to states'with the probabilities intransitions[s][a](a list of(s', prob)). Every state must offer at least one action; the probabilities of each action must sum to 1. - MdpSolution
- The value function and a greedy policy.
Enums§
- EditOp
- One step of an edit script turning sequence
aintob.
Functions§
- coin_
change_ min_ coins - The fewest coins (unlimited supply of each denomination) summing to
amount, as the count of each denomination;Noneif the amount cannot be made. Zero-valued denominations are ignored. - coin_
change_ ways - The number of distinct multisets of coins summing to
amount(order ignored), saturating atu64::MAX. - edit_
distance - Levenshtein distance between
aandb(unit cost for insert, delete and substitute) and one optimal edit script. - knapsack_
01 - 0/1 knapsack: chooses items (each at most once) maximising total value within
capacity. Returns(best value, chosen item indices in increasing order).O(n · capacity)time and memory. - longest_
common_ subsequence - A longest common subsequence of
aandbas pairs of matched indices(i in a, j in b). - longest_
increasing_ subsequence - A longest strictly increasing subsequence, as indices into
values, inO(n log n). - matrix_
chain_ order - The cheapest way to multiply a chain of matrices where matrix
kisdims[k] × dims[k+1]:(scalar multiplications, parenthesisation such as "((A0A1)A2)"). Needs at least one matrix (dims.len() >= 2).