Optimization in wireless sensor networks