In multi-hop wireless sensor networks characterized by many-to-one traffic patterns, problems related to energy imbalance among sensors often appear. For example, the amount of traffic that sensors are required to forward increases dramatically as the distance to the sink node becomes smaller. Thus, sensors closest to the sink node tend to die early, leaving areas of the network completely unmonitored and causing network partitions. Hence, an important issue of wireless sensor networks routing is how to mitigate the energy-hole problem. Based on the characteristics of wireless sensor networks, a routing problem is converted firstly into linear programming problem, and the equivalence between the routing problem and linear programming problem is proved. On the basis of the above, the particle swarm optimization algorithm (PSO) is used for solving the routing problem of avoiding the energy-hole. The algorithm redefines the particle of the PSO, the operation of particle, and the “flying” rules. Then it turns into a routing optimization algorithm for WSN based on PSO. The algorithm can be applicable to the flat network, while being applicable to the hierarchical network if improved in some sort. The significant advantage of the algorithm is that it could provide the general routing optimization approach for energy balance, regardless of the topology structure of network. Finally, the accuracy and effectiveness of the algorithm are proved respectively by theoretical analysis and a number of simulated experiments.