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自动下载.这里不推荐第二种方法安装,因为这种方法安装会像天女散花一样把安装的文件散落在系统的 ...
随机推荐
- [Javascript] Either Functor
Either Functor: // API Right(val) // resolve the value Left(val) // return error message Examples: m ...
- Android 实现书籍翻页效果----完结篇
By 何明桂(http://blog.csdn.net/hmg25) 转载请注明出处 之前由于种种琐事,暂停了这个翻页效果的实现,终于在这周末完成了大部分功能,但是这里只是给出了一个基本的雏形,没有添 ...
- 使用proguard混淆android代码
当前是有些工具比方apktool,dextojar等是能够对我们android安装包进行反编译,获得源代码的.为了降低被别人破解,导致源代码泄露,程序被别人盗代替码,等等.我们须要对代码进行混淆,an ...
- android144 360 快捷方式
package com.example; import android.net.Uri; import android.os.Bundle; import android.app.Activity; ...
- win7家庭版任务栏预览消失,只显文字终极解决法
出现问题:win7家庭基础版,任务栏的预览窗口没有了,只有文字: Likethis: 工具/原料 services.msc 方法/步骤 网上的解决办法都试了,不管用,先把网上的方法列举出来如下 ...
- YAR 并行RPC框架研究
前几天,部门召开了PHP技术峰会 学习会议,大家分别对这次会议的PPT 做了简单的介绍, 其中提到了 鸟哥[惠新辰]的一篇PPT<微博LAMP 演变>,如果谁有需要可以去谷歌搜,或者去 h ...
- Android(java)学习笔记94:关于广播接收者的注册和使用心得
下面我们先看一部分代码,由代码进行进一步的深入: registerReceiver( new BroadcastReceiver() {//onReceive中代码的执行时间不要超过5s,androi ...
- [辛酸历程]在Mac中使用Python获取屏幕截图
一.起因 最近想做个小外挂玩玩,技术倒是不难,就是通过图片匹配加上一些判断方法来刷分.但是在最不起眼(却最容易出问题)的准备阶段卡住了. 为什么卡住了呢,简单说,因为我需要获取截屏的数据,所以就要找一 ...
- jquery中ajax向action传递对象参数,json ,spring注入对象
首先,我这个程序的框架是spring+struts2+hibernate. 后端的action的需要接受从前端传进来的参数,由spring的注入,可知,如果前端用的是form的话,只需要在每个inpu ...
- Linux文件与目录管理之ls的使用
来源:鸟哥的私房菜 查看文件与目录 ls ls [-aAdfFhilnrRSt] 目录名 ls [--color={never,auto,always}] ls [--full-time] 目录名 选 ...