作者: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. 通过缓存数据库结果提高PHP性能(转)

    众所周知,缓存数据库查询的结果可以显著缩短脚本执行时间,并最大限度地减少数据库服务器上的负载.如果要处理的数据基本上是静态的,则该技术将非常有效.这是因为对远程数据库的许多数据请求最终可以从本地缓存得 ...

  2. AttributeBehavior

    当事件触发的时候... 会循环所有behavior的events  为ower添加事件.....AttributeBehavior  为事件添加如下方法 public function evaluat ...

  3. UIDatePicker的时间选择器里的时区的问题

    转自:http://www.cocoachina.com/bbs/simple/?t70445.html 初始化代码: - (void)viewDidLoad { [super viewDidLoad ...

  4. 1043. Is It a Binary Search Tree (25)

    the problem is from pat,which website is http://pat.zju.edu.cn/contests/pat-a-practise/1043 and the ...

  5. 对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)--转

    出处:http://blog.csdn.net/xxd851116/archive/2009/06/25/4296866.aspx [前面的话] 在网上经常看到有人对request.getSessio ...

  6. 普通字符串与Hex编码字符串之间转换

    import java.io.UnsupportedEncodingException; import org.apache.commons.codec.binary.Hex; public clas ...

  7. E - 最短的名字

    Description 在一个奇怪的村子中,很多人的名字都很长,比如aaaaa, bbb and abababab. 名字这么长,叫全名显然起来很不方便.所以村民之间一般只叫名字的前缀.比如叫'aaa ...

  8. Python刷票小脚本——网络人气奖?不好意思,我要了

    零.前言 最近参加微软的kinect大赛,报名之后发现有一个网络投票,票数最多的项目可以得到网络人气奖. 这种事,必然是要搞一搞! 说干就干. 说明:由于本人过于懒惰,所以就不截图了,让大家失望了! ...

  9. Simple Arithmetics

    def Add(a, b): l = [] alen = len(a) blen = len(b) result = str(int(a) + int(b)) relen = len(result) ...

  10. github/hexo搭建个人博客几个问题总结

    问题一:hexo ERROR Deployer not found: github or hexo ERROR Deployer not found: git npm install hexo-dep ...