Consider a graph whose vertices can be partitioned into $n$ layers. Edges exist only between vertices in successive layers. So, there are edges between layers $1$ and $2$, between layers $2$ and $3$ and so on but never between layers $1$ and $3$ (since they are not successive layers) nor between vertices in the same layer.
An example of such a graph with three layers is shown in the figure below.
Now, I want to number the vertices in each layer from $1$ to $m_i$ (with $m_i$ being the number of vertices in layer $i$) in a way that the vertices at the two ends of any edge are as close in number as possible. We can think of an objective function that is the sum of squared differences of the numbers assigned to the vertices connected by each edge, across all edges.
Is there an efficient algorithm that can do this?
One idea is to use concepts from drawing force directed graphs, where we consider that each edge has a spring force trying to make it as short as possible with the additional constraint that vertices in each layer be restricted to vertical "pipes". Trying to implement this seems very complicated and not the most efficient method.
It was mentioned in the comments that this problem is related to the bandwidth problem in graph theory: https://en.wikipedia.org/wiki/Graph_bandwidth
