CVXPY is an open source Python-embedded modeling language for convex optimization problems. It lets you express your problem in a natural way that follows the math, which is quite flexible and efficient. This chapter introduces how to use the Cardinal Optimizer (COPT) in CVXPY.
Before calling COPT in CVXPY to solve problem, users need to setup CVXPY and COPT correctly. CVXPY currently supports Python 3.6 and later versions of Python. Users can download Python from Anaconda distribution or Python official distribution . We recommend users install the Anaconda distribution, because it is more user-friendly and convenient for Python novices.
Install via conda
We recommend that users who have installed the Anaconda distribution of Python
use its own
conda tool to install CVXPY. Execute the following commands in
Windows command prompt or terminal on Linux and MacOS:
conda install -c conda-forge cvxpy
Install via pip
Users can also install CVXPY through the standard
pip tool, execute the following
command in Windows command prompt or Linux and MacOS terminal:
pip install cvxpy
Setup CVXPY interface
The CVXPY interface of COPT is the Python file
copt_cvxpy.py in the COPT package,
and also depends on the Python interface of COPT. Suppose Python version is 3.7,
users should install the Python 3.7 version of COPT Python interface, see
Python Interface for detailed install guide.
After installing and configuring COPT, users only need to put the interface file
in the project directory and import the plugin:
from copt_cvxpy import *
In the solving function
solve, specify the solver to COPT to solve:
Introduction of features
The CVXPY interface of COPT supports Linear Programming (LP), Mixed Integer Programming (MIP), Quadratic Programming (QP) and Second-Order-Cone Programming (SOCP), common used parameters are:
CVXPY builtin parameter, which controls whether to display solving log to the screen. The default value is
False, which means no log to be displayed.
This option sets optimization parameters in the form of
key=value. Please refer to the chapter Parameters for currently supported parameters.