To simplify the business example, I have the following situation:
Some objects should be distributed on the graph in the most "linear" way for a given "thermometer".
Say a traveler visits some cities. Several cities are visited several times.
So, we have a list of cities along the ordinate (which can be duplicated), and time - on the abscissa.
Now, for this path, say (A => X => A => B => C) , we need to display the line in the βmost linear wayβ.

E.g. In the image above, the green line is optimal. (1> 2> 3> 4> 5)
but there may be several possible solutions
(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)
Are there any algorithms that help in such situations?
source share