| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  |   LPAD and CP-Logic interpreter | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | Copyright (c) 2007, Fabrizio Riguzzi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | This package uses the library cudd, see http://vlsi.colorado.edu/~fabio/CUDD/
 | 
					
						
							|  |  |  | for the relative license. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2016-05-14 11:29:15 +01:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-26 17:39:52 +00:00
										 |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-05 23:51:35 +00:00
										 |  |  | #include "cudd_config.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-09 14:58:57 +00:00
										 |  |  | #if HAVE_CUDD_CUDD_H
 | 
					
						
							|  |  |  | #include "cudd/cudd.h"
 | 
					
						
							|  |  |  | #include "cudd/mtr.h"
 | 
					
						
							|  |  |  | #elif HAVE_CUDD_H
 | 
					
						
							|  |  |  | #include "cudd.h"
 | 
					
						
							|  |  |  | #include "mtr.h"
 | 
					
						
							| 
									
										
										
										
											2014-10-26 17:39:52 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | #include "YapInterface.h"
 | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   int var,value; | 
					
						
							|  |  |  | } factor; | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-27 16:53:47 +02:00
										 |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   int nFact; | 
					
						
							|  |  |  |   factor * factors; | 
					
						
							|  |  |  | } term; | 
					
						
							| 
									
										
										
										
											2010-07-27 16:53:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   int nTerms; | 
					
						
							|  |  |  |   term * terms; | 
					
						
							|  |  |  | } expr; | 
					
						
							| 
									
										
										
										
											2010-07-27 16:53:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   int nVal,nBit; | 
					
						
							|  |  |  |   double * probabilities; | 
					
						
							|  |  |  |   DdNode * * booleanVars; | 
					
						
							|  |  |  | } variable; | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-27 16:53:47 +02:00
										 |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   int nVar; | 
					
						
							|  |  |  |   int nBVar; | 
					
						
							|  |  |  |   variable * varar; | 
					
						
							|  |  |  |   int * bVar2mVar; | 
					
						
							|  |  |  | } variables; | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | typedef struct  | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   DdNode *key; | 
					
						
							|  |  |  |   double value; | 
					
						
							|  |  |  | } rowel; | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | typedef struct   | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int cnt; | 
					
						
							|  |  |  |   rowel *row; | 
					
						
							|  |  |  | } tablerow; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | variables createVars(YAP_Term t,DdManager * mgr, int create_dot,  | 
					
						
							|  |  |  |   char inames[1000][20]); | 
					
						
							|  |  |  | expr createExpression(YAP_Term t); | 
					
						
							|  |  |  | void init_my_predicates(void); | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-27 16:53:47 +02:00
										 |  |  | DdNode * retFunction(DdManager * mgr, expr expression,variables v); | 
					
						
							|  |  |  | DdNode * retTerm(DdManager * mgr,term t,variables v); | 
					
						
							|  |  |  | DdNode * retFactor(DdManager * mgr, factor f, variables v); | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  | double Prob(DdNode *node, variables vars,tablerow * nodes); | 
					
						
							| 
									
										
										
										
											2009-02-16 12:23:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | double ProbBool(DdNode *node, int bits, int nBit,int posBVar,variable v, | 
					
						
							| 
									
										
										
										
											2011-10-22 16:33:04 +02:00
										 |  |  |   int mVarIndex, | 
					
						
							|  |  |  |   variables vars,tablerow * nodes, int comp); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | tablerow* init_table(int nbvars); | 
					
						
							|  |  |  | double * get_value(tablerow *tab,  DdNode *node); | 
					
						
							|  |  |  | void add_node(tablerow *tab, DdNode *node, double value); | 
					
						
							|  |  |  | void destroy_table(tablerow *tab, int nbvars); | 
					
						
							|  |  |  | 
 |