This hands-on lab is created around the persona of a store manager. The manager has information about the demand, and wants to ensure that inventory is optimized by minimizing the cost of distribution. There are many distribution plants to pick from, each with their own capacity and their own cost. Our goal is to minimize the total cost, while still ensuring we meet all of the demand.
In the previous tutorial we used SPSS Modeler to build a model to predict demand. As you can see below, we will use the demand as input, and other information about the distribution plants such as production cost and capacity, to reach our goal of minimizing overall cost.
In this tutorial, you will explore the following key capabilities:
- You will learn how to build Optimization model
- A model builder to guide developers through the typical optimization development steps
- Dashboards for communicating the optimization model results
Required software, access, and files To complete this lab, you will need:
- IBM Cloud Pak for Data
- IBM Watson Machine Learning Service
After the prerequisites are met, it should take you around 35-45 minutes to complete this tutorial.
If you are familiar with optimization problems, you can skip down to step 1.
Skip down to steps if familiar with Optimization problems
As shown below, there are 5 main steps in order to reach an optimal decision. As users of Decision Optimization, we are only concerned with step 1 and step 2. We want to formulate the business problem, as an optimization problem. That means we have to create data tables to represent our business problem.
An Optimization problem is the problem of finding the best solution from all possible solutions. We do this by defining objectives, constraints, and decision variables.
We have to create an optimization model in order to ensure that our CPLEX Optimization engine knows how to solve the correct problem. Let's take a look at the optimization model in more detail.
An optimization model defined in terms of
- an objective, decision variables, and constraints
- a optimization engine to solve the model instance
- data to create an instance of the model
An objective is what we are trying to solve for. An example of this is maximizing (profit) or minimizing cost, as is the case in our example here.
A constraint is a condition that the problem must meet in order to reach an optimal solution. For our example, we are limited by the capacity of our distribution plants. The capacity (or the maximum number of units that a plant can produce) is our constraint in this example.
A decision variable is a quantity that the decision-maker controls. In our case, the decision-maker is the CPLEX Optimization engine, and the quantity that it controls is the quantity of each product to be produced at a particular plant.
Some of the main use cases for optimization are portfolio allocation based on risk-reward, allocation of human resources, and determining which plant should manufacture which product, which is the focus of this tutorial.
- Create Watson Studio service
- Create a project
- Create a Decision Optimization experiment
- Create a Deployment Space
- Clone the Repo
- Prepare the Data
- Prepare the Model
- Add Objectives
- Add Constraints
- Explore Solution
- Deploy Model (Optional - needed for web-app only)
- Import Intermediate Scenario
- Conclusion
First login to your IBM Cloud account. Use the video below for directions on how to create IBM Watson Studio Service.
-
After logging into IBM Cloud, click
Proceedto show that you have read your data rights. -
Click on
IBM Cloudin the top left corner to ensure you are on the home page. -
Within your IBM Cloud account, click on the top search bar to search for cloud services and offerings. Type in
Watson Studioand then click onWatson StudiounderCatalog Results. -
This takes you to the Watson Studio service page. There you can name the service as you wish. For example, one may name it
Watson-Studio-trial. You can also choose which data center to create your instance in. The gif above shows mine as being created in Dallas. -
For this guide, you choose the
Liteservice, which is no-charge. This has limited compute; it is enough to understand the main functionality of the service. -
Once you are satisfied with your service name, and location, and plan, click on create in the bottom-right corner. This creates your Watson Studio instance.
-
Go to https://cloud.ibm.com/resources and then click on your recently created
Watson Studioservice.
- Next, click on
Get Started.
Once you click on your Watson Studio service, you should be taken to Cloud Pak for Data overview page. From there, click on Projects.
You will be taken to a page which shows your projects. Click on New Project.
Next, you will be given the option to create a project from a file or from scratch. Click on Create an empty project.
Next, you will define your project details. First we need to add a storage service. Click on Add.
This will take you to the create Cloud Object Storage page. Name your resource as you wish, and click Create.
Next, once you go back to your new project, your newly created Cloud Object Storage should automatically be detected. Name
the project as you want, and click Create.
Next, from your newly created project, click on Add to project.
Select Decision Optimization experiment.
You will be taken to the New Decision Optimization experiment page. You'll need a Machine Learning service to work with Decision Optimization.
Click on Add service.
This will take you to the Associate service page. Click on New service, unless you already have a Watson Machine Learning service.
Next, click on Machine Learning.
This will take you to the create Machine Learning service page. Name the service as you want, and then click Create.
You will be directed back to the Associate service page. This time, your newly created Machine Learning service should appear. Click on
the check-mark next to it, and then on Associate service.
After you associate your service, you should be taken back ot the New Decision Optimization experiment page. Next, we need to add a Deployment space. If you do not have one yet, click on Create a Deployment space.
Name the deployment space as you want, and then click Create.
Back on your New Decision Optimization experiment page, your newly created deployment space should be populated. Click Create.
In a terminal of your choice, issue the following command to clone this repository so that you have all the data files needed for our experiment.
git clone https://github.com/IBM/optimize-procurement-and-inventory-with-ai.git
Next, from the project overview page click on Assets from the top tab, and then go down to your newly created Decision Optimization experiment and click on it.
You will then be taken to the Prepare data page of your experiment. Click on browse in the top-right to add data.
Browse to where you cloned the repository, and go to decision-optimization-case-study/tutorials/decision-optimization-tutorial/intro-scenario/data and then select plants.csv and customerDemand.csv and click Open.
Next click on Import.
Next, from the Prepare data page, click on Run model.
Next, click on Modeling assistant.
Next, you'll be asked to choose the domain of your problem. Choose Selection and Allocation.
Next, we will choose the decision variable. This is what the model will be deciding. For us, it's the optimal number of items to be produced at a certain plant.
Choose the plants table, and then click continue.

