## Latex: When Algorithms and Hyperref hate each other

When using algorithms in Latex and trying to use hyperref to produce automatic links in the references that one uses in LaTeX documents one usually finds out that although the references are printed correctly, the links for algorithms don’t work (usually pointing to the first page in the document). If you investigate the messages of the output you usually find:

pdfTeX warning (dest): name{algorithm.1} has been referenced
but does not exist, replaced by a fixed one

Well, the problem is that for some reason hyperref doesn’t work correctly with the algorithm and float packages. The trick to solve this is to push the use of hyperref package down the most in the preamble (without breaking anything) and then put the float package before hyperref and algorithm package after hyperref like in the example below:

... \usepackage{float} % Before hyperref \usepackage{hyperref} \usepackage{algorithm} % After hyperref \begin{document} ...

This seems to solve the problem, and there are other situations where one might want to be careful with the order we load packages.

Does this solve the problem for you?

## The languages in developing a new algorithm

You have an idea for a new algorithm! Great, what to do next?

You prototype it in Python because of the expressiveness and the dynamic typing is a really cool thing to have while messing around. Performance wise it isn’t anything to show off and you think that you really need something faster.

You choose Go to rewrite the algorithm to take advantage of gorotutines, channels, etc… and you change your app so it can run in your multi-core computer.

Your algorithm is getting to shape, is fast but not the fastest and in your pursuit to make it faster than light, you end up rewriting it in plain old good C just to see how much you can squeeze of those clock cycles.

It is now fast, great and is attracting attention from the industry. You end up writing the algorithm in Java, that gold standard of the industry, and make big money selling it.

But it was developed in academia so you have to publish it in journals and conferences. After all this is your master piece! You rewrite your algorithm in Clojure, just to look smart, you publish several papers on it, and get a tenure on a famous university… doing the occasional consulting sting and getting rich (you hope).

After some time in academia you get a grad student that wants to work with your algorithm. He is excited about the work, but he doesn’t know how to program. You then decide to rewrite your algorithm once again in Python (you lost your original code years ago) to make it easy on your student to learn.

Curiously your code is now shorter, elegant, and very fast. You tell yourself that Guido must have done something magic to CPython in the past few years and contemplate the brilliance of your code.

I could have just called this post ‘some programming languages that you should know or be aware of’

## Playing with A* Updated

Just updated the Playing with A* algorithm app so that now one can toggle on and off the use of the heuristic and the use of a cross product tiebreaker. This leads to new variants of the algorithm, mainly the well known Dijkstra algorithm.

This A * application was written in Java, so you’ll need to check your java permissions to run it. You can download the .jnlp file and run it from your computer.

The A* Algorithm (A star) is a pathfinding and graph traversal algorithm. It is widely used in computer science, games, robotics and network science. A thorough overview of the algorithm can be found in Introduction to A* which presents several comparisons and illustrations on the mechanics of the A star algorithm.

## Playing with the A* Algorithm

In computer science, A* (pronounced “A star”) is a computer algorithm that is widely used in pathfinding and graph traversal, the process of plotting an efficiently traversable path between points, called nodes. Noted for its performance and accuracy, it enjoys widespread use. [Wikipedia]

My implementation uses a tie-breaker based on the cross product of the vectors from the start to the target and the evaluated node and the target.

The A Star App was coded in java. If your browser doesn’t run java you can download the A Star Jnlp file and run it from your desktop.