Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Sunday, August 28, 2011

Installing hmatrix-glpk under Windows

Today I had some trouble trying to install hmatrix-glpk on my Windows machine, but I finally found a way. Here's how:

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.
  1. First, create a directory $GLPK (e.g., "c:\lib\glpk") on your computer.
  2. 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.
  3. 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".
  4. Double-check: Your $GLPK directory should now contain two files, glpk.dll and glpk.h.
  5. 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])



UPDATE 2011-09-01: Notes for compiling

I found out today that when you compile a Haskell program, the executable will actually look for glpk_4_46.dll instead of glpk.dll. It's not a pretty solution, but you can easily solve this issue by making an additional copy of the DLL with the correct name. If I find a better solution, I'll update this blog post again.

Friday, February 11, 2011

Input Trick: Typing Greek using JP IME

One of the first things I configure after a fresh Windows installation are the keyboard languages. As a programmer I loathe the international version of the US layout (I want my quotes immediately, not after pressing space), so I always make sure the correct layout is selected. I also like to type a bit of Japanese in Google every now and then, so I add the Japanese IME as an additional language.

But did you know you can also use the IME to type Greek symbols? It is actually quite simple when you're used to IMEs.

First of all, make sure you have the Japanese IME added as a keyboard:

Japanese IME added as an input method

Before typing, make sure you have selected the Japanese language and the Hiragana input method:

Hiragana input method selected

Now when you start typing, the IME will replace the Latin unigraphs, bigraphs and trigraphs with Japanese hiragana characters. After completing a word by pressing space, the IME will replace the string of hiragana characters with a word or symbol. If it chooses the correct word or symbol, you can continue on typing the next word. If it does not, you can press space again and a menu apears with other suggestions. You can select the suggestion with the space bar or arrow keys and confirm using enter.

To type Greek letters using the Japanese IME, you would have to input the Japanese pronunciation of those letters. The table below shows which Greek letters can be typed using the IME.



And here's the IME in action:



Happy typing. :)