Transmission line impedance in DC microgrids can cause voltage dips and uneven current distribution, negatively impacting droop control and voltage stability. To address this, this study proposes an optimization approach using heuristic techniques to determine the optimal droop parameters. The optimizcv ation considers reference voltage constraints and virtual impedance at various load conditions, particularly resistive. The optimization problem is addressed using two techniques: queen honey bee migration (QHBM) and particle swarm optimization (PSO). Simulation results show that QHBM reaches an error of 0.8737 at the fourth iteration. The QHBM and PSO algorithms successfully optimized the performance of the DC microgrid under diverse loads, with QHBM converging in 5 iterations with an error of about 0.8737, and PSO in 40 iterations drawn error is 0.9 while keeping the current deviation less than 1.5 A and voltage error less than 0.5 V. The deviation of current control and virtual impedance values are verified through comprehensive simulations in MATLAB/Simulink.