A general algorithm to fit constrained DEDICOM models