A message-passing paradigm for optimization