its silly, its a matter of the shortest longest path if that makes sense. i.e. it will go as long as possible but wont loop around or take the scenic route to make sure it is the longest route...
i posted a similar thread about this, someone posted a pic (i think it was from a wiki) about trade routes etc. one of the more interesting points is that you can channel your trade route by choosing where and where not to put trade ports, that way the optimum route mechanic doesnt have to think too much, and cant screw you over by being lazy.
i would however like it to be fixed, or, alternatively, be scrapped in favour of something new and altogether more important. perhaps an optimum trade route has merchant protection (ie police forces) and pirate raids on your OTR cause economic damage that can be felt.
otherwise, just leave it, forget about it, and get possibly the same amount of credits by putting ports on all your planets?