The long-term development of hydrocarbon reservoirs (HCR) in the geological environment, complex deformation processes occur. Gravity monitoring is carried out to evaluate the possible geodynamic risk and negative consequences from HCR. As a result, the interrelationships of the continuously changing field-geological situation (changes in production volumes, changes in reservoir pressure, processes of fluid injection into productive formations) are investigated. The main tool for solving the gravity inversion when determining areas of increased industrial hazard is the solution of the gravity direct problem. In these studies, proceeding from a given initial approximation of the environment, the problem is realized through successive approximations. To assess such distributions, the authors of the article recommend using the simulated annealing technique within the framework of stochastic optimization. It is aimed at fitting the optimal parameters of the medium provided that a minimal residual of the gravity field values occurs. The approach is implemented using three simple mathematical models of the geological medium such as horizontal prism, homogeneous sphere, and vertical ledge. This technique allows fitting the media values simultaneously by a pair of its parameters. The operation of the algorithm is described and the simulation results are provided. The results showed acceptable accuracy of the algorithm for solving the direct gravity problem by the proposed method. The simulated annealing technique made it possible to increase the reliability of the HCR model while reduce the time for the analysis of the gravity field.