Generating multiple scenarios

This tutorial shows you how to generate multiple scenarios from a notebook using randomized data. Generating multiple scenarios lets you test a model by exposing it to a wide range of data.

About this task

The files used in this example are in the DO-samples project. The model concerned is StaffPlanning and the notebook is CopyAndSolveScenarios.


  1. Download and unzip the DO-samples from the Decision Optimization GitHub on to your machine.
  2. Create a project in IBM Watson Studio. Select Create an empty project.
  3. Click Add to Project.
  4. Select Decision Optimization.
  5. Select the From file tab in the New Decision Optimization experiment pane that opens.
  6. Associate a Machine Learning service instance with your project and reload the page.
  7. Click Add file. Then browse and choose from the Model_Builder folder in the DO-samples that you downloaded.
  8. Click Create.
    A Decision Optimization model is created with the same name as the sample.
  9. Working in Scenario 1 of the StaffPlanning model, click Run model in the sidebar, then click Run to solve the model.
    The solution contains tables to identify which resources work which days to meet expected demand.

Using random generator to create new scenarios


  1. In your project, click Add to Project.
  2. Select Notebook.
  3. Select the From file tab in the New notebook pane that opens.
  4. Browse and choose the CopyAndSolveScenarios notebook from the DO-samples jupyter folder that you downloaded.
  5. Click Create Notebook.
    The notebook opens in your project.
  6. In the More menu More menu icon containing three vertical dots, select Import Project Token. This adds your authorization token in a hidden cell.
  7. From the main home Navigation Menu, select Manage > Access (IAM) > IBM Cloud API keys. Create and copy your API key.
  8. Return to your CopyAndSolveScenarios notebook and locate the cell containing client=Client(pc=pc,apikey="IAM_APIKEY", and replace IAM_APIKEY with your own IBM Cloud API key that you just copied.
  9. Locate the cell containing decision = client.get_model_builder(name="StaffPlanning").
    This cell instructs the notebook to copy Scenario 1 from the StaffPlanning model and use it to generate additional scenarios based on randomized data. If you’ve used another name for your model, replace Staffplanning with the name you chose.
  10. Run the notebook using Cell>Run All.
    The notebook uses the Python random module to generate data for five additional scenarios in the model named StaffPlanning. The new scenarios are named Copy 01 ... Copy 05. The number of scenarios to generate is specified in cell 9, N_SCENARIOS = 5.
  11. Open the StaffPlanning model to compare the solutions of the different scenarios. Click the Scenarios icon to open the Scenario panel and quickly move between scenarios.
  12. Click Visualization in the navigation pane to compare the different scenarios on the Multi Scenario tab.
    The Demand chart plots the demand for the different periods in the randomly generated scenarios. The KPIs chart plots the total cost across the randomly generated scenarios. The My KPIs chart provides a heat map of costs for the different scenarios along with the mix of temporary and fixed resources for each.


This example shows how easily you can test your model by generating additional scenarios based upon randomized data. Such testing makes it possible to assess whether the model is robust enough to perform effectively in an environment with variable data.