Constraint solving for diagrams