Optimal clustering and inter-cluster routing in large-scale wireless ad hoc and sensor networks