GLPK的安装与使用

GLPK的安装与使用
http://blog.sciencenet.cn/home.php?mod=space&uid=3249403&do=blog&id=1019884
GLPK的安装与使用

GLPK(GNU Linear Programming Kit)

http://www.gnu.org/software/glpk/#TOCdocumentation

http://ftp.gnu.org/gnu/glpk/

 

GLPK是一个开源的求解线性规划问题的工具套件,这里简要的介绍一下GLKP在linux环境下的安装,并以一个简单的例子来介绍在C++中调用GLPK解决线性规划问题。

安装环境:

      OS:Ubuntu 16.04

      CPU:Intel i5-6200U

      Memory:DDR4 8G

      VM:YES

安装与配置:

      首先下载相应版本的GLPK,本人下载了4.60版本的套件。

      解压缩: tar -zxvf glpk-4.60.tar

      GLPK支持使用GMP来计算大数字以及高精度浮点,默认不适用,但是使用GMP的话效率更高,因此本人在配置时添加了对GMP的支持。进入解压安装文件目录,并配置:

./configure –with-gmp

      根据配置变异安装文件:

      make

      编译完成后可进行检查:

      makecheck

      然后就可以进行安装了,安装的默认路径是/usr/local/lib,因此需要取得管理员权限:       sudo make install

      等待一会即安装完成了,由于使用GLPK需要使用到其动态库,因此在安装完毕后需要更新动态库:

      ldconfig
GLPK的使用:

      在源文件中添加GLPK头文件即可:

      #include<glpk.h>

      编译时需要引用GLPK动态库:

      -lglpk

      注意事项:

GLPK并不是线程安全的!

             GLPK使用数组从下标1开始,而不从0开始。

      例子:

Windows 7上安装pulp和glpk步骤: 亲测环境: Windows 6.1.7601 Service Pack 1 Build 7601 x64 Python 2.7.11 PuLP 1.6.8 GLPK 4.34 安装步骤: 1、下载PuLP安装包:前提是,已安装python2.6以及2.6以上版本,在网页(https://pythonhosted.org/PuLP/main/installing_pulp_at_home.html)上点击PuLP zipfile下载pulp包,当然,也可以在我的资源里下载 2、安装PuLP:将zipfile解压缩,并在命令行窗口中,进入解压缩的目录,然后输入命令:setup.py install 3、下载glpk安装包:在网页(https://sourceforge.net/projects/gnuwin32/files/glpk/4.34/)上,下载glpk-4.34-setup.exe(也可以在我的资源里下载),然后双击默认安装 4、按照以上步骤,安装完以后,写一个.py的脚本并运行,脚本内容: from pulp import * pulp.pulpTestAll() 然后,会看到以下类似输出结果: D:\002-Task_150524\117-17data_thesis\004-code\testPulp.py Testing zero subtraction Testing inconsistant lp solution Testing continuous LP solution Testing maximize continuous LP solution Testing unbounded continuous LP solution Testing Long Names Testing repeated Names Testing zero constraint Testing zero objective Testing LpVariable (not LpAffineExpression) objective Testing Long lines in LP Testing LpAffineExpression divide Testing MIP solution Testing MIP solution with floats in objective Testing MIP relaxation Testing feasibility problem (no objective) Testing an infeasible problem Testing an integer infeasible problem Testing column based modelling Testing dual variables and slacks reporting Testing fractional constraints Testing elastic constraints (no change) Testing elastic constraints (freebound) Testing elastic constraints (penalty unchanged) Testing elastic constraints (penalty unbounded) * Solver pulp.solvers.PULP_CBC_CMD passed. Solver pulp.solvers.CPLEX_DLL unavailable Solver pulp.solvers.CPLEX_CMD unavailable Solver pulp.solvers.CPLEX_PY unavailable Solver pulp.solvers.COIN_CMD unavailable Solver pulp.solvers.COINMP_DLL unavailable Testing zero subtraction Testing inconsistant lp solution Testing continuous LP solution Testing maximize continuous LP solution Testing unbounded continuous LP solution Testing Long Names Testing repeated Names Testing zero constraint Testing zero objective Testing LpVariable (not LpAffineExpression) objective Testing LpAffineExpression divide Testing MIP solution Testing MIP solution with floats in objective Testing MIP relaxation Testing feasibility problem (no objective) Testing an infeasible problem Testing an integer infeasible problem Testing column based modelling Testing fractional constraints Testing elastic constraints (no change) Testing elastic constraints (freebound) Testing elastic constraints (penalty unchanged) Testing elastic constraints (penalty unbounded) * Solver pulp.solvers.GLPK_CMD passed. Solver pulp.solvers.XPRESS unavailable Solver pulp.solvers.GUROBI unavailable Solver pulp.solvers.GUROBI_CMD unavailable Solver pulp.solvers.PYGLPK unavailable Solver pulp.solvers.YAPOSIB unavailable 表示已经成功安装pulp和glpk
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值