OKlibrary
0.2.1.6
|
00001 // Oliver Kullmann, 26.2.2002 (Swansea) 00002 /* Copyright 2002 - 2007, 2009, 2010 Oliver Kullmann 00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute 00004 it and/or modify it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation and included in this library; either version 3 of the 00006 License, or any later version. */ 00007 00020 #include <iostream> 00021 #include <string> 00022 #include <set> 00023 #include <ctime> 00024 00025 #include <OKlib/Satisfiability/ProblemInstances/Variables/VarSet.hpp> 00026 #include <OKlib/Satisfiability/ProblemInstances/Literals/Literal.hpp> 00027 #include <OKlib/Satisfiability/ProblemInstances/Clauses/Clause.hpp> 00028 #include <OKlib/Satisfiability/ProblemInstances/ClauseSets/ClauseSet.hpp> 00029 #include <OKlib/Satisfiability/Assignments/PartialAssignments/PartAssign.hpp> 00030 #include <OKlib/Satisfiability/Algorithms/Backtracking/DLL_Algorithms.hpp> 00031 00032 #include <OKlib/General/Kommandozeile.hpp> 00033 00034 namespace { 00035 00036 const std::string Selbst = "DLL-Implementations"; 00037 00038 const char* const Version = "1.0.3"; 00039 const char* const Datum = "27.4.2010"; 00040 const char* const Autor = "Oliver Kullmann (Swansea); O.Kullmann@Swansea.ac.uk"; 00041 const char* const Uebersetzungsdatum = __DATE__ " " __TIME__; // Gnu-Uebersetzung 00042 00043 00044 00045 KMZ::Sprachen Language = KMZ::Englisch; 00046 00047 const int NumberLanguages = 2; 00048 00049 const char* const messages[][NumberLanguages] = { 00050 {"Es wurde versucht, einen leeren Variablennamen zu benutzen.", // 0 00051 "There has been an attempt to use an empty variable name."}, 00052 {"Es wurde eine Zuweisung zwischen Variablenmengen versucht.", // 1 00053 "There has been an attempt to do an assignment for variable sets."}, 00054 {"Es wurde versucht, eine tautologische Klausel zu erzeugen.", // 2 00055 "There has been an attempt to create a tautological clause."}, 00056 {"Es wurde versucht, den Wert einer partiellen Belegung fuer ein nicht im Definitionsbereich vorzufindendes Element zu bestimmen.", // 3 00057 "There has been an attempt to evaluate a partial assignment for an argument which is not in the domain."}, 00058 {"Es wurde versucht, eine partielle Belegung in inkonsistenter Weise zu erweitern.", // 4 00059 "There has been an attempt to extend a partial assignment in an inconsistent way."}, 00060 {"FEHLER", // 5 00061 "ERROR"}, 00062 {"Zeitverbrauch (in Sekunden) fuer die SAT-Entscheidung = ", // 6 00063 "Running time (in seconds) for SAT decision = "}, 00064 {"Zeitverbrauch (in Sekunden) fuer das Einlesen = ", // 7 00065 "Running time (in seconds) for reading the input = "}, 00066 }; 00067 00068 const char* message(const int i) { 00069 return messages[i][Language]; 00070 } 00071 00072 const std::string standarderr = message(5) + Selbst + "]: "; 00073 00074 void output_litset(const Clauses::Litset& L) { 00075 for (std::set<Literals::Lit>::const_iterator i = L.ls.begin(); i != L.ls.end(); ++i) { 00076 const Literals::Lit l = *i; 00077 std::cout << " "; 00078 if (l.val() == true) 00079 std::cout << "-"; 00080 std::cout << l.var().get_name(); 00081 } 00082 std::cout << "\n"; 00083 } 00084 00085 void output_varset(const std::set<Variables::Var>& V) { 00086 for (std::set<Variables::Var>::const_iterator i = V.begin(); i != V.end(); ++i) 00087 std::cout << " " << i -> get_name(); 00088 std::cout << "\n"; 00089 } 00090 00091 } 00092 00093 00094 int main (const int argc, const char* const argv[]) { 00095 00096 enum choices {A_DLL_1}; 00097 choices choice = A_DLL_1; // default 00098 if (argc >= 2) 00099 if (std::string(argv[1]) == "DLL_1") 00100 choice = A_DLL_1; 00101 DLL_Algorithms::SAT_Algorithms* const algorithms[] = {DLL_Algorithms::DLL_1}; 00102 00103 Variables::Var_Set V; 00104 Clausesets::Cls F; 00105 00106 try { 00107 std::clock_t time_stored, time_new; 00108 00109 time_stored = std::clock(); 00110 F.read(V); 00111 time_new = std::clock(); 00112 00113 std::cout << message(7) << (double) (time_new - time_stored) / CLOCKS_PER_SEC << "\n"; 00114 00115 std::cout << "n = " << F.n() << ", c = " << F.c() << ", l = " << F.l() << ", pmin = " << F.pmin() << ", pmax = " << F.pmax() << "\n"; 00116 00117 time_stored = std::clock(); 00118 const DLL_Algorithms::Result r = algorithms[choice](F); 00119 time_new = std::clock(); 00120 00121 std::cout << "sat = " << r.sat << "\n"; 00122 std::cout << message(6) << (double) (time_new - time_stored) / CLOCKS_PER_SEC << "\n"; 00123 } 00124 00125 catch (Variables::Error::empty_name) { 00126 std::cerr << standarderr << message(0) << "\n"; 00127 return 1; 00128 } 00129 catch (Variables::Error::invalid_assignment) { 00130 std::cerr << standarderr << message(1) << "\n"; 00131 return 1; 00132 } 00133 catch (Clauses::Error::not_a_clause) { 00134 std::cerr << standarderr << message(2) << "\n"; 00135 return 1; 00136 } 00137 catch (PartAssignments::Error::not_in_domain) { 00138 std::cerr << standarderr << message(3) << "\n"; 00139 return 1; 00140 } 00141 catch (PartAssignments::Error::inconsistent_extension) { 00142 std::cerr << standarderr << message(4) << "\n"; 00143 return 1; 00144 } 00145 }