Step 1: Installing hmatrix
The package hmatrix-glpk relies on hmatrix, so it's best to install and test that first. Instructions on installing hmatrix on Windows have been provided by the author of the package. When following these instructions, it is important to pay attention to line 32:"It may be necessary to put the dlls in the search path."It is certainly necessary to add the DLLs to the search path. If you extracted the files to, e.g., "c:\lib\gls", then make you sure you add that directory to your PATH environment variable.
Step 2: Getting glpk
Since hmatrix-glpk is a binding for glpk, we need to find the right binaries and header files.- First, create a directory $GLPK (e.g., "c:\lib\glpk") on your computer.
- Download glpk-4.34-lib.zip from the GnuWin SourceForge project. From this archive, extract "include/glpk.h" and copy this header file to the $GLPK directory created in the first step.
- Download winglpk-4.46.zip from the GLPK for Windows SourceForge project. From this archive, extract "glpk-4.46/w32/glpk_4_46.dll" and copy this file to "$GLPK/glpk.dll".
- Double-check: Your $GLPK directory should now contain two files, glpk.dll and glpk.h.
- Add $GLPK to your PATH environment variable.
Note: The GnuWin project also has glpk binaries, but on my machine, GHC couldn't load them.
Step 3: Installing hmatrix-glpk
Installing hmatrix-glpk is now easy. Just open an MSYS shell and enter:$ cabal install hmatrix-glpk --extra-lib-dir=$GLPK \ --extra-include-dir=$GLPK
This should fetch the package from Hackage and install it.
Step 4: A simple test
Fire up ghci and try solving a simple problem:ghci> import Numeric.LinearProgramming ghci> let prob = Maximize [4, -3, 2] ghci> let constr = Sparse [[2#1, 1#2] :<=: 10, [1#2, 5#3] :<=: 20] ghci> simplex prob constr [] Optimal (28.0,[5.0,0.0,4.0])
No comments:
Post a Comment