I need recommendation on machine learning algorithm(s) that can learn how to swap the values of the centroid_1 and centroid_2 (i.e. re-arrange the cent, in a predefined pattern). Sometimes the centroids between the different groups of objects can be very close but I want the objects with the same id to be arranged in a square or horizontal pattern. The test data will contain mismatched centroids to the objects but the algorithm would have learned to match the centroid to the right object_ids (making sure object with same ids are closely arranged i.e. the value of the centroids are close). The solution should be able to re-arrange objects of the same ids in a specific learned pattern when visualized. I expect the algorithm to have been trained with the right pattern (arrangement) and would be able to swap the centroid columns if there is any mismatch.
The snapshot attached below would be similar to the required output when visualised.