Decision Optimization notebooks
You can create and run Decision Optimization models in Python notebooks by using DOcplex, a native Python API for Decision Optimization. Several Decision Optimization notebooks are already available for you to use.
Python 3.11 and 3.10
(deprecated)
. Decision Optimization (DOcplex) is available in the following runtimes: Runtime 24.1 on Python 3.11
withCPLEX 22.1.1.0
Runtime 23.1 on Python 3.10 (deprecated)
withCPLEX 20.1.0.1
The Decision Optimization service includes the full CPLEX commercial edition. If you do not install Decision Optimization, you have access only to the Community Edition of the CPLEX engines. The Community Edition is limited to solving problems with up to 1000 constraints and 1000 variables, or with a search space of 1000 X 1000 for Constraint Programming problems.
- The Sudoku example, a Constraint Programming example in which the objective is to solve a 9x9 Sudoku grid.
- The Balance production of pasta example. This Linear Programming example has the objective to minimize the production cost for some pasta products and to ensure that the customers' demand for the products is satisfied.
All Decision Optimization notebooks use DOcplex.
DOcplex
The Decision Optimization notebooks use DOcplex, a native Python API for modeling and solving Decision Optimization problems. The API is available by default as part of the Python environment.
- Mathematical Programming Modeling for Python that uses
docplex.mp
- Constraint Programming Modeling for Python that uses
docplex.cp
from docplex.mp.model import Model
The API is licensed under the Apache license V2.0 and is numpy/pandas
friendly.
You can read the full DOcplex API documentation on rawgit. You can find DOcplex examples on the Decision Optimization GitHub.
Decision Optimization client API
In addition to DOcplex, a Decision Optimization client API is available for you to create scenarios and handle models that are made in the Decision Optimization experiment UI. For example, see Generating multiple Decision Optimization scenarios.
See the Decision Optimization client API documentation. You can also find the previous example in the jupyter folder of the DO-samples.
Running Decision Optimization notebooks
Download a notebook from the jupyter folder of the DO-samples and run it as follows.
- Select the Assets tab.
- Select New asset > Work with data and models in Python or R in the Work with models section.
- Choose From file. Then, click Drag and drop files here or upload, and browse to the notebook on your computer.
- Click Create Notebook. The notebook is added to your project.
If you do not have a project in Cloud Pak for Data
- Create a new project: select Projects > View all Projects from the menu and click the New Project button.
- Select Create an empty project and in the window that opens enter a name and click Create.
- Select the Assets tab.
- Select New asset > Work with data and models in Python or R in the Work with models section.
- Choose From File. Then, click Drag and drop files here or upload, and browse to the notebook on your computer.
- Click Create Notebook. The notebook is added to your project.
The Decision Optimization service includes the full CPLEX commercial edition. If you do not install Decision Optimization, you have access only to the Community Edition of the CPLEX engines. The Community Edition is limited to solving problems with up to 1000 constraints and 1000 variables, or with a search space of 1000 X 1000 for Constraint Programming problems.
To run your notebook, click Cell > Run All.
Example Python notebooks are provided in the Decision Optimization GitHub. To use these examples, see Jupyter notebook samples. These examples do not use the experiment UI.
Also, a Python notebook that shows you how to generate multiple scenarios by using randomized data is provided in the jupyter folder of the DO-samples. This approach can be useful to test a model made in the experiment UI with different data sets. For more information, see Generating multiple scenarios.
Decision Optimization tutorials
You can find more DOcplex examples that introduce you to the DOcplex Python API on the Decision Optimization GitHub:
- Linear Programming
- You can read a detailed description of this notebook in this Linear Programming (CPLEX Part 1) tutorial. You can clone or download this Decision Optimization Linear Programming notebook from Github.
- Beyond Linear Programming
- You can read a detailed description of this notebook in this Linear Programming (CPLEX Part 2) tutorial. You can clone or download this Decision Optimization Beyond Linear Programming notebook from Github.
- Getting started with Scheduling in CPLEX for Python
- You can read a detailed description of this notebook in this Scheduling in CPLEX for Python tutorial. You can clone or download this Getting started with Scheduling in CPLEX for Python notebook from Github.