*关于安装*
linux上比较容易(才不,更新源找到正确安装包名字什么的花了好久orz)。Windows是非常简单的!win10亲测可行!
下载:http://www.gnu.org/software/glpk/glpk.html
选择版本:glpk-4.57.tar.gz
修改Build_GLPK_with_VC10.bat和Build_GLPK_with_VC10_DLL.bat两个文件中你VS安装的绝对路径。32位的系统选择w32,64位的系统选择w64,然后做修改,写本机VS的绝对路径。
打开你的cmd,到D盘(我的在D)glpk-4.57/w64
Build_GLPK_with_VC10.bat
Build_GLPK_with_VC10_DLL.bat
用glpsol –version查看检查是不是成功
**安装完成后***
把写好的.mod文件放在D:\glpk-4.57\w64里
执行glpsol -m test.mod -o test.sol
执行结果在\w64里的test.sol中,记事本打开就可以看到啦
关于例子:
/* Variables */
var x1 >= 0;
var x2 >= 0;
var x3 >= 0;
/* Object function */
maximize z: 3*x1 + x2 +2*x3;
/* Constrains */
s.t. con1: x1 + x2 + 3*x3 <= 30;
s.t. con2: 2*x1 +2*x2 + 5*x3 <= 24;
s.t. con3: 4*x1 + x2 + 2*x3 <= 36;
end;
Problem: test
Rows: 4
Columns: 3
Non-zeros: 12
Status: OPTIMAL
Objective: z = 28 (MAXimum)
No. Row name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- ------------- -------------
1 z B 28
2 con1 B 12 30
3 con2 NU 24 24 0.166667
4 con3 NU 36 36 0.666667
No. Column name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- ------------- -------------
1 x1 B 8 0
2 x2 B 4 0
3 x3 NL 0 0 -0.166667
Karush-Kuhn-Tucker optimality conditions:
KKT.PE: max.abs.err = 0.00e+000 on row 0
max.rel.err = 0.00e+000 on row 0
High quality
KKT.PB: max.abs.err = 0.00e+000 on row 0
max.rel.err = 0.00e+000 on row 0
High quality
KKT.DE: max.abs.err = 0.00e+000 on column 0
max.rel.err = 0.00e+000 on column 0
High quality
KKT.DB: max.abs.err = 0.00e+000 on row 0
max.rel.err = 0.00e+000 on row 0
High quality
End of output
复杂一点的例子,比如求和式,可以参考:http://blog.csdn.net/yxf/article/details/1595058
更复杂的话,可以查阅MathProg语法相关,就搞定啦!
参考:http://www.cnblogs.com/Iambda/archive/2012/12/12/3933510.html
http://blog.csdn.net/xuqingict/article/details/24366901
http://wenku.baidu.com/link?url=pbqlgeEJLB7Xd6h1HDW04d8tm7CXAHWyGzFeY0jI9Iq5TxU0h2xyU854FYWfJoJaj3pEnUm3obdtKRGt6mLrj1C9CN8Sdpi_rMWodA1Nk_G