Why Python?¶
Introduces the Python API of CPLEX.
The Python application programming interface (API) of CPLEX supports the full functionality of CPLEX. Like other APIs, it enables a user to design models and solve problems in these disciplines:
linear programming (LP),
linear programming (LP),
mixed integer programming (MIP),
mixed integer programming (MIP),
quadratic programming (QP),
quadratic programming (QP),
quadratically constrained programming (QCP),
quadratically constrained programming (QCP),
second-order cone programming (SOCP),
second-order cone programming (SOCP),
mixed integer quadratic programming (MIQP),
mixed integer quadratic programming (MIQP),
mixed integer quadratically constrained programming (MIQCP).
mixed integer quadratically constrained programming (MIQCP).
Python itself is a freely available, open-source, cross-platform scripting language with a gentle learning curve. It enjoys a growing user-base in both industry and academia.
As a scripting language, it offers an easy approach for newcomers to CPLEX. For more experienced programmers, it promises good performance and ease of development in full-fledged optimization applications.
Python supports procedural, functional, and object-oriented coding paradigms. Because of its automatic memory management, Python applications do not require clean-up code, as C or C++ applications do. Thanks to its dynamic typing, Python applications do not need variable declarations, making Python applications easy to maintain or extend as modeling conditions change.
As an interpreted language, Python applications do not require the usual steps of compilation and linking like other APIs. In addition, many mature libraries supporting graphic user interfaces, database queries, visualization, statistical analysis, scientific computing, and so forth, are readily available for Python applications.
With those advantages of Python in general, you can use the Python API of CPLEX in a variety of ways. For example, you can use it to write scripts and applications that call CPLEX. Because of its interpreter, you can also use the Python API interactively. Like the Interactive Optimizer, the Python API of CPLEX supports important features of CPLEX, such as:
An alternative to the Interactive Optimizer, it offers features not available there, such as callbacks and programming loops. For an example of callback programming with the Python API, see Using callbacks in the Python API. For a sample programming loop, see Example: solving a sequence of related problems in the Python API