Optimize plant selection based on cost and capacity with Decision Optimization

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.

Learning objectives

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:

Estimated time

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.

Decision optimization

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 optimization

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.

Use cases


  1. Create Watson Studio service
  2. Create a project
  3. Create a Decision Optimization experiment
  4. Create a deployment space
  5. Clone the repo
  6. Prepare the data
  7. Prepare the model
  8. Add objectives
  9. Add constraints
  10. Explore solution
  11. Deploy model
  12. Import intermediate scenario

Create Watson Studio service

  1. Log in to your IBM Cloud account. The following demo shows you how to create an IBM Watson Studio service.

    Watson Studio

  2. Log in to IBM Cloud, and click Proceed to show that you have read your data rights.

  3. Click IBM Cloud in the upper-left corner to ensure that you are on the home page.

  4. 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.

  5. Choose the Lite service, which is free. This has limited compute but it is enough to understand the main functions of the service.

  6. After you’re satisfied with your service name, location, and plan, click Create. This creates your Watson Studio instance.

  7. Go to https://cloud.ibm.com/resources, and click your recently created Watson Studio service.

    Clicking Watson Studio service

  8. Click Get Started.

    getting started

Create a project

  1. After you click your Watson Studio service, you are taken to the IBM Cloud Pak for Data overview page. From there, click Projects.


  2. You are taken to a page that shows your projects. Click New project.

    New project

  3. Next, you are given the option to create a project from a file or an empty project. Click Create an empty project.

    Create empty project

  4. Click Add to add a storage service.

    Adding storage service

  5. Name your resource, then click Create to the create IBM Cloud Object Storage.

    Naming the resource

  6. After you return to your new project, your newly created IBM Cloud Object Storage should be detected automatically. Name the project, and click Create.

    Naming the project

Create a Decision Optimization experiment

  1. From your newly created project, click Add to project.

    Add to project

  2. Select Decision Optimization experiment.

    Machine learning service

  3. The Decision Optimization page opens. You’ll need a Watson Machine Learning service to work with Decision Optimization, so click Add service.

    Decision Optimization

  4. The Associate service page opens. Click New service unless you already have a Watson Machine Learning service.

    Associating service

  5. Click Machine Learning.

    Selecting machine learning

  6. The Machine Learning service page opens. Name the service, then click Create.

    Naming the service

  7. 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.

    Associating the 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.

  1. Click Create a deployment space if you do not have one.

    Create deployment space

  2. Name the deployment space, and then click Create.

    Name the space

  3. On your New Decision Optimization experiment page, your newly created deployment space should be populated. Click Create.

    Creating new experiment

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.ibm.com/Horea-Porutiu/decision-optimization-case-study.git

Prepare the data

  1. From the project overview page, click Assets from the top tab, then find your newly created Decision Optimization experiment, and click it.


  2. You are taken to the Prepare data page of your experiment. Click browse in the upper right to add data.


  3. 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.

    Adding files

  4. Click Import.

    Importing the data

Prepare the model

  1. From the Prepare data page, click Run model.

    Prepare data

  2. Click Use modeling assistant.

    Modeling assist

  3. Choose Selection & Allocation to choose the domain of your problem.

    Selecting allocations

  4. 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.

    Selecting plants Click continue Finish

Add objectives

The first thing you must do after you prepared your problem statement is to add your objectives.

  1. Delete the default objective.

  2. Enter maximize total plants allocations in the Suggestions box. Click the plus sign (+) to add it to your model.

  3. Enter minimize total cost of plants over all allocations in the Suggestions box. Add this to your model.


Add constraints

The default constraint for your problem is to synchronize selection with plant allocations. Expand this statement to define the maximum and minimum values.

  1. Ensure that the max allocation of plants is defined by Capacity.

  2. The min assignment of plants should be 0.

  3. Move the slider next to Maximize total plant allocations to 10 to prioritize this objective.

  4. Enter All plant allocations must be integer in the Suggestions box. Add this to your model.

  5. Enter for each plant, allocation is less than or equal to Capacity in the Suggestions box. Add this to your model.

  6. Enter for each customerDemand, total allocation of plants (such that plants Product is customerDemand) is less than or equal to Demand in the Suggestions. Add this to your model.


Explore solution

Make sure that the objectives and constraints are the same as the following image, then click Run model.

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.

    Plant allocation

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.

Deploy model

This step is optional. It’s only needed for web application connection. To deploy the model:

  1. 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.

    Save for deployment

  2. Name the model, and click Save.

    Naming the model

    You should see a notification that the model was successfully saved.

  3. Click View in project. If you missed the notification, click Projects/demo-sept29.

    Viewing notifications

  4. From your project, go to Models. You should see your newly saved model. Click the three-dot icon, and then click Promote.

    Viewing saved model

  5. The next page lets you pick which space to deploy to. Pick the one you created in step 4, and click Promote.

    Picking deployment space

  6. 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.

    Deployment space

  7. In your deployment space, you should see your model that you promoted. Click Deploy.

    Deploying model

  8. This creates a deployment. Give it a name, select the hardware definition you want, then click Create.

    Naming model

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 horea-deploy-demo.

Saving deployment ID

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.

Saving Space ID

Import intermediate scenario

  1. Next, let’s import a more complex scenario. Click Scenarios from the top tab.

    Going to scenarios

  2. From the Scenarios tab, click Create scenario and From file.

    Creating scenario

  3. 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.

    Opening scenario

  4. 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.

    Preparing data

  5. Click Run model on the left. Here, you can see a new objective, Maximize total Profit of plants over all allocations. Click Run model.

    Running the model

  6. 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.

    Exploring solution

  7. 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.

Importing scenarios

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.