Randomized and distributed self-configuration of wireless networks: two-layer Markov random fields and near-optimality