Optimization with looping

Hi. I’m working in a project which I have 16 modules ( 4 pavements of 16 modules, as the image bellow) and I need to remove 8 of them. My objective is to remove 8 modules in a way that I have the less perimeter as possible. The problem (that I think can be solved with a loop, I just don’t know how) Is that I only can choose the modules that are in the top. I thought I should use galapagos to choose which module I should remove. But the problem is that the list of modules that I can choose change everytime I remove one. I’ve tested hoopsnake and octopus loop but I couldn’t make it happen.

Any ideas?