Non-intersecting line segments while minimizing the cumulative length
Solution 1:
This is Minimum Euclidean Matching in 2D. The link contains a bibliography of what's known about this problem. Given that you want to minimize the total length, the non-intersection constraint is redundant, as the length of any pair of segments that cross can be reduced by uncrossing them.
Solution 2:
You can select a random connection, then each time delete one cross by changing the connections of its endpoints. This operation reduces the total length (by triangle inequality). Since the number of ways of lines crossing each other is finite, in a finite number of steps we arrive at a noncrossing solution. In practice, it should converge quickly.