A Novel Approach for Constrained Optimization in Graphical Models