作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4156204.html

glpk是一个开源的求解线性规划的包。

添加源:

deb http://us.archive.ubuntu.com/ubuntu saucy main universe

更新源并安装:

sudo apt-get update

sudo apt-get install glpk

写入如下glpsolEx.mod 文件

 /* Variables */
var x1 >= ;
var x2 >= ;
var x3 >= ; /* Object function */
maximize z: x1 + *x2 + *x3; /* Constrains */
s.t. con1: x1 + x2 + x3 <= ;
s.t. con2: x1 <= ;
s.t. con3: x3 <= ;
s.t. con4: *x2 + x3 <= ; end;

运行 glpsol -m glpsolEx.mod -o glpsolEx.sol,输出到glpsolEx.sol文件中

结果为:

 Problem:    glpsolEx
Rows:
Columns:
Non-zeros:
Status: OPTIMAL
Objective: z = (MAXimum) No. Row name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- ------------- -------------
z B
con1 NU
con2 B
con3 B
con4 NU No. Column name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- ------------- -------------
x1 NL -
x2 B
x3 B Karush-Kuhn-Tucker optimality conditions: KKT.PE: max.abs.err = 0.00e+00 on row
max.rel.err = 0.00e+00 on row
High quality KKT.PB: max.abs.err = 4.44e-16 on row
max.rel.err = 1.11e-16 on row
High quality KKT.DE: max.abs.err = 0.00e+00 on column
max.rel.err = 0.00e+00 on column
High quality KKT.DB: max.abs.err = 0.00e+00 on row
max.rel.err = 0.00e+00 on row
High quality End of output

帮助文档中一个求解八皇后的例子:

 /* QUEENS, a classic combinatorial optimization problem */

 /* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */

 /* The Queens Problem is to place as many queens as possible on the 8x8
(or more generally, nxn) chess board in a way that they do not fight
each other. This problem is probably as old as the chess game itself,
and thus its origin is not known, but it is known that Gauss studied
this problem. */ param n, integer, > , default ;
/* size of the chess board */ var x{..n, ..n}, binary;
/* x[i,j] = 1 means that a queen is placed in square [i,j] */ s.t. a{i in ..n}: sum{j in ..n} x[i,j] <= ;
/* at most one queen can be placed in each row */ s.t. b{j in ..n}: sum{i in ..n} x[i,j] <= ;
/* at most one queen can be placed in each column */ s.t. c{k in -n..n-}: sum{i in ..n, j in ..n: i-j == k} x[i,j] <= ;
/* at most one queen can be placed in each "\"-diagonal */ s.t. d{k in ..n+n-}: sum{i in ..n, j in ..n: i+j == k} x[i,j] <= ;
/* at most one queen can be placed in each "/"-diagonal */ maximize obj: sum{i in ..n, j in ..n} x[i,j];
/* objective is to place as many queens as possible */ /* solve the problem */
solve; /* and print its optimal solution */
for {i in ..n}
{ for {j in ..n} printf " %s", if x[i,j] then "Q" else ".";
printf("\n");
} end;

