1 /******************************************
2 Copyright (c) 2014, Mate Soos
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 ***********************************************/
22 
23 // How To compile on Linux:
24 // 1) compile cryptominsat
25 // 2) install cryptominisat: sudo make install
26 // 3) run ldconfig: sudo ldconfig
27 // 4) build: g++ -std=c++11 readme_test.cpp -lcryptominisat5 -o readme_test
28 // 5) run: ./readme_test
29 
30 #include <cryptominisat5/cryptominisat.h>
31 #include <cassert>
32 #include <vector>
33 using std::vector;
34 using namespace CMSat;
35 
main()36 int main()
37 {
38     SATSolver solver;
39     vector<Lit> clause;
40 
41     //We need 3 variables
42     solver.new_var();
43     solver.new_var();
44     solver.new_var();
45 
46     //adds "1 0"
47     clause.push_back(Lit(0, false));
48     solver.add_clause(clause);
49 
50     //adds "-1 2 3 0"
51     clause.clear();
52     clause.push_back(Lit(0, true));
53     clause.push_back(Lit(1, false));
54     clause.push_back(Lit(2, false));
55     solver.add_clause(clause);
56 
57     lbool ret = l_True;
58     while(ret == l_True) {
59         ret = solver.solve();
60         if (ret == l_True) {
61             std::cout
62             << "Solution is: "
63             << solver.get_model()[0]
64             << ", " << solver.get_model()[1]
65             << ", " << solver.get_model()[2]
66             << std::endl;
67 
68             clause.clear();
69             for(size_t i = 0; i < 3; i++) {
70                 if (solver.get_model()[i] != l_Undef) {
71                     clause.push_back(Lit(i, solver.get_model()[i] == l_True));
72                 }
73             }
74             solver.add_clause(clause);
75         } else if (ret == l_False) {
76             std::cout << "No more solutions." << std::endl;
77         } else {
78             std::cout << "Solver returned that it didn't finish running."
79             "maybe you put a limit on its runtime?" << std::endl;
80         }
81     }
82 
83     return 0;
84 }
85