Lower energy consumption and higher data rate have been becoming the key factors of modern wireless mobile communication for the improvement of user experiences. At present, the commercialization of 5G communications is gradually promoting the development of Internet of things (IoT) techniques. Due to the limited coverage capability of direct wireless communications, the indirect device-to-device (D2D) communications using information relay, in addition to the single 5G base station deployment, have been introduced. Along with the increase of information nodes, the relay devices have to undertake the nonnegligible extra data traffic. In order to adjust and optimize the information routing in D2D services, we present an algorithmic investigation referring to the ant colony optimization (ACO) algorithm and the artificial immune algorithm (AIA). By analyzing the characteristics of these algorithms, we propose a combined algorithm that enables the improved the iterative convergence speed and the calculation robustness of routing path determination. Meanwhile, the D2D optimization pursuing energy saving is numerically demonstrated to be improved than the original algorithms. Based on the simulation results under a typical architecture of 5G cellular network including various information nodes (devices), we show that the algorithmic optimization of D2D routing is potentially valid for the realization of primitive wireless IoT networks.