An Optimization algorithm for the collapse detection of stone masonry structures