SAT Solver Template
Loading...
Searching...
No Matches
Solver.hpp
Go to the documentation of this file.
1/**
2* @author Tim Luchterhand
3* @date 27.11.24
4* @file Solver.hpp
5* @brief Contains the main solver class
6*/
7
8#ifndef SOLVER_HPP
9#define SOLVER_HPP
10
11#include <memory>
12
14#include "Clause.hpp"
15
16namespace sat {
17 /*
18 * These two types might be useful for your implementation. A shared pointer manages an object on the heap. It can
19 * be copied without copying the actual object. This can be useful if you want to access the same clause from
20 * multiple locations without copying it. Once all copies of the pointer have been destroyed, the actual object
21 * is also destroyed
22 */
23 using ClausePointer = std::shared_ptr<Clause>;
24 using ConstClausePointer = std::shared_ptr<const Clause>;
25
26
27 /**
28 * @brief Main solver class
29 */
30 class Solver {
31 // @TODO private members here
32 public:
33
34 /**
35 * Ctor. Allocates enough space for the variables.
36 * @param numVariables Number of variables in the problem
37 * @note This Ctor needs to exist for the tests. You can add other Ctors if you want
38 */
39 explicit Solver(unsigned numVariables);
40
41 /*
42 * @TODO if you want, you can declare additional constructors here
43 */
44
45
46 /*
47 * You can design the interface of your solver as you want. You can for example add clauses already in the
48 * constructor. The tests require the addClause method, however.
49 */
50
51 /**
52 * Adds a clause to the solver.
53 * @param clause The clause to add
54 * @return bool true if clause was successfully added, false if clause is empty or unit and violates the current
55 * model
56 */
57 bool addClause(Clause clause);
58
59 /**
60 * Returns a reduced set of clauses. Excludes satisfied clauses and removes falsified literals from clauses
61 * @return equivalent set of clauses
62 */
63 auto rebase() const -> std::vector<Clause>;
64
65 /**
66 * Returns the truth value of the given variable
67 * @param x a variable (needs to be contained in the solver)
68 * @return TruthValue of the given variable
69 */
70 TruthValue val(Variable x) const;
71
72 /**
73 * Checks if a literal holds
74 * @param l literal (needs ti be contained in the solver)
75 * @return true if literal holds under current model, false otherwise
76 */
77 bool satisfied(Literal l) const;
78
79 /**
80 * Checks if a literal does not hold
81 * @param l literal (needs ti be contained in the solver)
82 * @return true if literal the negated literal is satisfied, false otherwise
83 */
84 bool falsified(Literal l) const;
85
86 /**
87 * Assigns the given literal
88 * @param l Literal to assign
89 * @return false if literal is already falsified, true otherwise
90 */
91 bool assign(Literal l);
92
93 /**
94 * Does the unit propagation.
95 * @return true if unit propagation was successful, false otherwise
96 */
97 bool unitPropagate();
98
99 };
100} // sat
101
102#endif //SOLVER_HPP
Clause class with watch literals.
Definition Clause.hpp:36
Structure representing a literal in a CNF-SAT problem.
Definition basic_structures.hpp:56
Main solver class.
Definition Solver.hpp:30
bool satisfied(Literal l) const
Definition Solver.cpp:77
auto rebase() const -> std::vector< Clause >
Definition Solver.cpp:26
bool assign(Literal l)
Definition Solver.cpp:85
TruthValue val(Variable x) const
Definition Solver.cpp:73
bool unitPropagate()
Definition Solver.cpp:89
Solver(unsigned numVariables)
Definition Solver.cpp:11
bool addClause(Clause clause)
Definition Solver.cpp:15
bool falsified(Literal l) const
Definition Solver.cpp:81
Structure representing a binary variable in a CNF-SAT problem.
Definition basic_structures.hpp:29
#define NOT_IMPLEMENTED
Definition exception.hpp:26
Definition basic_structures.cpp:10
TruthValue
Represents a truth value.
Definition basic_structures.hpp:20