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
- Add a Machine Learning service to your project. You can either do this at the project level (see Creating a Watson Machine Learning Service instance), or this can be done when you first create a new Decision Optimization experiment: click Add a service, select or create a New service, click Associate service in the item bar, then close the pane.
- Associate a deployment space with your Decision Optimization experiment (see Deployment spaces). Even if you have a deployment space associated with your project, you must associate a space with your Decision Optimization experiment. A deployment space can be created or selected when you first create a new Decision Optimization experiment: click Create a deployment space, enter a name for your deployment space and click Create. For existing models, you can also create or select a space in the Overview information pane.
- Download and unzip the DO-samples from the Decision Optimization GitHub on to your machine.
- Create a project in IBM Watson Studio. Select Create an empty project, enter a project name and click Create.
- In the Overview tab of your project, click add a Machine Learning service and select an existing service instance (or create a new one) and click Select.
- Click Add to Project.
- Select Decision Optimization experiment.
- Select the From file tab in the Decision Optimization experiment pane that opens.
- Choose a deployment space from the drop-down menu (or create one) and click Create. If you haven't already associated a Machine Learning service with your project, you must first select Add a service to select or create one, before choosing your deployment space for your experiment.
- Click Add file. Then browse and choose StaffPlanning.zip from the Model_Builder folder in the DO-samples that you downloaded.
- Click Create. A Decision Optimization model is created with the same name as the sample.
Working in Scenario 1 of the
StaffPlanningmodel, 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
- In your project, click Add to Project.
- Select Notebook.
- Select the From file tab in the New notebook pane that opens.
- Browse and choose the CopyAndSolveScenarios notebook from the DO-samples jupyter folder that you downloaded.
- Click Create Notebook. The notebook opens in your project.
- In the More menu , select Insert Project Token. This adds your authorization token in a hidden cell.
- From the main home Navigation Menu, select Administer > Access (IAM) > API keys. Create and copy your API key.
- Return to your
CopyAndSolveScenariosnotebook and locate the cell containing
client=Client(pc=pc,apikey="IAM_APIKEY", and replace
IAM_APIKEYwith your own IBM Cloud API key that you just copied.
Locate the cell containing
decision = client.get_model_builder(name="StaffPlanning").This cell instructs the notebook to copy
Scenario 1from the
StaffPlanningmodel and use it to generate additional scenarios based on randomized data. If you’ve used another name for your model, replace
Staffplanningwith the name you chose.
Run the notebook using
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.
StaffPlanningmodel to compare the solutions of the different scenarios. Click the Scenarios icon to open the Scenario pane and quickly move between scenarios. You can also see all your scenarios at a glance in the Overview pane.
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.