Suppose we have a 6 vertices graph. We also have 6 gates. Each gate is attributed a path.
For example,
Gate 'A' will have to go to 'B'- 'C' - 'D' and 'E'
Gate 'B' will have to go to 'D'
Gate 'C' will have to go to 'A' and 'B'
Gate 'D' will have to go to 'E' - 'A' and 'B'
Gate 'E' will have to go to 'C' - 'E' and 'A'
Gate 'B' will have to go to 'D'
How can I find the optimal placement of the gates on the graph, such that it makes the least distance overall, computing all the paths to be made?
For 6 gates, we could search all possible placements by brute force. However, in my current project I have 42 gates to dispatch, thus it sounds too complicated to brute force.
The following is the function used to calculate the distance between the two gates (stocked in a Pandas DataFrame)
import math
def calculateDistance(df, gate_a, gate_b):
coord_a = [(x, df.columns[y]) for x, y in zip(*np.where(df.values == gate_a))][0] # GET COORDINATE OF GATE_A
coord_b = [(x, df.columns[y]) for x, y in zip(*np.where(df.values == gate_b))][0] # GET COORDINATE OF GATE_B
y1, x1 = coord_a[0], coord_a[1]
y2, x2 = coord_b[0], coord_b[1]
dist = math.sqrt((((x2 - x1) * scale_x) **2) + ( ((y2 - y1) * scale_y) **2 ))
return dist
calculateDistance(df, "A", "C")