GLPK 安装配置与使用

一、背景

这学期选修了卜东波老师的“计算机算法设计与分析”,Linear Programmin 部分的作业要求用GLPK求解,于是开始摸索GLPK的 安装与使用。

二、GLPK安装配置

  1. GLPK 简介
    GLPK全程GNU Linear Programming Kits,是GNU opensource 的用于解线性规划的项目。网上大多数配置教程都是教如何在Linux平台上安装配置,比较少介绍Windows平台的安装配置,本博文主要介绍自己在Windows平台上进行安装配置的过程。

  2. Windows 环境下GLPK的安装配置

    • 下载网址:http://ftp.gnu.org/gnu/glpk/
      下载GLPK包,我下载的是“glpk-4.60.tar.gz”,下的“glpk-4.60.tar.gz.sig”没用到(估计是Linux上安装需要的文件)
    • 安装细节:http://www.cnblogs.com/jecyhw/p/4978956.html
      将下载的“glpk-4.60.tar.gz”包解压,修改两个文件
      Build_GLPK_with_VC10.bat
      Build_GLPK_with_VC10_DLL.bat
      然后,依次运行两个文件,安装成功后,glpk下的w64/w
      32(取决于你的操作系统)目录下会有glpk.lib和glpsol.exe这两个文件

三、GPLK在Windows上的使用

在Windows上安装配置好后如何使用呢?答案是通过cmd进行使用。由于本人很少在windows上使用cmd DOS窗口操作,所以着实折腾了一下。
1、首先,在DOS窗口下,要进入你安装的GLPK的目录下的w32或w64目录下,其中要特别注意windows文件目录转移命令格式
我的是32位系统,目录是“D:\Program Files\GLPK\glpk-4.60\w32”,具体指令如下:
 windows文件目录转移命令

2、进入glpsol.exe所在的文件后,就可以使用它了,指令如下:
glpsol -m test.mod -o test.sol
test.mod 是写好的带求解的文件
test.sol 是生成的结果文件
测试过程使用了http://blog.csdn.net/icodingbird/article/details/53054001的例子
这里写图片描述

That’s all!!!
参考:

http://www.cnblogs.com/jecyhw/p/4978956.html
http://blog.csdn.net/icodingbird/article/details/53054001

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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值