Ubuntu18.04配置Ipopt,CppAD 通过C++求解最优控制

安装Ipopt

在一个目录下执行新建文件 install_ipopt.sh

touch install_ipopt.sh

文件中放入如下的内容:

# Pass the Ipopt source directory as the first argument
if [ -z $1 ]
then
    echo "Specifiy the location of the Ipopt source directory in the first argument."
    exit
fi
cd $1

prefix=/usr/local
srcdir=$PWD

echo "Building Ipopt from ${srcdir}"
echo "Saving headers and libraries to ${prefix}"

# BLAS
cd $srcdir/ThirdParty/Blas
./get.Blas
mkdir -p build && cd build
../configure --prefix=$prefix --disable-shared --with-pic
make install

# Lapack
cd $srcdir/ThirdParty/Lapack
./get.Lapack
mkdir -p build && cd build
../configure --prefix=$prefix --disable-shared --with-pic \
    --with-blas="$prefix/lib/libcoinblas.a -lgfortran"
make install

# ASL
cd $srcdir/ThirdParty/ASL
./get.ASL

# MUMPS
cd $srcdir/ThirdParty/Mumps
./get.Mumps

# build everything
cd $srcdir
./configure --prefix=$prefix coin_skip_warn_cxxflags=yes \
    --with-blas="$prefix/lib/libcoinblas.a -lgfortran" \
    --with-lapack=$prefix/lib/libcoinlapack.a
make
make test
make -j1 install

给文件可执行权限

sudo chmod +x install_ipopt.sh

依次执行如下命令:

sudo apt-get install gfortran
sudo apt-get install unzip
wget https://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.7.zip && unzip Ipopt-3.12.7.zip && rm Ipopt-3.12.7.zip
sudo ./install_ipopt.sh Ipopt-3.12.7

备注:Ipopt的版本可以自己指定,根据需要配置。

安装CppAD

sudo apt-get install cppad

编译成功后,运行程序出现以下错误:
error while loading shared libraries: libcoinmumps.so.1: cannot open shared
对于这个错误,是因为系统是64位的,但是程序用到的某个32版本的库。运行以下命令就解决了。

sudo apt-get update
sudo apt-get install lib32z1

你可能感兴趣的:(Linux系统)