cnode/ModLeaf.h
00001 /*
00002  * ModLeaf.h
00003  *
00004  *  Created on: Feb 12, 2009
00005  *      Author: tdillig
00006  */
00007 
00008 #ifndef MODLEAF_H_
00009 #define MODLEAF_H_
00010 
00011 #include "Leaf.h"
00012 #include "Term.h"
00013 
00014 class ILPLeaf;
00015 class VariableTerm;
00016 
00017 class ModLeaf:public Leaf {
00018         friend class boost::serialization::access;
00019 private:
00020         Term* t;
00021         long int k;
00022         template<class Archive>
00023         void save(Archive & ar, const unsigned int version) const
00024         {
00025                 ar & boost::serialization::base_object<Leaf>(*this);
00026                 ar & t;
00027                 ar & k;
00028         }
00029         template<class Archive>
00030         void load(Archive & ar, const unsigned int version)
00031         {
00032                 ar & boost::serialization::base_object<Leaf>(*this);
00033                 ar & t;
00034                 ar & k;
00035                 t = Term::get_term_nodelete(t);
00036                 hash_c = t->hash_code();
00037                 hash_c = (hash_c*79) + k;
00038 
00039         }
00040         BOOST_SERIALIZATION_SPLIT_MEMBER()
00041 protected:
00042         // t%k=0
00043         ModLeaf(Term* t, long int k);
00044 
00045 public:
00046         ModLeaf(){};
00047         virtual ~ModLeaf();
00048         static CNode* make(Term* t, long int k, Term* r);
00049         static CNode* make(Term* t, long int k, long int r);
00050         static CNode* make(Term* t, long int k);
00051         Term* get_term();
00052         long int get_mod_constant();
00053         /*
00054          * Converts this mod constraint into a set of ILP leaves
00055          * First arg: resulting set of ilp leaves
00056          * Second arg: Indicates phase of the mod leaf
00057          * Third arg: id of the temp variable to introduce
00058          */
00059         void to_ilp(set<ILPLeaf*>& ilp_leaves, bool pos, int temp_id);
00060         virtual bool operator==(const CNode& other);
00061         virtual CNode* substitute(map<Term*, Term*>& subs);
00062         virtual string to_string();
00063         VariableTerm* get_ilp_temp(int temp_id);
00064         pair<VariableTerm*, VariableTerm*>
00065                 get_ilp_temps(int temp_id); // for negated leaves
00066 };
00067 
00068 #endif /* MODLEAF_H_ */