It seems GNU Scientific Library does not include a library for doing linear programming. This is quite useful as some expensive optimization problems in economics are, or, can be approximately re-cast as linear programming problems (see e.g.
Trick and Zin, 1993 and
Judd, Yeltekin and Conklin, 2003). Fortunately there is GNU Linear Programming Kit (GLPK) which includes:
- primal and dual simplex methods
- primal-dual interior-point method
- branch-and-cut method
- translator for GNU MathProg
- application program interface (API)
- stand-alone LP/MIP solver
Step 0: Download and Install GNU Linear Programming Kit
Note: I have tried to build from Fink, but the build is missing a crucial header file! So on to building from scratch. First, dowload the latest version of GPKL from
http://www.gnu.org/software/glpk/. When you're done, go to your terminal. Assuming you have downloaded the tar file to your Dowloads folder, then type (where the Terminal prompt is denoted by $):
$ cd ~/Downloads
$ tar -xzf glpk-4.45.tar.gz
$ .configure --prefix=/usr/local
$ make
$ sudo make install
Now you should have a working GLPK library. Check:
$ which glpsol
$ glpsol --help
Step 1: Xcode interface
Just like in the
GSL with Xcode tutorial, you also need to tell Xcode to find GLPK's header file
glpk.h, how to link to it, and what flags to pass to the compiler.
So next, click on the blue Info button on the toolbar. In the previous
GSL with Xcode tutorial example, you'd see on the right, a new panel called: Project "my_project_001" Info. Do the following:
- Type "Header Search Paths" in the search window. Add the path "/usr/local/include".
- Type "Library Search Paths" in the search window. Add the path "/usr/local/lib".
- Type "Other Linker Flags" in the search window. Add the additional linker flag: "-lglpk".
Now Xcode should be able to find and link to GLPK when compiling and linking C code which call the GLPK. Read the GLPK manual (currently version 4.4.5) for how to use the library.
Step 2: Start Coding, Compiling and Linking, and Debugging ...