Intrusion detection in wireless mobile networks without infrastructure is of great importance because of the dynamic structure, non-central locations and limited resources of nodes. Due to the characteristics of wireless sensor network, similarities between them and the natural communities can be found. Natural communities working together can do something much bigger than each can handle. For this reason, it seems that the natural communities can be used as a model in wireless sensor networks. These systems have a mechanism that can be matched with a wireless sensor network. With the help of particle swarm algorithm in intrusion detection system problems like falling into local optimality trap and slowness of convergence rate can be solved. Given the important elements that affect the network security, we have investigated a model in this study which evaluates energy and throughput of metaheuristic algorithms such as particle swarm and genetic and glowworm that occur in natural communities. Since the sensor nodes in the network are critical, since numerous attacks can put networks safety in danger which in terms of activity are active and passive, in this study also we have used active attacks with the help of NS2 simulator and MATLAB software. Also the impact of these metaheuristic algorithms in wireless sensor networks was considered to assess lifetime of nodes in wireless sensor network.