Monday, September 12, 2022
HomeData ScienceUtilizing Python and Operational Analysis to Optimize your Happiness | by François...

Utilizing Python and Operational Analysis to Optimize your Happiness | by François St-Amant | Sep, 2022


Utilizing Gurobi and the knapsack drawback to search out an optimum resolution

Supply: https://unsplash.com/images/u0vgcIOQG08

With out figuring out, individuals are always attempting to optimize their lives. As an illustration, by occurring trip, you resolve that the journey is price it, even when it comes at a monetary value.

Sadly, you can not spend all of your time in search of solely pleasure. Most individuals should take into consideration their longterm wellbeing as nicely.

Certainly, on a given morning, a person might choose going skydiving as an alternative of going to work. Nevertheless, ultimately, if this particular person by no means goes to work and goes skydiving as an alternative, he’ll quickly run out of cash, lose his job and won’t be able to afford to go skydiving anymore.

This stability between work and play will be onerous to search out. How can I decide which actions to take with a view to maximize my happiness?

This all sounds rather a lot just like the knapsack drawback, a basic of operational analysis.

The knapsack drawback is a combinatorial optimization drawback the place you will have a set of things which have a sure worth and quantity that you simply wish to put in a backpack. Contemplating that the backpack has a restricted capability, you need to resolve which gadgets to place within the bag to maximise the worth.

Supply: https://en.wikipedia.org/wiki/Knapsack_problem

In our case, as an alternative of objects, values and volumes (like within the knapsack drawback), we will assume by way of actions, the pleasure they carry and their value (each by way of money and time).

Within the following instance, I shall be displaying a fictional instance of how a person might resolve on his weekly schedule to maximise his wellbeing and pleasure.

The article may also present you how one can resolve an Operational Analysis drawback utilizing Python. I shall be utilizing Gurobi (and most particularly the Gurobi Optimizer), an incredible product that lets you simply mannequin and resolve all kinds of Operational Reasearch issues.

1. The variables

Step one in the issue is to find out what actions have to be executed. For every exercise, you additionally have to specify:

  1. The price of doing it (for 1 hour on this instance)
  2. The pleasure it brings (grade from 1 to 10)
  3. How helpful it’s to you well being clever (monetary, bodily, psychological, and so forth.). Grade from 1 to 10 once more.
  4. The minimal and maximal period of time you can spend on this particular exercise.
  5. Your complete funds, i.e. how a lot you may spend weekly on “actions”.
  6. How a lot time you will have, eradicating sleep, transportation, and so forth.

So as an illustration, the person right here doesn’t take pleasure in going to the fitness center a lot (pleasure = 1). It’s nevertheless deemed very helpful for common wellbeing. However, gaming is pleasurable however doesn’t contribute to wellbeing as a lot.

After all, the problem right here is to fill out all of this. How a lot pleasure does an exercise deliver? How good is it for you? That is very subjective and onerous to quantify. Solely the particular person doing the exercice is aware of what the precise values are! It relies upon what you need in life, what your targets are, and so forth.

2. The constraints

As soon as we have now our variables, we will add constraints to the mannequin. That is the place we make sure that our closing resolution will respect the principles specified earlier.

  • Line 4: we specify that our variables are integers, i.e. numbers
  • Line 7: the overall amount of cash spent have to be inferior or equal to our funds
  • Traces 10 and 13: we should respect the minimal and most for every variable. In different phrases, if the particular person mentioned he should work between 35 and 45 hours, it have to be revered
  • Line 16: The sum of time spent on all our totally different actions have to be equal to the time specified

3. The target operate

Now, it’s time to optimize our goal. This goal is totally different for everyone! Some simply wish to take pleasure in life as a lot as attainable. Others wish to work extra to get a promotion. Others need an ideal stability. The operate shall be totally different for everybody as a result of everybody has a distinct definition of happiness.

Right here is the target operate used on this instance.

As you may see, the aim right here is to maximise the sum of delight and wellbeing. Nevertheless, pleasure is given extra significance than wellbeing, for the reason that latter is multiplied by 0.75.

4. The answer

We will lastly optimize our drawback and get our optimum resolution!

Listed below are the outcomes.

So the particular person beneath, to optimize his goal operate (and so his happiness), should work 45 hours every week, play golf for two hours, watch netflix for 15, and so forth.

Based mostly on all that the particular person has specified, that is what is going to optimize his goal operate and make him happiest!

First of, it is a very common drawback, however you may at all times add extra constraints, variables, and so forth. to make it extra complicated and extra consultant of the true world. I used the instance of every week however it may be a month, a 12 months…no matter you need! Gurobi makes it very simple to take action. Look it up right here! https://www.gurobi.com/documentation/9.5/refman/refman.html

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments