# Optimizing with Uncertainty

Analytica uses Monte Carlo simulation to analyze uncertain quantities. Probability distributions are represented as sample arrays that include the system index Run. Each element of the Run index represents a sample of possible values for uncertain quantities, according to the chosen probability distribution. As an array dimension, Run propagates through the model in the same way as any other index. How can uncertain quantities be combined with optimization and how should we interpret results of uncertain optimizations?

There are two basic approaches to combining uncertainty with optimization in Analytica.The appropriate approach depends on whether the decision maker must commit before or after the uncertainty is resolved. These lead to a Monte Carlo simulation within a single optimization (the Stochastic approach) or an optimization within each Monte Carlo scenario (the preposterior approach). For convenience, we label these FAST and MOSS, respectively.

1. Optimize on Fractiles or Averages Stochastically (FAST)

Reduce the Run index in the Objective and Constraints by using summary statistics. In the Airline example, Module 3, we maximize the expected value of the objective: Mean(Profit). This collapses the Run dimension so that there is a scalar objective, and hence only one optimization. Fractile statistics are also commonly used instead of expected value. You can summarize the Objective as the median (50% fractile) or any other fractile value using the GetFract() function. For example, a constraint might require the 5% fractile for Profit to be greater than a certain value. In any case, it is important to reduce the Run index in the Objective as well as all Constraints when performing Stochastic Optimization.
1. Multiple Optimizations of Separate Samples (MOSS)

Treat Run as an extrinsic index, abstracting it over the optimization. The result is a Monte Carlo sample of solutions. Each solution represents optimum decisions corresponding to the input values of an individual Monte Carlo sample. The MOSS method establishes the range of decision values that should be considered given the uncertainty. But it assumes that the actual decision will be made a posteriori, or after the uncertainty is resolved. Even though Analytica’s Intelligent Arrays make setting up MOSS optimizations much easier than in other environments, the method remains computationally intensive on all platforms. The sheer number of optimizations (equal to the sample size) may prevent the computational stone from rolling along as fast as you would like it to. It is always important to choose the correct sample size when using the MOSS method. For NLPs, you should also avoid unnecessary computation by identifying context variables. (See Improving Computational Efficiency of NLPs).

### Module 3: Stochastic Optimization (FAST)

Starting with the Module 1 Base Case, suppose that Base Demand and Elasticity are uncertain quantities described by triangular distributions:

Chance Base_Demand := Triangular(300k, 400k, 500k)
Chance Elasticity := Triangular(300k, 400k, 500k)


Create a new Objective for the expected value of Profit. Use this as the objective for the optimization.


Objective Mean_Profit := Mean(Profit)
Variable Opt := DefineOptimization(
Decisions: Number_of_Planes, Fare,
Maximize: Mean_Profit)


Analytica allows you to adjust the sample size (the size of the Run index). For new models, the default is 100. For the Airline NLP example, we only use 10. Select Uncertainty Options from the Result menu and enter 10 for the sample size.

This result represents the decision values that yield the highest expected value for Profit. It would be appropriate to implement these values if the uncertainty cannot be resolved before the decision is made, and if maximizing expected value of Profit is your goal. The values differ only slightly from the Base Case.

### Module 4: Multiple Optimizations of Separate Samples (MOSS)

If you evaluate the Profit Objective from Module 3 (not the mean of Profit) and view in Sample mode, you’ll see that it’s an array dimensioned by Run.

Naturally, the Run index was propagated to Profit from the Base Demand and Elasticity inputs. As long as an index does not originate from a Decision, it is eligible for array abstraction. To get a Monte Carlo sample of optimizations, we just need to make sure the dimension gets propagated all the way to the DefineOptimization() node. In Module 3, the Mean function reduced the Run index before it could get that far.

Delete the Mean_Profit node and switch back to Profit as the optimization objective.

Variable Opt := DefineOptimization(
Decisions: Number_of_Planes, Fare,
Maximize: Profit)


If at first, the result does not look like it includes the Run index, remember that you must view it in Sample mode.

The MOSS approach does not determine what the best decision would be under circumstances of uncertainty. It gives us a range of decisions that would be optimal in situations where the corresponding Base Demand and Elasticity are already known with certainty. This allows you answer questions that would not be addressable using Stochastic Optimization. For example, “What is the current expected value of Profit, given that the Number of Planes and Fare decisions will be determined after Base Demand and Elasticity uncertainties are resolved?” The answer to this question is simply the average of the Optimal Profit samples (although it would be a good idea to use a larger sample size to avoid inherent sampling error.)