Installing GLPK and GLPK-hs on Windows

As I want to try some LP (looking into a coursera-course) I tried to setup GLPK on Windows. (BTW: doing this in Linux is trivial: apt-get or you friendly packet-manager).

The goal was to get this simple skript:

import Control.Monad.LPMonad
import Data.LinearProgram
import Data.LinearProgram.GLPK

objFun :: LinFunc String Int
objFun = linCombination [(10, "x1"), (6, "x2"), (4, "x3")]

lp :: LP String Int
lp = execLPM $ do   
    setDirection Max
    setObjective objFun
    leqTo (varSum ["x1", "x2", "x3"]) 100
    leqTo (linCombination [(10, "x1"), (4, "x2"), (5, "x3")]) 600
    leqTo (linCombination [(2, "x1"), (2, "x2"), (6, "x3")]) 300
    varGeq "x1" 0
    varBds "x2" 0 50
    varGeq "x3" 0
    setVarKind "x1" IntVar
    setVarKind "x2" ContVar

main = print =<< glpSolveVars mipDefaults lp

running.

Well here are the steps that got me going:

  • Download and extract the executables
  • in the /w32 folder edit the Build_GLPK_with_VC10.bat file to update your installation folder for VS2010 (mine was under Programm files (x86))
  • run the batch-file and make sure you are in the right environment (I put it into programm files so I had to run the developers console from VS2010 tools as administrator!)
  • copy the build version of glpk dll and lib without it’s version (for example copy glpk_4_52.dll glpk.dll)
  • use cabal install with extra-libs and extra-sources like this:
cabal install glpk-hs --extra-lib-dirs="c:\Program Files (x86)\GNU\glpk\w32" --extra-include-dirs="c:\Program Files (x86)\GNU\glpk\src" 
  • now runhaskell example.hs should run and result in \( x_1 = 40 \), \( x_2 = 50 \) and \( x_3 = 0 \).