How to use IT and “Linear Programming” to please your partner!

Posted on

Linear programming has commonly been used in optimisation for a long time, especially in production, investment and transport problems. However it doesn’t need to be boring all the time and it can be used to improve your personal life.

In this example we are going to plan our anniversary and try to get the best out of our money (high benefit is very goooood!).

You have thought about possible presents and activities that you could prepare and with some of your friends help you came up with this table.

You have thought about buying Flowers and Chocolates, organising a trip, have a nice dinner and maybe going to the cinema or the opera. However, you don’t have unlimited resources, you only have $500 and the next release is coming up and you can only have 6h to organise everything without her suspecting something.

low budget

high budget



prep. time




prep. Time



1 Rose (F1)




12 Roses (F2)





8 Pack (C1)




24 Pack (C2)





daytrip (T1)




weekend (T2)




Art & Culture

Cinema (A1)




Opera (A2)





Normal (D1)




Upper class (D2)




Additionally you don’t want to double up in the type of present because it doesn’t make sense buying a small and a large box of chocolates (at most 1 of the presents of each type)

Then, the big question. How can I improve the benefit with these restrictions?

/* ——— Objective function – Maximise Benefit ————-*/

max: 5 F1 + 8 F2 + 5 C1 + 7 C2 + 12 T1 + 30 T2 + 3 A1 + 20 A2 + 8 D1 + 10 D2;

/* ————- Restrictions —————-*/

// Limited budget (We only have $500)

4 F1 + 40 F2 + 5 C1 + 16 C2 + 65 T1 + 250 T2 + 20 A1 + 180 A2 + 50 D1 + 120 D2 <= 500;

// Limited the preparation time (We only have 6h to prepare it)

1 F1 + 1 F2 + 0.5 C1 + 0.5 C2 + 1.5 T1 + 4 T2 + 0.25 A1 + 1 A2 + 0.5 D1 + 0.5 D2 <= 6;

// Only get one of the same category products

F1 + F2 <= 1;

C1 + C2 <= 1;

T1 + T2 <= 1;

A1 + A2 <= 1;

D1 + D2 <= 1;

// The values are integers because we can’t buy ½ Opera for instance (0 or 1)

int F1,F2,C1,C2,T1,T2,A1,A2,D1,D2;


To solve this problem you can use one of the several products in the market. I have used lpsolve, a free option with LGPL license (there is a GNU package as well). You can also use the Excel solver; however you need to transform the problem into an Excel Spreadsheet.

Once the problem is solved we get that to get the maximum benefit we need to get: A2 (Opera), C2 (Big chocolates), D1 (small dinner) and T2 (a weekend) with a benefit of 65 and a total cost of $496. This will take you 6h to organise.

But we haven’t finished yet. Let’s do a bit of pos analysis:

Notice that we have $4 left so there is still some possible gain that we could get. Our benefit has been restricted by the time we can spend organising the surprise.

What if I could squeeze 0.5 hour more?

Well then, the optimal solution would become: A2, C2, T2 and F2 to achieve the same benefit, 65. However, if we have a look at the total cost, we would save money only $486 for the same benefit.

And, if we can add half an hour more and make it 7?

Now the solution would be: A2, C2, D1, T2 and F1 with a total benefit of 70 and a cost of $500.

This optimisation approach and post analysis can be used for a number of problems

-Restriction 1: limited by your imagination

-Restriction 2: limited by the time your partner lets you spend investigating J

Have fun!


One thought on “How to use IT and “Linear Programming” to please your partner!

    Ruggy said:
    September 4, 2008 at 09:56

    Need to talk to you ! please contact me !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s