Install glpk under Ubuntu

Source: Internet
Author: User

However, in my computer. Install command for sudo apt-get install glpk-utils

Jostree Reprint Please specify the source http://www.cnblogs.com/jostree/p/4156204.html

GLPK is an open-source solution for linear programming packages.

Add Source:

Deb Http://us.archive.ubuntu.com/ubuntu Saucy main universe

Update the source and install:

sudo apt-get update

sudo apt-get install glpk

Write the following glpsolex.mod file

1/*Variables*/2var x1 >=0;3var x2 >=0;4var x3 >=0;56/*Object function*/7 Maximize z:x1 +14*X2 +6*x3; 8  9 /* constrains */< Span style= "color: #008080;" >10 s.t con1:x1 + x2 + x3 <= 4;11 s.t con2:x1 <= 2;3;3*x2 + x3 <= 6 14 15 end;        

Run glpsol-m glpsolex.mod-o glpsolex.sol, output to Glpsolex.sol file

The result is:

1Problem:glpsolex2 Rows:53 Columns:34 Non-zeros:105Status:optimal6 objective:z =32(MAXimum)78No. Row name St Activity Lower bound Upper bound marginal9------------------------------------------------------------------------101 Z B32112 Con1 NU442123 Con2 B02134 Con3 B33145 Con4 NU6641516No. Column name St Activity Lower bound Upper bound marginal------------------------------------------------------------------------181 X1 NL00-1192 X2 B10203 X3 B3021stkarush-kuhn-Tucker optimality Conditions:23KKT. PE:max.abs.err =0.00e+00 on row0Max.rel.err =0.00e+00 on row026High quality27KKT. PB:max.abs.err =4.44e-16 on row4Max.rel.err =1.11e-16 on row430High quality31 32 KKT.DE:max.abs.err = 0.00e+00 on column 033 Max.rel.err = 0.00e+00 on column 034  high Quality35 36 KKT. DB:max.abs.err = 0.00e+00 on row 037 Max.rel.err = 0.00e+00 on row 038  high Quality39 40 End of output               

An example of solving the eight queens in the Help document:

1/*QUEENS, a classic combinatorial optimization problem*/23/*Written in GNU MathProg by Andrew Makhorin <[email protected]>*/45/*The Queens problem is to place as many Queens as possible on the 8x86(or more generally, NXN) chess board in a-a-to-that they does not fight7Each of the other. This problem are probably as old as the chess game itself,8And thus its origin isn't known, but it's known that Gauss studied9This problem.*/10param n, Integer, >0,Default8;12/*Size of the chess board*/1314var x{1..N,1.. n}, binary;15/*X[I,J] = 1 means that a queen was placed in square [i,j]*/16S.T. A{iInch1..N}: Sum{jInch1..N} X[i,j] <=1;18/*At the most one queen can is placed in each row*/19S.T. b{jInch1..N}: Sum{iInch1..N} X[i,j] <=1;21st/*At the most one queen can is placed in each column*/22S.T. c{kInch2-n. N-2}: Sum{iInch1..N, JInch1..n:i-j = = k} X[i,j] <=1;24/*At the most one queen can is placed in each "\"-diagonal*/25S.T. d{kInch3..n+n-1}: Sum{iInch1..N, JInch1..n:i+j = = k} X[i,j] <=1;27/*At the most one queen can is placed in each "/"-diagonal*/28Maximize Obj:sum{iInch1..N, JInch1.. n} x[i,j];30/*Objective is to place as many queens as possible*/3132/*Solve the problem*/33Solve3435/*and print its optimal solution*/36for {iInch1.. N37 {for {J in 1..N} printf Span style= "color: #800000;" > "%s", if X[i,j] Then Span style= "color: #800000;" > "q" else  ".  "; \n" ); 39 }40 41 end;                 

Install glpk under Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.