A variational approach for minimum cost flow problems