Generative Spatial Planning

Hi everyone! I need help in creating a fitness value (objective) by making sure that space 1 and space 2 will always be adjacent to each other during generation

You can calculate the distance between each space (centre point for example) and minimise that value.