# Including generated scenarios in the optimization | | | |---|---| |License|yes| |Release version|10.8| This functionality allows Prodrisk to include additional generated scenarios in the optimization. The scenarios are redrawn each iteration, and are only included in the beginning of each main iteration. At the end of each main iteration, Prodrisk optimizes only on the historical scenarios. This mechanic is controlled by the attributes [last_iteration_generated_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#last-iteration-generated-scenarios) and [min_iterations_without_generated_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#min-iterations-without-generated-scenarios) (see [Attribute list](#attribute-list) below). The number of additional generated scenarios are controlled by the attribute [n_generated_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#n-generated-scenarios). For each of the scenarios, inflow and price series are drawn from the [chosen inflow model](inflow_model.md) and [price model](../../price/price_model/price_model.md) used during backwards recursion. Correlation between inflow and price is not considered, since these are sampled independently. For the inflow sampling, there exists three configurations, controlled by the attribute [generated_inflow_type](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#generated-inflow-type): - **Random** (*generated_inflow_type = 0*) - inflow series are drawn directly from the chosen inflow model - **Percentiles** (*generated_inflow_type = 1*) - samples from the inflow model are sorted by sum inflow over the simulation period, and percentiles are chosen. - **Extremes** (*generated_inflow_type = 2*) - samples from the inflow model are sorted by sum inflow over the simulation period, and extremes "on both ends" are chosen. For the configurations "Percentiles" and "Extremes", the number of samples to choose from is controlled by the attribute [n_sample_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#n-sample-scenarios). The different types of inflow sampling are illustrated in the figure below: ![](./images/generated_inflow_configurations.png) ## Output to the log file When using the functionality, Prodrisk will write a descriptive message to the log file prior to the optimization: ``` Using 6 generated scenarios until iteration 30 Using extreme inflow scenarios Total: 64 scenarios ``` In the above example, 58 historical scenarios are used during the entire optimization, and 6 additional generated scenarios are used until iteration 30. Prodrisk writes to the log file when the generated scenarios are removed: ``` Max Limit: Remaining iterations without generated scenarios ``` If convergence is achieved before iteration 30, the generated scenarios will be removed and Prodrisk will write the following message to the log file: ``` Convergence: Remaining iterations without generated scenarios ``` (attribute-list)= ## Attribute list |prodrisk.CPAR | API attribute | Default value | Explanation| |---------------|--------------|------------|------------| |n_gen_forward|[n_generated_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#n-generated-scenarios)|0|Number of generated scenarios to include in the optimization| |n_sample_forward|[n_sample_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#n-sample-scenarios)|1000|Number of sampled inflow scenarios to generate percentiles or extremes from| |gen_inflow_forw_type|[generated_inflow_type](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#generated-inflow-type)|0|Type of generated inflow sampling (0: Random, 1: Percentiles, 2: Extremes)| |last_iter_gen_forw|[last_iteration_generated_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#last-iteration-generated-scenarios)|1000|Last iteration where generated scenarios are included in the optimization| |min_iter_no_gen_forw|[min_iterations_without_generated_scenarios](https://docs.prodrisk.sintef.energy/objects/setting/setting.html#min-iterations-without-generated-scenarios)|10|Minimum number of iterations without generated scenarios at the end of the optimization|