VHISTlib
1.84.0.3018
|
00001 /* $HEADERS 00002 $Id: cnf.h 2168 2011-05-30 09:09:54Z ahuesgen $ 00003 */ 00004 00005 #ifndef CONJUNCTIVENORMALFORM_H 00006 #define CONJUNCTIVENORMALFORM_H 00007 00008 #include "../shared/misc_defines.h" 00009 00010 #include <QString> 00011 #include <QList> 00012 #include <QSet> 00013 00014 namespace vhist 00015 { 00016 00017 enum CNFOperandType 00018 { 00019 OPERAND_TYPE_INVALID = 0, 00020 OPERAND_TYPE_STRING = 1, 00021 OPERAND_TYPE_VAR = 2 00022 }; 00023 00024 class VHIST_EXTERN CNFLiteralIndex 00025 { 00026 public: 00027 CNFLiteralIndex(int disjunctionIndex, int literalIndex); 00028 00029 public: 00030 int disjunctionIndex() const; 00031 int literalIndex() const; 00032 00033 private: 00034 int m_disjunctionIndex; 00035 int m_literalIndex; 00036 }; 00037 00038 00039 class VHIST_EXTERN CNFOperand 00040 { 00041 private: 00042 CNFOperand(); 00043 public: 00044 ~CNFOperand(); 00045 00046 public: 00047 static CNFOperand fromInvalid(); 00048 static CNFOperand fromString(const QString& str); 00049 static CNFOperand fromVariable(const QString& var, const QString& attr); 00050 00051 public: 00052 bool isString() const; 00053 bool isVariable() const; 00054 bool isInvalid() const; 00055 00056 QString string() const; 00057 QString variableName() const; 00058 QString variableAttribute() const; 00059 00060 private: 00061 CNFOperandType m_type; 00062 QString m_variable; 00063 QString m_attribute; 00064 QString m_string; 00065 }; 00066 00067 00068 enum LiteralType 00069 { 00070 LITERAL_TYPE_BOOL_VARIABLE, 00071 LITERAL_TYPE_TWO_PARAMTER_PREDICATE 00072 }; 00073 00074 00075 class VHIST_EXTERN CNFLiteral 00076 { 00077 public: 00078 CNFLiteral(bool negated, const CNFOperand& boolVariable); 00079 CNFLiteral(bool negated, const CNFOperand& left, const QString& op, 00080 const CNFOperand& right); 00081 ~CNFLiteral(); 00082 00083 public: 00084 bool isPredicate() const; 00085 bool isBoolVariable() const; 00086 00087 bool isNegated() const; 00088 CNFOperand left() const; 00089 CNFOperand right() const; 00090 QString op() const; 00091 00092 CNFOperand boolVariable() const; 00093 00094 QSet<QString> variableNames() const; 00095 00096 public: 00097 void setNegated(bool negate); 00098 00099 public: 00100 static CNFLiteral fromInvalid(); 00101 00102 private: 00103 LiteralType m_type; 00104 bool m_negated; 00105 QString m_operator; 00106 CNFOperand m_left; 00107 CNFOperand m_right; 00108 }; 00109 00110 00111 class VHIST_EXTERN CNFDisjunction 00112 { 00113 public: 00114 void addLiteral(const CNFLiteral& literal); 00115 QMultiHash<QString, int> variableLocations() const; 00116 int numLiterals() const; 00117 const CNFLiteral* literalAt(int i) const; 00118 00119 private: 00120 QList<CNFLiteral> m_literals; 00121 }; 00122 00123 00124 class VHIST_EXTERN ConjunctiveNormalForm 00125 { 00126 public: 00127 void clear(); 00128 00129 public: 00130 void addDisjunction(const CNFDisjunction& disjunction); 00131 CNFDisjunction* lastDisjunction(); 00132 QMultiHash<QString, CNFLiteralIndex> variableLocations() const; 00133 int numDisjunctions() const; 00134 const CNFDisjunction* disjunctionAt(int i) const; 00135 const CNFLiteral* literalAt(CNFLiteralIndex index) const; 00136 00137 private: 00138 QList<CNFDisjunction> m_disjunctions; 00139 }; 00140 00141 } 00142 00143 #endif // CONJUNCTIVENORMALFORM_H