SAT Solver Template
Loading...
Searching...
No Matches
basic_structures.hpp
Go to the documentation of this file.
1/**
2* @author Tim Luchterhand
3* @date 26.11.24
4* @file basic_structures.hpp
5* @brief Contains the basic structures variable and literal
6*/
7
8#ifndef BASIC_STRUCTURES_HPP
9#define BASIC_STRUCTURES_HPP
10
11/* These are only the declarations of the classes and their members
12 * @TODO implementation in basic_structures.cpp
13 */
14
15namespace sat {
16
17 /**
18 * @brief Represents a truth value
19 */
20 enum class TruthValue {
21 False = -1, ///< variable is true
22 Undefined = 0, ///< variable is unassigned
23 True = 1 ///< variable is true
24 };
25
26 /**
27 * @brief Structure representing a binary variable in a CNF-SAT problem
28 */
29 class Variable {
30 //@TODO Private members here
31 public:
32 /**
33 * CTor
34 * @param val variable number (name of the variable)
35 */
36 Variable(unsigned val);
37
38 /**
39 * gets the underlying variable number
40 * @return
41 */
42 unsigned get() const;
43
44 /**
45 * Compares the underlying variable identifier
46 * @return True if both variables are the same (have the same identifier)
47 */
48 bool operator==(Variable other) const;
49 };
50
51 /**
52 * @brief Structure representing a literal in a CNF-SAT problem.
53 * @details @copybrief
54 * A literal of variable x is either x or ¬x
55 */
56 class Literal {
57 //@TODO Private members here
58 public:
59 /**
60 * CTor
61 * @param val Literal identifier. A literal is related to a variable by dividing its identifier by two. An even
62 * identifier stands for a negative literal, an odd one for a positive
63 * see also sat::pos and sat::neg
64 */
65 Literal(unsigned val);
66
67 /**
68 * Gets the underlying literal identifier
69 * @return the literal identifier
70 */
71 unsigned get() const;
72
73 /**
74 * Gets the negated literal
75 * @return the negated literal
76 */
77 Literal negate() const;
78
79 /**
80 * Gets the sign of the literal
81 * @return -1 if negative literal, +1 else
82 */
83 short sign() const;
84
85 /**
86 * Compares underlying literal identifiers
87 * @return True if both literals are exactly the same (sign and variable)
88 */
89 bool operator==(Literal) const;
90 };
91
92 /**
93 * Creates the positive Literal for a given variable
94 * @param x Variable for which to create the literal
95 * @return positive literal of x
96 */
98
99 /**
100 * Creates the negative Literal for a given variable
101 * @param x Variable for which to create the literal
102 * @return negative literal of x
103 */
105
106 /**
107 * Gets the corresponding Variable of a Literal
108 * @param l
109 * @return Variable of given Literal
110 */
112
113}
114
115#endif //BASIC_STRUCTURES_HPP
Structure representing a literal in a CNF-SAT problem.
Definition basic_structures.hpp:56
unsigned get() const
Definition basic_structures.cpp:30
short sign() const
Definition basic_structures.cpp:38
bool operator==(Literal) const
Definition basic_structures.cpp:42
Literal negate() const
Definition basic_structures.cpp:34
Literal(unsigned val)
Definition basic_structures.cpp:26
Structure representing a binary variable in a CNF-SAT problem.
Definition basic_structures.hpp:29
bool operator==(Variable other) const
Definition basic_structures.cpp:22
unsigned get() const
Definition basic_structures.cpp:18
Variable(unsigned val)
Definition basic_structures.cpp:14
#define NOT_IMPLEMENTED
Definition exception.hpp:26
Definition basic_structures.cpp:10
Literal neg(Variable x)
Definition basic_structures.cpp:50
Literal pos(Variable x)
Definition basic_structures.cpp:46
TruthValue
Represents a truth value.
Definition basic_structures.hpp:20
@ Undefined
variable is unassigned
@ True
variable is true
@ False
variable is true
Variable var(Literal l)
Definition basic_structures.cpp:54