Centos7安装Bonmin求解器

Bonmin

  Bonmin (Basic Open-source Nonlinear Mixed INteger programming) is an
open-source code for solving general MINLP (Mixed Integer NonLinear
Programming) problems.
It builds on top of Cbc
and Ipopt.

It is a COIN-OR project and licensed under the
EPL (Eclipse Public License). The EPL is a license approved by the OSI (Open Source
Initiative), thus Bonmin is OSI Certified Open Source Software.

This project was initiated in 2004 by IBM and Carnegie Mellon University
as part of a joint effort to study algorithm for MINLP.
You may find additional informations at http://egon.cheme.cmu.edu/ibm/page.htm,
in particular

  • A publicly available library of test instances of Convex MINLPs,
  • Research papers on new algorithmic procedures for MINLP.

Bonmin features several algorithms, including

  • B-BB is a NLP-based branch-and-bound algorithm,
  • B-OA is an outer-approximation decomposition algorithm,
  • B-QG is an implementation of Quesada and Grossmann’s branch-and-cut algorithm,
  • B-Hyb is a hybrid outer-approximation based branch-and-cut algorithm.

英文水平有限,就不做翻译了。

Github地址

github-bonmin

Bonmin下载地址

下载地址

安装相关软件

  1.   由于bonmin是C++语言开发,所以在安装编译过程中需要安装C++编译器
    yum install gcc gcc-c++
  1.   在安装bomin过程中需要使用到patch修补文件,所以需要安装patch
    yum install patch

安装Bonmin

  1. 下载Bonmin
#我安装的是1.8.7
wget https://www.coin-or.org/download/source/Bonmin/Bonmin-1.8.7.tgz
  1. 解压缩
tar -zxvf Bonmin-1.8.7.tgz 
  1. 获取第三方依赖包
cd Bonmin-1.8.7
cd ThirdParty/ASL
#如果不执行安装patch 此处会报错,找不到patch命令
./get.ASL
cd ../Blas
./get.Blas
cd ../Lapack
./get.Lapack
cd ../Mumps
./get.Mumps
  1. 安装前配置
#在Bonmin根目录执行
mkdir build
cd build
../configure -C
  1. 编译安装
make
make install
  1. 测试
make test

如果安装成功,执行上一步命令会出现下图结果
在这里插入图片描述

Python代码测试

   算法工程师提供了测试代码如下

# encoding=utf-8
import numpy as np
import pandas as pd
from pyomo.environ import *
import pyutilib.subprocess.GlobalData
pyutilib.subprocess.GlobalData.DEFINE_SIGNAL_HANDLERS_DEFAULT = False

def object_func(model):
    return sum(model.x[i]*model.y[i] for i in range(10))

def constraint_01(model):
    return sum(model.x[i] for i in range(10)) * sum(model.y[i] for i in range(10)) <= 200

model = ConcreteModel(name="cplex_test")
model.x = Var([i for i in range(10)],bounds=(1,5),within=NonNegativeReals,initialize=1)
model.y = Var([i for i in range(10)],bounds=(1,5),within=NonNegativeReals,initialize=1)
model.z = Var([i for i in range(10)],bounds=(1,25),within=NonNegativeReals,initialize=1)
model.cons = ConstraintList()
model.cons.add(constraint_01(model))
model.obj = Objective(rule=object_func, sense=maximize)

solver_path = '/usr/local/algorithm/bonmin/Bonmin-1.8.7/build/bin/bonmin'
opt = SolverFactory('bonmin', executable=solver_path)

results = opt.solve(model, tee=True)
results.write()
model_x = np.array(list(model.x.get_values().values()))
model_y = np.array(list(model.y.get_values().values()))
print(model_x)
print(model_y)
print(model.obj())

   将代码中solver_path的路径改成Bonmin安装编译后可执行文件bonmin的路径即可,如果测试成功如下图所示:
在这里插入图片描述

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