1 /*
2   LPAD and CP-Logic interpreter
3 
4 Copyright (c) 2007, Fabrizio Riguzzi
5 
6 This package uses the library cudd, see http://vlsi.colorado.edu/~fabio/CUDD/
7 for the relative license.
8 
9 */
10 
11 #include "util.h"
12 #include "cuddInt.h"
13 #include "mtr.h"
14 #include "YapInterface.h"
15 
16 typedef struct
17 {
18   int var,value;
19 } factor;
20 
21 typedef struct
22 {
23   int nFact;
24   factor * factors;
25 } term;
26 
27 typedef struct
28 {
29   int nTerms;
30   term * terms;
31 } expr;
32 
33 typedef struct
34 {
35   int nVal,nBit;
36   double * probabilities;
37   DdNode * * booleanVars;
38 } variable;
39 
40 typedef struct
41 {
42   int nVar;
43   int nBVar;
44   variable * varar;
45   int * bVar2mVar;
46 } variables;
47 
48 typedef struct
49 {
50   DdNode *key;
51   double value;
52 } rowel;
53 
54 typedef struct
55 {
56   int cnt;
57   rowel *row;
58 } tablerow;
59 
60 variables createVars(YAP_Term t,DdManager * mgr, int create_dot,
61   char inames[1000][20]);
62 expr createExpression(YAP_Term t);
63 void init_my_predicates(void);
64 
65 DdNode * retFunction(DdManager * mgr, expr expression,variables v);
66 DdNode * retTerm(DdManager * mgr,term t,variables v);
67 DdNode * retFactor(DdManager * mgr, factor f, variables v);
68 
69 double Prob(DdNode *node, variables vars,tablerow * nodes);
70 
71 double ProbBool(DdNode *node, int bits, int nBit,int posBVar,variable v,
72   int mVarIndex,
73   variables vars,tablerow * nodes, int comp);
74 
75 tablerow* init_table(int nbvars);
76 double * get_value(tablerow *tab,  DdNode *node);
77 void add_node(tablerow *tab, DdNode *node, double value);
78 void destroy_table(tablerow *tab, int nbvars);
79 
80