You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importcscl.dimacs_printerasdimacsimportcscl.cardinality_constraint_encodersascardencdimacs_out=dimacs.DIMACSPrinter()
# DIMACSPrinter implements the CNFLiteralFactory role interface.# Create 100 fresh literals with distinct variables:some_literals= [dimacs_out.create_literal() for_inrange(0, 100)]
# Create a constraint that at most 7 literals in constrained_literals may have# the value 'true':constraint_clauses=cardenc.encode_at_most_k_constraint_ltseq(lit_factory=dimacs_out,
constrained_lits=some_literals,
k=7)
# DIMACSPrinter implements the ClauseConsumer role interface.# Pass the constraint to the clause consumer:forclauseinconstraint_clauses:
dimacs_out.consume_clause(clause)
# Print the CNF formula as a DIMACS problem, passing the Python print()# function as the receiver of DIMACS-problem lines:dimacs_out.print(print)