Support stopping condition for optimize