0
$\begingroup$

So I feel like I'm in elementary school again, but I have an optimization problem I've been banging my head against, I'll abstract it into a word problem.

Say that I have a factory that makes chocolate chip cookies, but they make a wide variety of cookies each with a different (integer) number of chips in them.

The chocolate chips themselves are stored in containers which hold a discrete, integer number of chips X. An order might ask for any number of cookies, and will contain multiple varities of cookies (e.g. An order might ask for 2 cookies with 5 chips, and 3 cookies with 4 chips). However, the machine that distributes the chips is only allowed to make one trip, and therefore must gather all the chips it needs from one container.

Therefore, is there a way to determine, knowing the contents of an order, the fewest number of containers possible such that if the cookies were made in any possible order the machine could always find enough chips in a single container to make the cookie?

A few assumptions can be made which simplify the problem:

  • The cookie machine is relatively smart. It knows the chip count of all containers and can access any of them, and is not required to "finish" a container before using another.
  • There will never be a case where a cookie requires more chips than 1 container provides
  • This is a programming problem so recursive solutions are usable.

Right now I'm solving it by over-estimating the number of containers and chips I'm using, but that has a monetary cost to it. I'm sure the solution is simple, but for the life of me I can't make headway on it.

  • 0
    What are the constraints? How many types of cookies can there be, and what can the size of the orders be?2017-01-25
  • 0
    Anywhere from 2 to X where X is the number of chips the container can hold for the types of cookies. There will never be a one chip cookie. The size of the order can be 1 to infinity in theory. In practice its ~90-1000 cookies.2017-01-25

1 Answers 1

1

This is the bin packing problem, which is NP hard. You can find a discussion of it in its wikipedia page