dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
literal.cpp
1
7#include "literal.h"
8
9#include <algorithm>
10
11namespace dlinear {
12
13bool operator==(const dlinear::Literal &lhs, const dlinear::Literal &rhs) {
14 return lhs.var.equal_to(rhs.var) && lhs.truth == rhs.truth;
15}
16std::strong_ordering operator<=>(const dlinear::Literal &lhs, const dlinear::Literal &rhs) {
17 if (lhs.var.get_id() < rhs.var.get_id()) return std::strong_ordering::less;
18 if (lhs.var.get_id() > rhs.var.get_id()) return std::strong_ordering::greater;
19 if (lhs.truth < rhs.truth) return std::strong_ordering::less;
20 if (lhs.truth > rhs.truth) return std::strong_ordering::greater;
21 return std::strong_ordering::equal;
22}
23
24bool operator==(const dlinear::LiteralSet &lhs, const dlinear::LiteralSet &rhs) {
25 return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
26}
27std::strong_ordering operator<=>(const dlinear::LiteralSet &lhs, const dlinear::LiteralSet &rhs) {
28 return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
29}
30
31std::ostream &operator<<(std::ostream &os, const Literal &literal) {
32 return os << (literal.truth ? "" : "¬") << literal.var;
33}
34
35std::ostream &operator<<(std::ostream &os, const LiteralSet &literal_set) {
36 os << "{ ";
37 for (const auto &lit : literal_set) os << lit << " ";
38 return os << "}";
39}
40
41std::ostream &operator<<(std::ostream &os, const std::vector<Variable> &variables) {
42 os << "[ ";
43 for (const auto &var : variables) os << var << " ";
44 return os << "]";
45}
46
47std::ostream &operator<<(std::ostream &os, const std::vector<Literal> &literals) {
48 os << "[ ";
49 for (const auto &lit : literals) os << lit << " ";
50 return os << "]";
51}
52
53std::ostream &operator<<(std::ostream &os, const Model &model) {
54 os << "Boolean model:\n";
55 for (const auto &lit : model.first) os << lit << " ";
56 os << "\nTheory model:\n";
57 for (const auto &lit : model.second) os << lit << " ";
58 return os;
59}
60} // namespace dlinear
bool equal_to(const Variable &v) const
Checks the equality of two variables based on their ID values.
Global namespace for the dlinear library.
std::set< Literal > LiteralSet
A set of literals.
Definition literal.h:28
std::pair< std::vector< Literal >, std::vector< Literal > > Model
A model is a pair of two vectors of literals.
Definition literal.h:29
A literal is a variable with an associated truth value, indicating whether it is true or false.
Definition literal.h:24
bool truth
Truth value.
Definition literal.h:26
Variable var
Variable.
Definition literal.h:25