There must be a stopping criterion that you have programmed to know that whether your algorithm reached to the solution or not. For example, you might write the criterion just like minimizing a performance index, and that no other solution found a value lower than the current one. the selection of the performance index may be MSE, ITAE, ITSE for control engineers. Or, any other cost function and it depends on your model and underlying application.