Generalized Restless Bandits and the Knapsack Problem for Perishable Inventories