This use case 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. The goal is to minimize the total cost while still ensuring that the demand is met.
In the previous tutorial, you used IBM SPSS® Modeler to build a model to predict demand. In this tutorial, you’ll use the demand as input as well as other information about the distribution plants such as production cost and capacity to reach the goal of minimizing overall cost.
In this tutorial, you explore the following key capabilities:
- How to build an optimization model
- A model builder that guides you through the typical optimization development steps
- Dashboards for communicating the optimization model results
The following prerequisites are required to follow the tutorial:
- An IBM® Cloud Account
- IBM Cloud Pak® for Data or IBM Watson Studio
- IBM Watson® Machine Learning Service
It should take you approximately 35 – 45 minutes to complete this tutorial.
Introduction to decision optimization
This section introduces decision optimization, which enables you to choose the optimal course of action from many input variables and their influence on the output. If you are familiar with decision optimization and optimization problems, you can skip to the steps. The Decision Optimization feature is available as part of IBM Watson Studio on IBM Cloud and IBM Watson Studio Premium for IBM Cloud Pak for Data, which supports multicloud environments.
How to use decision optimization to reach an optimal solution
There are five main steps to reaching an optimal decision. However, by using decision optimization, you are only concerned with the first two steps. You want to formulate the business problem as an optimization problem. That means that you must create data tables to represent your business problem.
What is an optimization problem?
An optimization problem is the problem of finding the best solution from all possible solutions. You do this by defining objectives, constraints, and decision variables.
What is an optimization model?
You must create an optimization model to ensure that your CPLEX optimization engine knows how to solve the correct problem. An optimization model defined in terms of:
- An objective, decision variables, and constraints
- An optimization engine to solve the model instance
- Data to create an instance of the model
What is an objective?
An objective is what you are trying to solve for. An example of this is maximizing profit or minimizing cost as is the case in this example.
What is a constraint?
A constraint is a condition that the problem must meet to reach an optimal solution. For this example, you are limited by the capacity of your distribution plants. The capacity (or the maximum number of units that a plant can produce) is the constraint in this example.
What is a decision variable?
A decision variable is a quantity that the decision maker controls. In this 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.
Optimization use cases
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
- Import intermediate scenario
Create Watson Studio service
Log in to your IBM Cloud account. The following demo shows you how to create an IBM Watson Studio service.
Log in to IBM Cloud, and click Proceed to show that you have read your data rights.
Click IBM Cloud in the upper-left corner to ensure that you are on the home page.
Within your IBM Cloud account, click the search bar to search for IBM Cloud services and offerings. Enter
Watson Studio, and then click Watson Studio under Catalog Results.
This takes you to the Watson Studio service page. Here, you can name the service. For example, you can name it Watson-Studio-trial. You can also choose which data center to create your instance in. The demo shows the one for this use case as being created in Dallas.
Choose the Lite service, which is free. This has limited compute but it is enough to understand the main functions of the service.
After you’re satisfied with your service name, location, and plan, click Create. This creates your Watson Studio instance.
Go to https://cloud.ibm.com/resources, and click your recently created Watson Studio service.
Click Get Started.
Create a project
After you click your Watson Studio service, you are taken to the IBM Cloud Pak for Data overview page. From there, click Projects.
You are taken to a page that shows your projects. Click New project.
Next, you are given the option to create a project from a file or an empty project. Click Create an empty project.
Click Add to add a storage service.
Name your resource, then click Create to the create IBM Cloud Object Storage.
After you return to your new project, your newly created IBM Cloud Object Storage should be detected automatically. Name the project, and click Create.
Create a Decision Optimization experiment
From your newly created project, click Add to project.
Select Decision Optimization experiment.
The Decision Optimization page opens. You’ll need a Watson Machine Learning service to work with Decision Optimization, so click Add service.
The Associate service page opens. Click New service unless you already have a Watson Machine Learning service.
Click Machine Learning.
The Machine Learning service page opens. Name the service, then click Create.
You are returned to the Associate service page. Now, your newly created Machine Learning service should appear. Click the box next to it, then click Associate service.
Create a deployment space
After you associate your service, you should be returned to the New Decision Optimization experiment page. Next, you’ll need to add a deployment space.
Click Create a deployment space if you do not have one.
Name the deployment space, and then click Create.
On your New Decision Optimization experiment page, your newly created deployment space should be populated. Click Create.
Clone the repo
In a terminal window, enter the following command to clone the repository for this solution so that you have all of the data files needed for the experiment.
git clone https://github.com/IBM/optimize-procurement-and-inventory-with-ai.git
Prepare the data
From the project overview page, click Assets from the top tab, then find your newly created Decision Optimization experiment, and click it.
You are taken to the Prepare data page of your experiment. Click browse in the upper right to add data.
Browse to where you cloned the repository and navigate to decision-optimization-case-study/tutorials/decision-optimization-tutorial/intro-scenario/data. Select plants.csv and customerDemand.csv, and click Open.
Prepare the model
From the Prepare data page, click Run model.
Click Use modeling assistant.
Choose Selection & Allocation to choose the domain of your problem.
Next, you’ll choose the decision variable. This is what the model is deciding. For this example, it’s the optimal number of items to be produced at a certain plant. Choose the plants table, then click Continue.
The first thing you must do after you prepared your problem statement is to add your objectives.
Delete the default objective.
maximize total plants allocationsin the Suggestions box. Click the plus sign (+) to add it to your model.
minimize total cost of plants over all allocationsin the Suggestions box. Add this to your model.
The default constraint for your problem is to synchronize selection with plant allocations. Expand this statement to define the maximum and minimum values.
Ensure that the max allocation of plants is defined by Capacity.
The min assignment of plants should be 0.
Move the slider next to Maximize total plant allocations to 10 to prioritize this objective.
All plant allocations must be integerin the Suggestions box. Add this to your model.
for each plant, allocation is less than or equal to Capacityin the Suggestions box. Add this to your model.
for each customerDemand, total allocation of plants (such that plants Product is customerDemand) is less than or equal to Demandin the Suggestions. Add this to your model.
Make sure that the objectives and constraints are the same as the following image, then click Run model.
Let’s look at the data. The primary goal with your optimization is to meet demand because you prioritized that objective by moving the slider to 10.
You know that demand is 100 for hand sanitizer and 120 for masks. You also know that there are two plants that have high cost (3). You want to limit allocating masks and hand sanitizer from those plants as much as possible.
To examine the solution, click the button next to the magnifying glass to open the table in a full screen.
You see that:
From the plant that produces masks with the highest cost of 3, there are 0 allocated.
From the plant that produces hand sanitizer with the highest cost of 3, there are 70 units allocated, which is below capacity of the plant.
All other plants are allocated all of their capacity, other than plant 2, which allocated 15 units to masks because you already produced enough for demand.
In summary, CPLEX allocated 100 units to the lowest-cost plants for creating hand sanitizer and 120 for masks. Therefore, demand was met at the lowest cost possible.
This step is optional. It’s only needed for web application connection. To deploy the model:
Return to your intro scenario by clicking the scenario on the top of the page. Click the three-dot icon, and then click Save for deployment.
Name the model, and click Save.
You should see a notification that the model was successfully saved.
Click View in project. If you missed the notification, click Projects/demo-sept29.
From your project, go to Models. You should see your newly saved model. Click the three-dot icon, and then click Promote.
The next page lets you pick which space to deploy to. Pick the one you created in step 4, and click Promote.
You should see a notification that successfully promoted your model to the deployment space. Click 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 Deploy.
This creates a deployment. Give it a name, select the hardware definition you want, then click Create.
Save your Deployment ID (Needed for API access)
After you’ve created the deployment, you should see the Deployment ID on the right side of the screen. Copy this. You need this for the web application environmental variables. After you’ve saved your Deployment ID, click your deployment space. In this example, it’s
Save your Space ID (Needed for API access)
After you’re in your deployment space, click Settings from the top of the page. There, you see your
Space ID. This is needed for the web application.
Import intermediate scenario
Next, let’s import a more complex scenario. Click Scenarios from the top tab.
From the Scenarios tab, click Create scenario and From file.
Navigate to where you cloned this repo, and then go to the decision-optimization-tutorial/data folder and select the intermediateScenario.zip file. Click Open.
Click Prepare data on the left to see the data that is being used for this scenario. You can see 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 you to determine which allocations will bring the largest profit.
Click Run model on the left. Here, you can see a new objective, Maximize total Profit of plants over all allocations. Click Run model.
After your model finishes running, click Explore solution on the left, then click Solution tables. Click the icon next to the magnifying glass to view the solution table in full-screen mode.
Here, you can see the final solution. You see that for the highest cost plants, you are still restricting allocation. You are also prioritizing plants that 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, look at DO-samples on GitHub.
You’ve just finished running your first Decision Optimization experiment. You now understand how to set up a decision optimization problem, import data, set objectives and constraints, and then run the model.
You also have 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 through an API.
In the next part of the solution, you’ll look at how to interact with the model using a web application.