Ubuntu 下 glpk 的安装及使用
作者: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 的安装及使用的更多相关文章
- Ubuntu下git的安装与使用
Ubuntu下git的安装与使用 Ubuntu下git的安装与使用与Windows下的大致相同,只不过个人感觉在Ubuntu下使用git更方便. 首先,确认你的系统是否已安装git,可以通过git指令 ...
- Ubuntu下Speedtest的安装
要安装Speedtest,需要先安装apache,参见<Ubuntu下Apache的安装>一文:*(再安装LAMP server,参见<Ubuntu下快速安装LAMP server& ...
- Ubuntu下Apache的安装
Ubuntu下可快速安装LAMP server(Apache+MySQL+PHP5),参见<Ubuntu下快速安装LAMP server>一文. 也可以手动安装Apache.本文介绍如何手 ...
- Linux(Ubuntu)下MySQL的安装与配置
转自:http://www.2cto.com/database/201401/273423.html 在Linux下MySQL的安装,我一直觉得挺麻烦的,因为之前安装时就是由于复杂的配置导致有点晕.今 ...
- ubuntu下的openfire安装、配置、运行
openfire服务器 Openfire 采用Java开发,开源的实时协作(RTC)服务器基于XMPP(Jabber)协议.您可以使用它轻易的构建高效率的即时通信服务器.Op ...
- ubuntu下boost编译安装
ubuntu下boost编译安装 boost 安装 1.依赖安装 apt-get install mpi-default-dev libicu-dev python-dev python3-dev l ...
- 2010-01-20 12:09 ubuntu下minicom的安装及使用
转http://hi.baidu.com/npugtawqdnbgqrq/item/106f805409b42813db163527 ubuntu下minicom的安装及使用 安装: sudo apt ...
- ubuntu 下redis的安装简介
Linux公社:https://www.linuxidc.com/topicnews.aspx?page=2&tid=2 简单介绍下ubuntu下redis的安装方式: 第一种: 1:进入re ...
- ubuntu下tomcat的安装及注册成系统服务
在ubuntu下tomcat的安装有两种方式,第一种是下载二进制文件,解压安装:第二种则是使用apt-get自动下载.这里不推荐第二种方法安装,因为这种方法安装会像天女散花一样把安装的文件散落在系统的 ...
随机推荐
- iOS开发——网络编程Swift篇&(一)网络监测
网络监测 enum ReachabilityType { case WWAN, WiFi, NotConnected } public class Reachability { /** :see: O ...
- 关于dispatchTouchEvent, onInterceptTouchEvent, onTouchEvent的分发机制浅析
虽说这个问题不是很难...动动手就能看出答案...但是似乎不太容易理解...几次尝试把这个问题说明白....但是好像感觉说不明白....(顿时想起了那句话----说不明白就是自己还不明白! 我怎么可能 ...
- win7关机命令
通过 DOS 命令 “shutdown” 来实现 Windows7 系统下的定时关机功能. 使用at 命令 at 12:00 shutdown -s,取消:at/delete shutdown -s ...
- Spark之路 --- Scala用JFreeChart画图表实例
JFreeChart介绍 JFreeChart是JAVA平台上的一个开放的图表绘制类库.它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用 ...
- SpringMVC的简单示例
首先导入所需的jar包,项目目录结构如下: 之后需要配置一下web.xml文件,内容如下: <?xml version="1.0" encoding="UTF-8& ...
- 用CCRenderTexture和BlendFunc制作游戏教学时使用的黑色覆盖层
游戏快要完成了,准备做教学. 我们的教学是在整个界面上盖一层灰色图片,然后把提示点击的按钮部分亮出来,也就是在一块黑色图片上,按需求扣空一小部分.如图,把武器部分扣空,那么在其它地方又会扣空其它部分, ...
- Android(java)学习笔记82:我们到底该如何处理异常?
我们到底该如何处理异常? 原则: 如果该功能内部可以将问题处理,用try,自己能解决就自己解决问题. 如果处理不了,交由调用者处理,这是用throws,自己不能解决的问题,我们就抛出去交个调用者解决这 ...
- [转]HTML accesskey 属性
本文转自:http://www.dreamdu.com/xhtml/attribute_accesskey/ 17.2. HTML accesskey 属性 accesskey 属性 -- 代表链 ...
- [未完成]关于CSS的总结
CSS和html 数据和样式分离,在java中称为降低了耦合性. css和html相结合的第一种方式. 1,每一个html标签中都有一个style样式属性.该属性的值就是css代码. 2,使用styl ...
- Unity3D除了在编辑器里,怎么用代码给一个Texture类型的变量赋值
resource.load上来一张贴图就行. using UnityEngine; using System.Collections; public class example : MonoBehav ...