In this paper, we propose an artificial neural network model (ANN) to solve a partial differential equation (PDE) constrained optimization problem. Here, the discretize then optimize approach is used. At first, the Legendre polynomials are used to discretize the optimization problem and transform it into a quadratic optimization problem with linear constraint. Then an ANN model is proposed to solve the obtained quadratic optimization problem. Finally, several examples are presented to illustrate the abilities and efficiency of the proposed approach.