| 
									
										
										
										
											2012-06-12 16:29:57 +01:00
										 |  |  | #ifndef HORUS_LIFTEDVE_H
 | 
					
						
							|  |  |  | #define HORUS_LIFTEDVE_H
 | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-14 21:55:51 +00:00
										 |  |  | #include "LiftedSolver.h"
 | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | #include "ParfactorList.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LiftedOperator | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2012-11-01 22:54:14 +00:00
										 |  |  |     virtual ~LiftedOperator (void) { } | 
					
						
							| 
									
										
										
										
											2012-12-20 23:19:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  |     virtual double getLogCost (void) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void apply (void) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual string toString (void) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static vector<LiftedOperator*> getValidOps ( | 
					
						
							|  |  |  |         ParfactorList&, const Grounds&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static void printValidOps (ParfactorList&, const Grounds&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static vector<ParfactorList::iterator> getParfactorsWithGroup ( | 
					
						
							| 
									
										
										
										
											2012-05-24 23:38:44 +01:00
										 |  |  |         ParfactorList&, PrvGroup group); | 
					
						
							| 
									
										
										
										
											2012-12-27 22:25:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     DISALLOW_ASSIGN (LiftedOperator); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ProductOperator : public LiftedOperator | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     ProductOperator ( | 
					
						
							|  |  |  |         ParfactorList::iterator g1, ParfactorList::iterator g2, | 
					
						
							|  |  |  |         ParfactorList& pfList) : g1_(g1), g2_(g2), pfList_(pfList) { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     double getLogCost (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void apply (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static vector<ProductOperator*> getValidOps (ParfactorList&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     string toString (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     static bool validOp (Parfactor*, Parfactor*); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-10 00:18:20 +00:00
										 |  |  |     ParfactorList::iterator  g1_; | 
					
						
							|  |  |  |     ParfactorList::iterator  g2_; | 
					
						
							|  |  |  |     ParfactorList&           pfList_; | 
					
						
							| 
									
										
										
										
											2012-12-27 22:25:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DISALLOW_COPY_AND_ASSIGN (ProductOperator); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SumOutOperator : public LiftedOperator | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2012-12-20 23:19:10 +00:00
										 |  |  |     SumOutOperator (PrvGroup group, ParfactorList& pfList) | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  |         : group_(group), pfList_(pfList) { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     double getLogCost (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void apply (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static vector<SumOutOperator*> getValidOps ( | 
					
						
							|  |  |  |         ParfactorList&, const Grounds&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     string toString (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							| 
									
										
										
										
											2012-05-24 23:38:44 +01:00
										 |  |  |     static bool validOp (PrvGroup, ParfactorList&, const Grounds&); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-24 23:38:44 +01:00
										 |  |  |     static bool isToEliminate (Parfactor*, PrvGroup, const Grounds&); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-24 23:38:44 +01:00
										 |  |  |     PrvGroup        group_; | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  |     ParfactorList&  pfList_; | 
					
						
							| 
									
										
										
										
											2012-12-27 22:25:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DISALLOW_COPY_AND_ASSIGN (SumOutOperator); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CountingOperator : public LiftedOperator | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     CountingOperator ( | 
					
						
							|  |  |  |         ParfactorList::iterator pfIter, | 
					
						
							|  |  |  |         LogVar X, | 
					
						
							|  |  |  |         ParfactorList& pfList) | 
					
						
							|  |  |  |         : pfIter_(pfIter), X_(X), pfList_(pfList) { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     double getLogCost (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void apply (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static vector<CountingOperator*> getValidOps (ParfactorList&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     string toString (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     static bool validOp (Parfactor*, LogVar); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ParfactorList::iterator  pfIter_; | 
					
						
							|  |  |  |     LogVar                   X_; | 
					
						
							|  |  |  |     ParfactorList&           pfList_; | 
					
						
							| 
									
										
										
										
											2012-12-27 22:25:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DISALLOW_COPY_AND_ASSIGN (CountingOperator); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GroundOperator : public LiftedOperator | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     GroundOperator ( | 
					
						
							| 
									
										
										
										
											2012-05-24 23:38:44 +01:00
										 |  |  |         PrvGroup group, | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  |         unsigned lvIndex, | 
					
						
							|  |  |  |         ParfactorList& pfList) | 
					
						
							|  |  |  |         : group_(group), lvIndex_(lvIndex), pfList_(pfList) { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     double getLogCost (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void apply (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static vector<GroundOperator*> getValidOps (ParfactorList&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     string toString (void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							| 
									
										
										
										
											2012-12-27 22:25:45 +00:00
										 |  |  |     vector<pair<PrvGroup, unsigned>> getAffectedFormulas (void); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-10 00:18:20 +00:00
										 |  |  |     PrvGroup        group_; | 
					
						
							|  |  |  |     unsigned        lvIndex_; | 
					
						
							|  |  |  |     ParfactorList&  pfList_; | 
					
						
							| 
									
										
										
										
											2012-12-27 22:25:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DISALLOW_COPY_AND_ASSIGN (GroundOperator); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-14 21:55:51 +00:00
										 |  |  | class LiftedVe : public LiftedSolver | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2012-11-14 21:55:51 +00:00
										 |  |  |    LiftedVe (const ParfactorList& pfList) | 
					
						
							| 
									
										
										
										
											2012-11-14 23:13:46 +00:00
										 |  |  |        : LiftedSolver(pfList) { } | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-31 23:06:53 +01:00
										 |  |  |    Params solveQuery (const Grounds&); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |    void printSolverFlags (void) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     void runSolver (const Grounds&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     LiftedOperator* getBestOperation (const Grounds&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-10 00:18:20 +00:00
										 |  |  |     ParfactorList  pfList_; | 
					
						
							|  |  |  |     double         largestCost_; | 
					
						
							| 
									
										
										
										
											2012-12-27 22:25:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DISALLOW_COPY_AND_ASSIGN (LiftedVe); | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 16:29:57 +01:00
										 |  |  | #endif // HORUS_LIFTEDVE_H
 | 
					
						
							| 
									
										
										
										
											2012-05-23 14:56:01 +01:00
										 |  |  | 
 |