In this paper, we consider a Device-to-Device (D2D)-assisted Mobile Edge Computing (MEC) system in which the edge server collaboratively performs tasks with users who possess mobile characteristics. The computational resources of the edge server and the users are limited. Our objective is to minimize latency and energy consumption while maximizing system stability by determining the offloading decisions for all tasks. However, solving this problem is particularly challenging due to the coupling between offloading decisions and user mobility characteristics. To address this challenge, a Particle Swarm Optimization (PSO) algorithm based on Latin Hypercube Sampling (LHS) is proposed. PSO can be employed for iterative computation to obtain the optimal solution by treating the offloading decisions for all tasks as particles. Furthermore, employing LHS for the initialization and updating of the particle swarm can significantly enhance the performance and convergence of the PSO. Simulation results indicate that our proposed algorithm outperforms other algorithms significantly in terms of latency, energy consumption, and system stability while also exhibiting excellent robustness.