Ecologically optimized coastal defense