A methodology for restructuring networks by using Markov Random Fields