Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

boolfunction.h

00001 #ifndef SCIL_BOOLFUNCTION
00002 #define SCIL_BOOLFUNCTION
00003 
00004 #include<scil/variable.h>
00005 #include<scil/scil.h>
00006 
00007 namespace SCIL {
00008   
00017    class boolfunction {
00018       
00019       friend class bool_inst;
00020 
00021       private:
00023          row rLinear;
00025          var v;
00027          boolfunction* left;
00029          boolfunction* right;
00031          boolOperator op;
00033          bool negated;
00040          std::string originalTerm;
00042          void remove_negation(bool root=true);
00045          void remove_xor_equ();
00046 
00048          inline void set_rLinear(row r) { rLinear = r;}
00049 
00051          inline void set_left(boolfunction* _left) { left = _left; }
00052 
00054          inline void set_right(boolfunction* _right) { right = _right; }
00055 
00057          inline void set_op(boolOperator _op) { op = _op; }
00058 
00059 
00060       public:
00061          boolfunction() : left(NULL), right(NULL), v(NULL), negated(false), rLinear(0) {};
00063          boolfunction(var _v, bool _negated = false)
00064             : left(NULL), right(NULL), v(_v), op(BASIC), negated(_negated), rLinear(0) { };
00065 
00067          boolfunction(var _v1, var _v2, boolOperator _op, bool _negated = false)
00068             : v(NULL), op(_op), negated(_negated), rLinear(0) {
00069             left = new boolfunction(_v1);
00070             right = new boolfunction(_v2);
00071          };
00072 
00074          boolfunction(boolfunction* _left, var _v2, boolOperator _op, bool _negated = false)
00075             : v(NULL), op(_op), negated(_negated), left(_left->copy()), rLinear(0) {
00076             right = new boolfunction(_v2);
00077          }
00078 
00080          boolfunction(var _v1, boolfunction* _right, boolOperator _op, bool _negated = false)
00081             : v(NULL), op(_op), negated(_negated), right(_right->copy()), rLinear(0) {
00082             left = new boolfunction(_v1);
00083          }
00084 
00086          boolfunction(boolfunction* _left, boolfunction* _right, boolOperator _op, bool _negated = false)
00087             : v(NULL), op(_op), negated(_negated), left(_left->copy()), right(_right->copy()), rLinear(0) { }; 
00088 
00089          ~boolfunction() {
00090             if(left!=NULL)
00091                delete left;
00092             if(right!=NULL)
00093                delete right;
00094          }
00095 
00097          boolfunction* copy();
00098 
00100          inline row get_rLinear() const { return rLinear; }
00101 
00103          inline boolfunction* get_left() const { return left; }
00104 
00106          inline boolfunction* get_right() const { return right; }
00107          
00111          inline var get_v() const { return v; }
00112 
00114          inline boolOperator get_op() const { return op; }
00115 
00117          inline bool is_negated() const { return negated; }
00118 
00120          inline void negate() { negated = !negated; }
00121 
00123          void add(boolOperator _op, var _v, bool negated = false);
00124 
00126          void add(var _v, boolOperator _op, bool negated = false);
00127 
00129          void add(boolfunction* _left, boolOperator _op, bool negated = false);
00130 
00132          void add(boolOperator _op, boolfunction* _right, bool negated = false);
00133 
00135          var& linearize(ILP_Problem& IP);
00136 
00142          void simplify();
00143 
00145          bool evaluate(solution& S);
00146 
00148          inline std::string get_originalTerm() {return originalTerm;}
00149 
00151          std::string toString();
00152 
00155          bool isHomogeneous(boolOperator _op = BASIC);
00156 
00158          std::vector<var> get_vars();
00159 
00160 
00161    };
00162 
00164    std::ostream& operator<<(std::ostream& o, const boolfunction* bf);
00165 
00167    bool bfcompare_less(const boolfunction* bf1, const boolfunction* bf2);
00168 
00170    bool bfcompare_equal(const boolfunction* bf1, const boolfunction* bf2);
00171 };
00172 #endif
00173 
00174 
00175 
00176 
00177 
Generated on Mon Mar 28 22:03:47 2011 for SCIL by  doxygen 1.6.3