Author Archives: Chang

Why Julia

I have always been hunting for something in the middle of MATLAB and Java (or C++).

MATLAB is easy and convenient, and enables us finish coding early. On the other hand, MATLAB is notorious for slow for-looping. Also, its another weakness, more important for math programmers, is that it does not have an algebraic modeling language for optimization solvers like CPLEX. We need to prepare those big A matrix and b, c vectors. Painful.

Java (or C, C++) usually performs much better than MATLAB, and CPLEX provides a great algebraic modeling language for optimization problems (called Concert Technology). However, it is really really painful to define all the variables, classes, methods, and packages before we start the first line of the algorithm. I personally don’t like the fact that the first index of Java arrays is 0, not 1. Math programmers mainly work with matrices and vectors in the form of array, so 0 does not make any sense.

Python might be an alternative, but again it has 0 as the first index of array, and it lacks convenient algebraic modeling language.

Here comes Julia.

The Julia Language has been developed by MIT guys, aiming to develop a MATLAB-like language (fast coding) with high-performance like C. It is still under heavy developments, and it’s still version 0.2. (By the way, I like the song by the Beatles, Julia.)

I just felt in love with Julia. Here is my sample code for an LP problem (without data manipulation parts):

m = Model()
@defVar(m, 0<= x[links] <=1)
@setObjective(m, Min, dot(link_length, x))
for i=1:no_node
@addConstraint(m, sum{x[(j,k)], (j,k) in links; j==i } 
                - sum{x[(j,k)], (j,k) in links; k==i } == b[i])

I think you will immediately catch what it is. Isn’t it beautiful?

Another good news is that you can connect CPLEX or Gurobi MILP solvers. As Julia is now being developed heavily, not everything is perfect. I had some bad experiences with connecting CPLEX, but had wonderful experiences with Gurobi. It seems that now many math programmers are accepting Gurobi as an excellent alternative to CPLEX.

If you are sold, see my guides.