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.
Before you begin
Copy link to section
Requirements
To edit and run Decision
Optimization models, you must have the following prerequisites:
Admin or Editor roles
You must have Admin or Editor roles in the
project. Viewers of shared projects can only see experiments, but cannot modify or run them
watsonx.ai Runtime service
You must have a watsonx.ai Runtime service that is
associated with your project. You can add one when you create a Decision
Optimizationexperiment.
Deployment space
You must have a deployment space that is associated with your Decision
Optimizationexperiment. You can choose a deployment space when
you create a Decision
Optimizationexperiment.
About this task
Copy link to section
The files used in this example are in the DO-samples project. The model concerned is
StaffPlanning and the notebook is
CopyAndSolveScenarios.
Procedure
Copy link to section
To create and solve a scenario using a sample:
Download and extract all the DO-samples on to your machine. You
can also download just the StaffPlanning.zip file from the
Model_Builder subfolder for your product and version, but in this case do not
extract it.
Open your project or create an empty project.
Select the Assets tab.
Select New asset > Solve optimization
problems in the Work with
models section.
Click Local file in the Solve optimization
problems window that
opens.
Browse to choose the StaffPlanning.zip file in
the Model_Builder folder. Select the relevant product and version subfolder.
If you haven't already associated a
watsonx.ai Runtime service with your project, you must first
select Add a Machine Learning service
to select or create one before you choose a deployment space for your experiment.
Click Create.
A Decision
Optimization model is created with the same name as the
sample.
Working in Scenario 1 of the StaffPlanning model, you can see that the
solution contains tables to identify which resources work which days to meet expected demand.
If there is no solution displayed, or to rerun the model, click Build model in the sidebar, then click
Run to solve the model.
Using a random generator to create new scenarios
Copy link to section
Procedure
Copy link to section
To create new scenarios using a randomized data using a sample:
Select the Assets tab.
Select New asset > Work with data and
models in Python or R notebooks in the Work with
models section.
Select the Local
file tab in the new window
that opens.
Click Drag and drop files or
upload and browse to choose
the CopyAndSolveScenarios notebook from the jupyter
folder. Select the relevant product and version subfolder.
Click Create Notebook.
The notebook opens in your
project.
In the Settings tab of your project, locate the
Access Tokens section, and click New token +. Enter a
token name, select Editor as the Access role and click
Create.
Return to your notebook from the Assets tab of
your project and click the pencil icon to edit it. In the More menu , select
Insert Project Token. This adds your authorization token in a hidden
cell.
From the main home Navigation Menu, select
Administration > Access (IAM) > API keys. Create and copy your API key.
Return to your CopyAndSolveScenarios notebook and
locate the cell containing client=Client(pc=pc,apikey="API_key", and replace
API_key with your own IBM Cloud API key that you just copied.
Locate the cell containing decision =
client.get_experiment(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.
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.
Open the StaffPlanning model 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.
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.
Results
Copy link to section
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.
About cookies on this siteOur websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising.For more information, please review your cookie preferences options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.