# Stochastic Optimization Introductory Example

Decision Optimization allows to take optimal decisions on “what to do next”, based on some given data (resources, demands, machine capacities, etc). Most of the times, this data is considered as perfectly known and models are deterministic. In fact, data always include some uncertainty. The question is whether this uncertainty has some impact on not on the validity of the decisions.

Some methods exist to manage uncertainty when its impact is significant, such as robust and stochastic optimization.

This DSX Public notebook is a very basic and practical introduction to 2-stage stochastic optimization.

**Problem**

Imagine you have to decide 2 numbers X and Y which sum has to be greater than a unknown value D, while minimizing the weighted sum of the two numbers.

If you can decide the 2 numbers AFTER the value is known, this is obvious. This is a standard deterministic linear problem.

Now imagine you can decide on one number first (e.g. X) but the second one (e.g. Y) can only be decided after the value D is known. If both numbers counts equally in the objective function then you will want to set 0 as the first number and decide everything later. But if the first number is “cheaper”, then selecting the two numbers becomes tricky.

The Y decision which can be taken after the unknown is revealed, is usually called “recourse decision”.

Note that if we can choose any number, then there is no “robustness” issue, there will always exist a solution. Our objective should hence be to find the value for X which is best on average, i.e. minimize the expected weighted sum of X and Y over all possible values of D.

**Business use**

This illustrative but very basic example has lots of real life applications.

The general idea is that you have to fulfill some initially unknown demand of goods (whatever). You can buy these goods early and cheap, or more expensive later, after you know the demand. For example, you own a restaurant on the French Riviera and you need fresh bread for everyone eating at our restaurant, but you don’t exactly know how many people will come and have lunch tomorrow. You can buy some bread in advance, cheaper, or you can buy it at the last minute when people comes in the restaurant, but hence this is more expensive. Everyone must have bread, so you need to cover the demand, and this is not acceptable to throw away some or keep for the next day. So you exactly need to match the unknown demand. (To keep all this simple, but that could be modeled)

See the notebook shared output:

https://apsportal.ibm.com/analytics/notebooks/fbd32016-7d11-4ecf-8945-7d5e7f714896/view?access_token=38d63d50b379997fd3a008c59e610dfea801af9b42bca85ab25c39c64cbbc54b