(This is just the first thread I found - Valery had posted the sheet in slight variations on several occasions.)
As for the crossing paths (which clearly shows that Valery's algorithm is not finding the minimal path) you may create a program which finds all offending crossing segments and apply the substitution as shown in Fig. 6.26 here: https://web.mit.edu/urban_or_book/www/book/chapter6/6.4.7.html
Quite some work to do, as you would have to compare all combinations of two segments and check for crossing and as usual the most work would have to be done to cover the special cases (like two segments cross in one of the four involved points or the four points being collinear, etc.). Furthermore care must be taken choose the correct one of the two possible substitutions for each pair of crossing segments (as otherwise the continuous path would be split in two). Moreover 'uncrossing' a pair of crossing line segments may result in created new pairs of crossings segments, so I guess its not the easiest way to work starting from a path already created by an algorithm like Valery's.
Thank you, Werner_E, I certainly saw Valery Ochkov's solution to this problem, actually this is his solution, he asked there whether it was possible to do this without crossing the lines, but there was no answer from him or anyone else, that's actually what I wanted to know. Thanks again for participating.