I am a software developer. My question could be too naive for this site. I'll try my best to use math language.
I have a matrix like this (the size is dynamic):
$$ \begin{matrix} a11 & a12 & a13\\ 0 & a22 & a23\\ 0 & 0 & a33 \end{matrix} $$
It represents the minimum required distance between points on a line segment. For example a13 means the minimum distance between P1 and P3 on the line segment. So a11 = a22 = a33 = 0. The left bottom corner has been kept as 0 because it is not important in the transformation.
The requirement is to get a one-dimension matrix that represents the position of each point (P1 ~ P3 in the above example), so that the length of the line segment is smallest.
For example, for matrix:
$$ \begin{matrix} 0 & 0 & 200 & 900 \\ 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{matrix} $$
One (relatively simple) solution is to keep all points to the left as much as possible and still satisfy the constraints. $$ \begin{matrix} 0 & 0 & 200 & 900 \end{matrix} $$
Or a better solution would be (to put P3 at the middle of P2 and P4). In this solution, we still keep the P3 and P4 to the left. P2's position won't impact the total length. So we could put it in the middle of P1 and P3. $$ \begin{matrix} 0 & 100 & 200 & 900 \end{matrix} $$
an even better solution would be (to evenly distribute P2 and P3 as long). Even though the minimum distance between P1 and P3 is 200, putting P3 at 600 still satisfy the constraint, the positions of all points are more balanced. $$ \begin{matrix} 0 & 300 & 600 & 900 \end{matrix} $$
A sister question is asked at https://stackoverflow.com/questions/71041722/get-the-position-of-points-on-a-line-segment-with-constraints. I am looking for a pure math solution at here. Thanks