# 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

## Prerequisites

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.

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

## Steps

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

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.

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

8. Click Get 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.

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

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

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.

### Create a Decision Optimization experiment

2. Select Decision Optimization experiment.

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

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

5. Click Machine Learning.

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

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.

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

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

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

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

2. Browse to where you cloned the repository and navigate to optimize-procurement-and-inventory-with-ai/tutorials/decision-optimization-tutorial/data. Select plants.csv and customerDemand.csv, and click Open.

3. Click Import.

### Prepare the model

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

2. Click Use modeling assistant.

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

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, Continue, and Finish.

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 allocation over all plants` in the Suggestions box. Click the plus sign (+) to add it to your model.

3. Enter `minimize total cost of plants` in the Suggestions box and add `Minimize total cost of plants over all allocations` 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.

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 allocation over all plants 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 plants, 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.

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 on Solution tables (1).

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.

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

2. Name the model, and click Save.

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

3. Click View in project. If you missed the notification, click Projects in the breadcrumb and select your project.

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

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

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.

7. In your deployment space, you should see your model that you promoted. Hover over your model to expose the action icons. Click the Deploy icon.

8. 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 `Decision Optimization deployment space`.

#### Save your Space GUID (Needed for API access)

After you’re in your deployment space, click Manage from the top of the page. There, you see your `Space GUID`. This is needed for the web application.

### Import intermediate scenario

Next, let’s import a more complex scenario.

1. Go back to your Project > Assets and select your Decision Optimization experiment.

2. Select Overview in the left sidebar.

3. Click Create scenario and From file.

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

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

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

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

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

### Conclusion

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

Legend