The problem you are describing is how to minimize the maximum distance. I think it's NP-hard so a simple solution won't be very good. You could however model it as an ILP problem and use some solver for that.
You would then minimize M as an objective.
constraints would be M>= abs(s_i-e_i)
for all links l_i
. s_i
and e_i
represent the absolute indices of the start and end entry of your link.
These entries can be rewritten in terms of the node they belong to as s_i=n_i+c_i
with n_i
the index of the node s_i
belongs to and c_i
the fixed offset within that node (among the other entries). e_i
is similarly rewritten. Then you're set to optimize n_i
with the solver