99# * how to compute weighted graphs and handle open vertices.
1010
1111# ## Problem definition
12+ # One can specify a satisfiable problem in the [conjuctive normal form](https://en.wikipedia.org/wiki/Conjunctive_normal_form).
13+ # In boolean logic, a formula is in conjunctive normal form (CNF) if it is a conjunction (∧) of one or more clauses,
14+ # where a clause is a disjunction (∨) of literals.
15+ using GraphTensorNetworks
16+
17+ @bools a b c d e f g
18+
19+ cnf = ∧ (∨ (a, b, ¬ d, ¬ e), ∨ (¬ a, d, e, ¬ f), ∨ (f, g), ∨ (¬ b, c))
20+
21+ # To goal is to find an assignment to satisfy the above CNF.
22+ # For a satisfiability problem at this size, we can find the following assignment to satisfy this assignment manually.
23+ assignment = Dict ([:a => true , :b => false , :c => false , :d => true , :e => false , :f => false , :g => true ])
24+
25+ satisfiable (cnf, assignment)
26+
27+ # We can contruct a [`Satisfiability`](@ref) problem to solve the above problem more cleverly.
28+
29+ problem = Satisfiability (cnf);
30+
31+ # ## Satisfiability and its counting
32+ # The size of a satisfiability problem is defined by the number of satisfiable clauses.
33+ num_satisfiable = solve (problem, SizeMax ())[]
34+
35+ # The [`GraphPolynomial`](@ref) of a satisfiability problem counts the number of solutions that `k` clauses satisfied.
36+ num_satisfiable_count = solve (problem, GraphPolynomial ())[]
37+
38+ # ## Find one of the solutions
39+ single_config = solve (problem, SingleConfigMax ())[]. c. data
40+
41+ # One will see a bit vector printed.
42+ # One can create an assignment and check the validity with the following statement:
43+ satisfiable (cnf, Dict (zip (labels (problem), single_config)))
0 commit comments