Change to the spec...missed a consistency property. Adding timing option.
[repair.git] / Repair / RepairInterpreter / ActionNormal.cc
1 #include <assert.h>
2 #include "ActionNormal.h"
3 #include "dmodel.h"
4 #include "normalizer.h"
5 #include "omodel.h"
6 #include "Relation.h"
7 #include "set.h"
8 #include "Hashtable.h"
9 #include "model.h"
10
11 ActionNormal::ActionNormal(model *m) {
12   globalmodel=m;
13   domrelation=m->getdomainrelation();
14 }
15
16 void ActionNormal::repairpredicate(Hashtable *env,CoercePredicate *p) {
17   /* Don't actually repair stuff */
18 }
19
20
21 void ActionNormal::breakpredicate(Hashtable *env, CoercePredicate *p)
22 {
23   /* Don't actually break stuff */
24 }
25
26
27 bool ActionNormal::conflict(Constraint *c1, CoercePredicate *p1,Constraint *c2, CoercePredicate *p2) {
28   if(!p1->isrule()&&
29      !p1->istuple()) {
30     /* Compute bounding set if there is one */
31     char *boundname=p1->getltype();
32     /* Check conflicts arrising from addition to set */
33     {
34       WorkSet *ws=domrelation->conflictaddsets(p1->getrelset(),boundname,globalmodel);
35       DomainSet *ds=(DomainSet *) ws->firstelement();
36       while(ds!=NULL) {
37         if (conflictwithaddtoset(ds->getname(),c2,p2)) {
38           delete(ws);
39           return true;
40         }
41         ds=(DomainSet *) ws->getnextelement(ds);
42       }
43       delete(ws);
44     }
45     /* Check conflicts arrising from deletions from set */
46     {
47       WorkSet *ws=domrelation->conflictdelsets(p1->getrelset(), boundname);
48       DomainSet *ds=(DomainSet *) ws->firstelement();
49       while (ds!=NULL) {
50         if (conflictwithremovefromset(NULL,ds->getname(),c2,p2)) {
51           delete(ws);
52           return true;
53         }
54         ds=(DomainSet *) ws->getnextelement(ds);
55       }
56       delete(ws);
57     }
58     return false;
59   }
60
61   if(!p1->isrule()&&
62      p1->istuple()) {
63     
64     {
65     /* Compute bounding set if there is one */
66     char *boundname=getset(c1,p1->getrtype());
67     DomainRelation *drel=globalmodel->getdomainrelation();
68     char *insertset=drel->getrelation(p1->getrelset())->getrange();
69     
70     /* Check conflicts arrising from addition to set */
71     {
72       WorkSet *ws=domrelation->conflictaddsets(insertset,boundname,globalmodel);
73       DomainSet *ds=(DomainSet *) ws->firstelement();
74       while(ds!=NULL) {
75         if (conflictwithaddtoset(ds->getname(),c2,p2)) {
76           delete(ws);
77           return true;
78         }
79         ds=(DomainSet *) ws->getnextelement(ds);
80       }
81       delete(ws);
82     }
83     /* Check conflicts arrising from deletions from set */
84     {
85       WorkSet *ws=domrelation->conflictdelsets(insertset, boundname);    
86       DomainSet *ds=(DomainSet *) ws->firstelement();
87       while (ds!=NULL) {
88         if (conflictwithremovefromset(NULL,ds->getname(),c2,p2)) {
89           delete(ws);
90           return true;
91         }
92         ds=(DomainSet *) ws->getnextelement(ds);
93       }
94       delete(ws);
95     }
96     }
97     /* Compute bounding set if there is one */
98     char *boundname=getset(c1,p1->getltype());
99     DomainRelation *drel=globalmodel->getdomainrelation();
100     char *insertset=drel->getrelation(p1->getrelset())->getdomain();
101     
102     /* Check conflicts arrising from addition to set */
103     {
104       WorkSet *ws=domrelation->conflictaddsets(insertset,boundname,globalmodel);
105       DomainSet *ds=(DomainSet *) ws->firstelement();
106       while(ds!=NULL) {
107         if (conflictwithaddtoset(ds->getname(),c2,p2)) {
108           delete(ws);
109           return true;
110         }
111         ds=(DomainSet *) ws->getnextelement(ds);
112       }
113       delete(ws);
114     }
115     /* Check conflicts arrising from deletions from set */
116     {
117       WorkSet *ws=domrelation->conflictdelsets(insertset, boundname);    
118       DomainSet *ds=(DomainSet *) ws->firstelement();
119       while (ds!=NULL) {
120         if (conflictwithremovefromset(NULL,ds->getname(),c2,p2)) {
121           delete(ws);
122           return true;
123         }
124         ds=(DomainSet *) ws->getnextelement(ds);
125       }
126       delete(ws);
127     }
128   
129     /* we have a in v.r */
130     /* add <v,a> to r */
131     return testforconflict(getset(c1,p1->getltype()),
132                            getset(c1,p1->getrtype()),
133                            p1->getrelset(),c2,p2);
134   }
135 }
136
137
138 bool ActionNormal::canrepairpredicate(CoercePredicate *cp) {
139   return false; /* Doesn't repair stuff */
140 }