Download:
Http://www.dcc.fc.up.pt /~ JPP/code/Python-glpk/
Installation:
Http://en.wikibooks.org/wiki/GLPK/Python
Google: Python glpk
Http://spokutta.wordpress.com/the-gnu-linear-programming-kit-glpk/
There are several interfaces for Python:
Python:
Python-glpk
(See also glpk's Wikipedia page
).
Pyglpk:
Pyglpk
Pymathprog:
Python mathprog (gmpl)
Java:
Glpk-Java
Is an interface for Java.
Yalmip:
Yalmip
Is a free MATLAB interface/MATLAB Modeling Environment for various solvers which can also access glpk using glpkmex.
Faster more interface can be found on glpk's Wikipedia page
.
Python development tools:
Http://www.builder.com.cn/2007/0915/507553.shtml
Swig Python
Http://www.swig.org/Doc1.3/Python.html
Just follow the steps of the makefile
Bottom to upper, build sequentially
========================================================== ========================================================== ========
Pyvers: = $ (shell pyversions-d)
Dir: = $ (shell basename 'pwd ')
ALL: _ glpkpi. So glpkpi. py
Glpkpi. py: glpkpi. I glpkpi. c glpkpi. h makefile
_ Glpkpi. So: glpkpi. py glpkpi. O glpkpi_wrap.o
Gcc-wall-shared glpkpi. O glpkpi_wrap.o-lm-lglpk-O _ glpkpi. So
Glpkpi. O: glpkpi. c
Gcc-wall-C-FPIC glpkpi. C-dhave_config_h-I d:/program files/python27
Glpkpi_wrap.o: glpkpi_wrap.c
Gcc-wall-C-FPIC glpkpi_wrap.c-dhave_config_h-I d:/program files/python27
Clean:
Rm-f *. O *~ *. PyC *. Pyo _ *. So glpkpi_wrap.c glpkpi. py
========================================================== ========================================================== ========
D:/tddownload/pros/_ eclipse workspace/python-glpk-0.4.43/swigwin-2.0.1> swig-PYT
Hon glpkpi. I
./Glpk. H (916): Warning 314: 'in' is a python keyword, renaming to '_ in'
Pydev cocould also finish that.
========================================================== ========================================================== ========
When "swig" or "GCC" shows up, just copy all the relevant files to the folders containing "swig.exe" or "gcc.exe ",
D:/TDDownload/pros/_ Eclipse Workspace/python-glpk-0.4.43/swigwin-2.0.1> swig-python glpkpi. I
D:/Program Files/MinGW/bin> gcc-Wall-c-fPIC glpkpi_wrap.c
Need to install MinGW and add D:/Program Files/MinGW/bin to the path environment variable
C. f.
Solve the "Unable to find vcvarsall. bat" error
1. success;
2. Add the MinGW path to the environment variable path. For example, if I install MinGW in D:/MinGW/, add D:/MinGW/bin to path;
3. Open the command line window and enter the directory of the Code to be installed in the command line window;
4. Run the following command to install the SDK.
Setup. py install build -- compiler = mingw32
========================================================== ========================================================== ========
Download GLPK
Edit Build_GLPK_with_VC9.bat as (c. f. http://glpk.blogspot.com /):
Bytes ----------------------------------------------------------------------------------------
Rem build glpk with Microsoft Visual Studio express 2008
Rem Note: Make sure that home variable specifies correct path
Set Home = "D:/program files/Microsoft Visual Studio 2005/VC"
Call % home %/bin/vcvars32.bat
Copy config_vc config. h
% Home %/bin/nmake.exe/F makefile_vc
% Home %/bin/nmake.exe/F makefile_vc check
Pause
Bytes ----------------------------------------------------------------------------------------
It shoshould be OK now (glpk. lib and glpsol.exe are obtained)
Bytes ----------------------------------------------------------------------------------------
./Glpsol.exe -- MPs.../examples/plan. MPs
Glpsol: glpk LP/MIP solver, v4.45
Parameter (s) specified in the command line:
-- Mps.../examples/plan. mps
Reading problem data from '.../examples/plan. mps '...
Problem: PLAN
Objective: VALUE
8 rows, 7 columns, 48 non-zeros
54 records were read
GLPK Simplex Optimizer, v4.45
8 rows, 7 columns, 48 non-zeros
Preprocessing...
7 rows, 7 columns, 41 non-zeros
Scaling...
A: min | aij | = 1.000e-002 max | aij | = 1.000e + 000 ratio = 1.000e + 002
GM: min | aij | = 2.534e-001 max | aij | = 3.946e + 000 ratio = 1.557e + 001
EQ: min | aij | = 6.422e-002 max | aij | = 1.000e + 000 ratio = 1.557e + 001
Constructing initial basis...
Size of triangular part = 7
0: obj = 6.500000000e + 002 infeas = 3.788e + 003 (0)
* 2: obj = 4.376770833e + 002 infeas = 0.000e + 000 (0)
* 10: obj = 2.962166065e + 002 infeas = 0.000e + 000 (0)
OPTIMAL SOLUTION FOUND
Time used: 0.0 secs
Memory used: 0.0 Mb (51150 bytes)
D:/TDDownload/pros/_ Eclipse Workspace/python-glpk-0.4.43/glpk-4.45/w32> pause
Bytes ----------------------------------------------------------------------------------------
Whenever there are path problems, simply change it to the absolute path...
Setup. py
========================================================== ========================================================== ============
# Directory containing libglpk
GLPK_LIB_DIR = 'd:/TDDownload/pros/_ Eclipse Workspace/python-glpk-0.4.43/glpk-4.45/lib'
# Directory containing glpk. h
GLPK_INC_DIR = 'd:/TDDownload/pros/_ Eclipse Workspace/python-glpk-0.4.43/glpk-4.45/include'
# Directory containing Python. h
D:/Program Files/Python27/include/Python. h
========================================================== ========================================================== ============
Install PLY
Setup. py -- help-commands
Standard commands:
Build everything needed to install
Build_py "build" pure Python modules (copy to build directory)
Build_ext build C/C ++ extensions (compile/link to build directory)
Build_clib build C/C ++ libraries used by Python extensions
Build_scripts "build" scripts (copy and fixup #! Line)
Clean up temporary files from 'build' command
Install everything from build directory
Install_lib install all Python modules (extensions and pure Python)
Install_headers install C/C ++ header files
Install_scripts install scripts (Python or otherwise)
Install_data install data files
Sdist create a source distribution (tarball, zip file, etc .)
Register the distribution with the Python package index
Bdist create a built (binary) distribution
Bdist_dumb create a "dumb" built distribution
Bdist_rpm create an RPM distribution
Bdist_wininst create an executable installer for MS Windows
Upload binary package to PyPI
Check perform some checks on the package
Usage: setup. py [global_opts] cmd1 [zookeeper opts] [cmd2 [ipv2_opts]...]
Or: setup. py -- Help [cmd1 cmd2...]
Or: setup. py -- Help-Commands
Or: setup. py cmd -- Help
Run Ply/setup. py install
========================================================== ========================================================== ============
Run src/setup. py install
Run test. py
Errro
Traceback (most recent call last ):
File "D:/tddownload/pros/_ eclipse workspace/python-glpk-0.4.43/examples/diet. py", line 1, in <module>
From glpk import *
File "D:/program files/python27/lib/Site-packages/glpk/_ init _. py", line 27, in <module>
From glpkpi import *
File "D:/program files/python27/lib/Site-packages/glpk/glpkpi. py", line 25, in <module>
_ Glpkpi = swig_import_helper ()
File "D:/program files/python27/lib/Site-packages/glpk/glpkpi. py", line 21, in swig_import_helper
_ Mod = imp. load_module ('_ glpkpi', FP, pathname, description)
Importerror: DLL load failed: the specified module cannot be found.
========================================================== ========================================================== ============
Make
_ Glpkpi. So: glpkpi. py glpkpi. O glpkpi_wrap.o
Gcc-wall-shared glpkpi. O glpkpi_wrap.o-lm-lglpk-O _ glpkpi. So
Make-K _ glpkpi. So
Gcc-wall-shared glpkpi. O glpkpi_wrap.o-lm-lglpk-O _ glpkpi. So
Process_begin: CreateProcess (null, pyversions-D,...) failed.
Process_begin: CreateProcess (null, basename 'pwd',...) failed.
D:/program files/mingw/bin /.. /lib/GCC/mingw32/4.5.2 /.. /.. /.. /.. /mingw32/bin/ld.exe: cannot find-lglpk
Collect2: LD returned 1 exit status
Make: *** [_ glpkpi. So] Error 1
Just copy the glpk. Lib file (c. f. http://glpk.blogspot.com/) to the following directory
D:/program files/mingw/bin/../lib/GCC/mingw32/4.5.2/.../mingw32/bin/ld.exe
D:/program files/mingw/bin
D:/program files/mingw/mingw32/bin
D:/program files/mingw/lib/GCC/mingw32/4.5.2
========================================================== ========================================================== ============
Make _ glpkpi. So
A lot of undefined reference
D:/program files/mingw/bin /.. /lib/GCC/mingw32/4.5.2/glpk. lib (.. /src/AMD/amd_2.obj ):(. text [_ glp_amd_2] + 0xb2): Undefined reference to '_ ftol2_sse'
Collect2: LD returned 1 exit status
Make: *** [_ glpkpi. So] Error 1
========================================================== ========================================================== ============
Build with mingw
Glpk 4.37/before
Rem build glpk with mingw
Rem Note: Make sure that home variable specifies correct path.
Set Home = "D:/program files/mingw"
Set Path = % home %/bin; % home %/libexec/GCC/mingw32/4.5.2; % PATH %
Copy config_mingw config. h
% Home %/ bin/mingw32-make.exe-F makefile_mingw
% Home %/bin/mingw32-make.exe-F makefile_mingw check
Pause
========================================================== ========================================================== ============