Simplifying a business example, I have the following situation:
Some objects should be distributed in a graph in most "linear" way possible for a given "thermometer".
Say, a voyager visits some cities. Several cities are visited multiple times.
So, we have list of cities in ordinate axis (that may be duplicated), and Time in abscissas one.
Now, for a given path, say (A => X => A => B => C) we should display a line, in the "most linear way possible".
By eg. in the image above, the green line is optimal one
(1 > 2 > 3 > 4 > 5)
but there could be multiple possible outputs
(1 > 2 > 1 > 4 > 5)
(1 > 2 > 3 > 4 > 5)
(1 > 2 > 6 > 4 > 5)
(3 > 2 > 1 > 4 > 5)
(3 > 2 > 3 > 4 > 5)
(3 > 2 > 6 > 4 > 5)
(6 > 2 > 1 > 4 > 5)
(6 > 2 > 3 > 4 > 5)
(6 > 2 > 6 > 4 > 5)
Is there some algorithms helping in such situations?