Ubuntu 下 glpk 的安装及使用的更多相关文章

  1. Ubuntu下git的安装与使用

    Ubuntu下git的安装与使用 Ubuntu下git的安装与使用与Windows下的大致相同,只不过个人感觉在Ubuntu下使用git更方便. 首先,确认你的系统是否已安装git,可以通过git指令 ...

  2. Ubuntu下Speedtest的安装

    要安装Speedtest,需要先安装apache,参见<Ubuntu下Apache的安装>一文:*(再安装LAMP server,参见<Ubuntu下快速安装LAMP server& ...

  3. Ubuntu下Apache的安装

    Ubuntu下可快速安装LAMP server(Apache+MySQL+PHP5),参见<Ubuntu下快速安装LAMP server>一文. 也可以手动安装Apache.本文介绍如何手 ...

  4. Linux(Ubuntu)下MySQL的安装与配置

    转自:http://www.2cto.com/database/201401/273423.html 在Linux下MySQL的安装,我一直觉得挺麻烦的,因为之前安装时就是由于复杂的配置导致有点晕.今 ...

  5. ubuntu下的openfire安装、配置、运行

    openfire服务器              Openfire 采用Java开发,开源的实时协作(RTC)服务器基于XMPP(Jabber)协议.您可以使用它轻易的构建高效率的即时通信服务器.Op ...

  6. ubuntu下boost编译安装

    ubuntu下boost编译安装 boost 安装 1.依赖安装 apt-get install mpi-default-dev libicu-dev python-dev python3-dev l ...

  7. 2010-01-20 12:09 ubuntu下minicom的安装及使用

    转http://hi.baidu.com/npugtawqdnbgqrq/item/106f805409b42813db163527 ubuntu下minicom的安装及使用 安装: sudo apt ...

  8. ubuntu 下redis的安装简介

    Linux公社:https://www.linuxidc.com/topicnews.aspx?page=2&tid=2 简单介绍下ubuntu下redis的安装方式: 第一种: 1:进入re ...

  9. ubuntu下tomcat的安装及注册成系统服务

    在ubuntu下tomcat的安装有两种方式,第一种是下载二进制文件,解压安装:第二种则是使用apt-get自动下载.这里不推荐第二种方法安装,因为这种方法安装会像天女散花一样把安装的文件散落在系统的 ...

随机推荐

  1. 《赢在用户:Web人物角色创建和应用实践指南》阅读总结

           本书针对创建人物角色的每一个步骤,包括进行定性.定量的用户研究,生成人物角色分类,使人物角色真实可信等进行了十分详细的介绍.而且,在人物角色如何指导总体商业策略.确定信息架构.内容和设计 ...

  2. CentOS中查看系统资源占用情况的命令

    用 'top -i' 看看有多少进程处于 Running 状态,可能系统存在内存或 I/O 瓶颈,用 free 看看系统内存使用情况,swap 是否被占用很多,用 iostat 看看 I/O 负载情况 ...

  3. apache 配置order allow deny讲解

    http://www.111cn.net/phper/apache/43025.htm

  4. php使用技巧--之链接地址

    高效PHP程序必知的53个技巧 http://developer.51cto.com/art/201105/265953.htm 非常实用 十个PHP高级应用技巧 http://developer.5 ...

  5. c语言海量数据处理

    教你如何迅速秒杀掉:99%的海量数据处理面试题 http://wenku.baidu.com/view/4546d06ca45177232f60a276.html c语言如何对海量数据进行处理 PDF ...

  6. query插件之ajaxForm ajaxSubmit的理解用法

    如今ajax满天飞,作为重点的form自然也受到照顾. 其实,我们在平常使用Jquery异步提交表单,一般是在submit()中,使用$.ajax进行.比如:   $(function(){ $('# ...

  7. PHP.5-DIV+CSS布局网站首页实例

    DIV+CSS布局网站首页实例 网站页面布局 http://www.sj33.cn/digital/wyll/201501/42379.html[页头.页脚.侧边栏和内容区域] #避免各浏览器对CSS ...

  8. Python 替换字符串

    string类型是不可变的,因此不能采用直接赋值的方式.比如一个字符串 helloworld,想把o替换成z,那么只有先替换,然后再迭代. strings="helloworld" ...

  9. CSS skills: 6) auto hide the top bar javascript

    //jquery $(document).ready(function(){ $(window).scroll(function() { $(this).scrollTop() > 10 ? $ ...

  10. Android 自学之画廊视图(Gallery)功能和用法

    Gallery与之前讲的Spinner有共同的父类:AbsSpinner,表明Gallery和Spinner都是一个列表框.他们之间的区别在于Spinner显示的是一个垂直的列表框,而Gallery显 ...