There are a number of technologies that when used together could eliminate the problem of unneeded milk being ordered. In this case, a 'smart' fridge would team up with dumb, but enabled packaging (RFID comes to mind) so it knows what is on each shelf and, with a shelf weight sensor, how much product exists. As items are removed and returned to the fridge an exact measurement (where only 1 item is removed) or an approximation (in the case of multiple items) can be used to deplete the inventory quantity of the used item. It really is simple math once the base data is known if you've got the proper senors in place.
The same would be true but on a grander scale (computationally speaking) to link traffic lights with each other and vehicles. Here queuing and cost algorithms are at play for the decision of when to change the light from red to green, but the basic inputs are relatively few.

































