Combined heat and power (CHP) systems are employed to supply electrical and thermal loads of distribution networks (DNs). However, the heat loss can significantly hinder the heat transfer through pipelines from CHP systems to consumers Therefore, the optimal placement and sizing of CHP systems to reduce losses, including electrical and thermal losses, are very crucial. To minimize electrical loss, many methods have been proposed for optimal resource allocation. In this paper, a new approach for the optimal allocation of CHP systems to minimize electrical loss and heat transfer loss (HTL) is presented. Accurate modeling of HTL through the pipeline is performed. The proposed method is applied to 33βbus, 69βbus, and 84βbus test systems. According to the simulation results, it is concluded that considering HTL in the resources optimization problem leads to major changes in the selection of CHP systems' optimal size and location. To solve the optimization problem, a new enhanced imperialist competitive algorithm (EβICA) is presented. The proposed algorithm enhances the performance and efficiency of the ICA algorithm by improving exploitation and exploration to prevent getting trapped in local optimums. Comparison of CHP systems allocation results confirms the superiority of the EβICA algorithm over other methods.