A: 

I think Java compiler will optimize your loop in its way. And it is ok.

Imaskar
+1  A: 

One obvious optimization is to pre compute your dist(pk,pj) values before the loop

for example

dist_pk_pj = dist(pk,pj);

/* then do as you did before */
for (int k = 1; k < i; ++k) {
  tmp = l(k,i) + dist_pk_pj;
  if (tmp < min) {
    min = tmp;
  }
}

Note I didn't do a similar optimization for l (as in precompute a table of l) because you stated that it was already a precomputed table. If it wasn't then I would perform the same optimization :)

But as the previous comment stated the Java compiler could very well do that optimization for you. I'm no expert on what optimizations the Java Compiler performs though so take that last comment with a grain of salt :)

Finally are there any special properties that the l(k,i) table has? For example some symmetry l(i,k) = l(k,i) (I am just guessing here because I don't know much about the problem so Ignore this comment if it sounds wacky). If there are any special properties post them and we could come up with further optimizations.

hhafez
A: