I’ve been unable to match this problem into some canonical one, and I would like some guides to build/use an algorithm and solve it. Description is as follows:
We have some people who want breakfast. Each one may order any number of coffee, juice and toast. We accumulate the order for all the group.
InitialOrder = { C1, J1, T1 } with C1, J1, T1 being integer non-negative numbers.
Each component has a given price, so the total price of the initial order is
InitialPrice = C1 * Pc + J1 * Pj + T1 * Pt with Pc, Pj, Pt being rational positive numbers
Cafeteria has also ‘breakfast menus’ consisting in combinations of standard items
full breakfast = coffee + juice + toast normal breakfast = coffee + toast bread breakfast = 2 toast
Choosing these menus is cheaper than choosing each component separately, so we have
Pf < Pc + Pj + Pt Pn < Pc + Pt Pb < 2 * Pt with Pf, Pn, Pb being rational positive numbers
People want to group the initial order into menus to minimize the total amount spent. Then
FinalOrder = { C2, J2, T2, F, N, B } with C2, J2, T2, F, N, B integer non-negative numbers
and we’ll have a FinalPrice <= InitialPrice as
FinalPrice = C2 * Pc + J2 * Pj + T2 * Pt + F * Pf + N * Pn + B * Pb with Pc, Pj, Pt, Pf, Pn, Pb as rational positive numbers
All prices (Pc, Pj, Pt, Pf, Pn and Pb) are known in advance.
Please, do you know Which approach should I follow to build an algorithm to minimize FinalPrice for a given InitialOrder? Feel free to ask any more details you need.
Thank you in advance.
This looks like a Linear Integer Programming problem.
You have six variables and a linear equation (for final price) which you need to minimize, given linear constraints (must match initial order). The restriction being that the variables are non-negative and take integer values.
For instance in your example case it will be (I am presuming your actual problem is more complicated than your example :-))
Minimize
(Multiply Pc etc with a suitable integer to make them integers if needed)
Subject to the constraints that
In the general case, Integer Programming is NP-Hard, but given the small size of the problem and the constraints, standard solving techniques can probably quickly solve it for you.
Hope that helps.