A Survey of Automatic Prompt Engineering: An Optimization Perspective