文章目录
安装
- 环境: ubuntu 21.04 + python 3.9.5(其实对于这个而言的话ubuntu / windows 以及 python的版本应该是不会对结果造成任何影响的)
整个求解是基于Python的pyomo建模平台的,因此首先先安装pyomo,然后在基于pyomo使用开源的ipopt进行求解
安装 pyomo 和 ipopt
!pip install pyomo # 安装 pyomo
# Download ipopt-linux64
!wget "https://ampl.com/dl/open/ipopt/ipopt-linux64.zip"
!unzip ipopt-linux64.zip # 解压后得到 ipopt 文件夹,里面有 ipopt 执行文件
建模和求解
以最基础的一个非线性求解问题来看
m i n f ( x ) = x 1 2 + x 2 2 s . t . − x 1 2 + x 2 < = 0 x 1 + x 2 = 2 \begin{aligned} min \quad &f(x) = x_1^2 + x_2^2 \\ s.t. \quad &-x_1^2 + x_2 <=0 \\ & x_1 + x_2 = 2 \end{aligned}