-
Now the first thing we must do after we have prepared our problem statement is to add our objectives.
-
First, delete the default objective.
-
Next, type in
maximize total plants allocationsinto theSuggestionsbox. Click on the plus sign to add it to our model. -
Next, type in
minimize total cost of plants over all allocationsinto theSuggestions. Add this to our model.
-
The default constraint for our problem is to
Synchronize selection with plants allocations. Expand this statement to define the max and min values. -
Ensure that the max allocation of plants is defined by
Capacity. -
Next, the min assignment of plants is
0. -
Next, move the slider next to
Maximize total plants allocationsto 10, in order to prioritize this objective. -
Next, type in
All plants allocations must be integerinto theSuggestions. Add this to our model. -
Next, type in
for each plants, allocation is less than or equal to Capacityinto theSuggestions. Add this to our model. -
Lastly, type in
for each customerDemand, total allocation of plants (such that plants Product is customerDemand) is less than or equal to Demandinto theSuggestions. Add this to our model.
Next, make sure the objectives and constrains are the same as the screenshot below, and then click on Run model from the
top-right.
-
Let's examine our data. Our primary goal with our optimization is to meet demand since we prioritized that objective by moving the slider to 10.
-
We know that demand is 100 for hand sanitizer and 120 for masks.
-
We also know there are two plants that have high cost (3). We want to limit allocating masks and hand sanitizer from those plants as much as possible.
Let's examine the solution. Click on the button next to the magnifying glass to open the table in a full screen.
We can now examine the solution.
Note: if you got an error running the model, you can simply click on Scenarios in the top right corner, then Create Scenario and From file and then import the introScenario.zip file from the tutorials/decision-optimization-tutorial/data directory. After you've imported it you can simply click on Run model to see the results.
-
We see that from the plant that produces mask with the highest cost of 3, we have allocated 0.
-
The plant that produces hand sanitizer with the highest cost of 3, we allocated only 70 units, which is below capacity of the plant.
-
All other plants allocated all of capacity, other than plant 2 which allocated 15 units to masks, since we already produced enough for demand.
In conclusion, CPLEX allocated 100 units to the lowest cost plants for creating hand sanitizer, and 120 for masks. We met demand, at the lowest cost possible.
Go back to your introScenario by clicking on the scenario on the top of the page. Click on the
three-dot icon and then on Save for deployment.
Name the model as you want. Click Save.
You should see a notification that the model was successfully saved. Click on View in project. If you missed
the notification, just click on Projects/demo-sept29.
From your project, go down to Models. You should see your newly saved model there. Click on the three-dot icon and then on Promote.
The next page will let you pick which space to deploy to. Pick the one we created in step 4. Click Promote.
You should see a notification that successfully promoted your model to the deployment space. Click on the
deployment space in the notification to prepare your model for deployment.
In your deployment space, you should see your model that you promoted. Click on Deploy.
This will create a deployment. Name it as you want, and select the hardware definition you want. Click Create.
Once you've created the deployment, you should see the Deployment ID on the right-hand side of the screen.
Copy this. You will need this for the web-application environmental variables. Once you've saved
your Deployment ID, click on your deployment space. Mine is horea-deploy-demo.
Once you're in your deployment space, click on settings from the top of the page.
There you will see your Space ID. This is needed for the web-app.
Next, let's import a more complex scenario. Click on the Scenarios Button from the top tab.
From the Scenarios tab, click on Create scenario and From file.
Navigate to where you cloned this repo, and then select go into the decision-optimization-tutorial/data and select the intermediateScenario.zip file. Click Open.
Next, click on Prepare data from the left side bar to see the data that is being used for this scenario. You can see here that
the customerDemand table has 29 rows, and that the plants table has 90 rows. The customerDemand table is taken from the
last month of estimated demand from the SPSS Modeler tutorial, and rounded to the nearest integer value.
It also has an extra column, which is the Profit column.
The Profit column enables us to determine which allocations will bring us the largest profit.
Next, click on the the Run model tab from the left side bar. Here you can see a new objective Maximize total Profit of plants over all allocations. Go ahead and Run model from the top-right corner.
Once your model has finished running, you can click on Explore solution in the left hand side, and then Solution tables. Click on
the icon next to the magnifying glass to view the solution table in full-screen mode.
Now, we can see the final solution here. We can see that for the highest cost plants, we are still restricting allocation. We are also prioritizing plants to have higher profit over ones that have lower profit.
Great job! You now know how to import scenarios into Decision Optimization.
For more complex scenarios, take a look at DO-samples on GitHub.
Congratulations! You've just finished running your first decision optimization experiment. You know understand how to setup a decision optimization problem, import data, set objectives and constraints, and then run the model.
You have also learned how to deploy the model, and where to find important model information such as the deployment ID and the space ID, which are needed to connect to the deployed model via API.
In the next part of the tutorial, we will look at how to interact with the model using a web-app.










































