Conventional mathematical modeling-based approaches are incompetent to solve the electrical power quality problems, as the power system network represents highly nonlinear, nonstationary, complex system that involves large number of inequality constraints. In order to overcome the various difficulties encountered in power system such as harmonic current, unbalanced source current, reactive power burden, active power filter (APF) emerged as a potential solution. This paper proposes the implementation of particle swarm optimization (PSO) and bacterial foraging optimization (BFO) algorithms which are intended for optimal harmonic compensation by minimizing the undesirable losses occurring inside the APF itself. The efficiency and effectiveness of the implementation of two approaches are compared for two different conditions of supply. The total harmonic distortion (THD) in the source current which is a measure of APF performance is reduced drastically to nearly 1% by employing BFO. The results demonstrate that BFO outperforms the conventional and PSO-based approaches by ensuring excellent functionality of APF and quick prevail over harmonics in the source current even under unbalanced supply.