Designing a rationing algorithm for a store Suppose I have a store and I have n units of item x. I want to sell all n units at the end of the day. I do not know how many customers will be coming in today. One customer could theoretically come in and buy all remaining units. This would not be desirable, as the next customer would not be able to buy this item, and would end up frustrated that we do not keep enough in stock. 

In general, how does one design a rationing algorithm that balances the need to sell as much quantity as possible with serving the most amount of (unknown number of) customers? Is this even possible?
This sounds like a maximization problem. The algoritm should try to maximize something, let us call it utility.  What You need to start with is to define the utility funktion: is it better to sell all to first customer or end the day with unsold goods?