3

I may need to implement Integer Linear Programming today and I am wondering if there are any pseudo codes or relatively pain-free (well commented) source codes that explain how to implement it? With strong preference towards pseudo code.

Please note, I am not looking for a serious complete project with all the "fine tuning" to get the most optimal performance. I am looking for the most basic solver that demonstrates how integer linear programming works vs. trying all the options one by one.

Thanks.

AturSams
  • 7,568
  • 18
  • 64
  • 98

1 Answers1

8

This question is a big ask, so let me try it step-by-step:

When you say Integer Linear Program, I assume you mean IP's with linear constraints and objective function.

1. Start with the Simplex Algorithm. (Even though this will NOT work for IP's, except in "lucky" cases where your linear program has the "integrality" property.) But the Simplex is always a good place to start, esp. since you are interested in a first principles approach

Surprisingly, PseudoCode is not that easy to find, though solved examples are plentiful. Here's one example of the steps in the Simplex algorithm. (Not Psuedo code)

In Section 3.1.4 Summary of Computation Procedure there is something close to pseudo-code.

This document also has a summary of the Simplex Algorithm that can be implemented, esp. if you follow the example in the preceding sections.

Note that Simplex is one of those algorithms that is relative easy to understand (esp. step-by-step) but notoriously difficult to implement. A really good discussion of why this is so can be found here.

2. Integer Programming - The "simplest" case. Many people tend to start with the "Knapsack" problem.

You can find both the pseudo-code and a Java implementation here.

3. IP's of increasing difficulty/complexity.

  • Capital Budgeting Problem
  • Assignment Problems
  • Transportation Problems

4. General Purpose vs Specialized You now have a choice:

  • 4a. You can build 'general purpose' IP Solver (but will take a very long time to run)
  • 4b. Build special purpose IP solvers for special types of problems.

For 4a: You can assume 0/1 variables and demonstrate branch-and-bound techniques. You can find implementations of trees and modify for your own purposes. (Essentially, clever implementations of exhaustive searches.)

For 4b: You could take one case, say the Assignment Problem, for which the Hungarian algorithm is often used since it is easy to understand and can be taught in one sitting to a group of students. This tutorial in topcoder covers it quite extensively with the math, pseudo and real code.

Long answer, but I hope this is along the lines of what you are hoping for.

Ram Narasimhan
  • 22,341
  • 5
  • 49
  • 55
  • Hi Ram Narashimhan, I am familiar with the simplex algo, we learn it in tau and I think I can find a document. I remember how it works. The answer is very good and well thought and explained. – AturSams Oct 10 '12 at 03:41
  • @ArthurWulfWhite Thanks. I wasn't exactly sure as to what your end goal was. If this is not what you are looking for, just clarify your needs and I can give you more pointers. – Ram Narasimhan Oct 10 '12 at 06:21
  • I thought it was like Linear Programming and Simplex where there is a well known algorithm that handles this situation more effectively than exhaustive searches. (even though it is npc). I used lpsolver in the past, it is a milp with good capabilities for ilp solving (much faster than trying all the options) and I was impressed. I guess I was hoping the implementation of a generic ilp solver was as simple as Simplex is to understand. – AturSams Oct 10 '12 at 06:35
  • @ArthurWulfWhite IP Solvers are not as simple, esp. if you are looking for something simple. If you are even somewhat familiar with R, I'd recommend that you look into the `optim` package. R code is exposed, so one can always learn something from looking at the code. – Ram Narasimhan Oct 10 '12 at 06:40
  • I kind of feel like the guy that asked for a simple implementation of a fast 3d physics engine a couple of days ago in gamedev se. I am glad you answered my question, I am all the wiser for it. I suspected this was not a trivial solver to implement. – AturSams Oct 10 '12 at 06:55