2 #include "ActionInSet.h"
5 #include "normalizer.h"
10 #include "ActionNotInSet.h"
12 ActionInSet::ActionInSet(DomainRelation *drel,model *m) {
17 void ActionInSet::repairpredicate(Hashtable *env,CoercePredicate *p) {
18 Element *ele=(Element*) env->get(p->getpredicate()->getlabel()->label());
19 switch(p->getpredicate()->getsetexpr()->gettype()) {
21 domrelation->addtoset(ele, domrelation->getset(p->getpredicate()->getsetexpr()->getsetlabel()->getname()),
25 Element *key=(Element*) env->get(p->getpredicate()->getsetexpr()->getlabel()->label());
26 domrelation->getrelation(p->getpredicate()->getsetexpr()->getrelation()->getname())->getrelation()->put(key,ele);
27 char *rangename=domrelation->getrelation(p->getpredicate()->getsetexpr()->getrelation()->getname())->getrange();
28 if (!equivalentstrings(rangename,"int")) {
29 DomainSet *range=domrelation->getset(rangename);
30 if (!range->getset()->contains(ele))
31 domrelation->addtoset(ele,range,globalmodel);
35 case SETEXPR_INVREL: {
36 Element *key=(Element*) env->get(p->getpredicate()->getsetexpr()->getlabel()->label());
37 domrelation->getrelation(p->getpredicate()->getsetexpr()->getrelation()->getname())->getrelation()->put(ele,key);
38 char *domainname=domrelation->getrelation(p->getpredicate()->getsetexpr()->getrelation()->getname())->getdomain();
39 if (!equivalentstrings(domainname,"int")) {
40 DomainSet *domain=domrelation->getset(domainname);
41 if (!domain->getset()->contains(ele))
42 domrelation->addtoset(ele,domain,globalmodel);
51 void ActionInSet::breakpredicate(Hashtable *env,CoercePredicate *p)
54 printf("ActionInSet::breakpredicate CALLED\n");
55 p->getpredicate()->print(); printf("\n");
58 ActionNotInSet *a = new ActionNotInSet(domrelation, globalmodel);
59 a->repairpredicate(env, p);
64 bool ActionInSet::conflict(Constraint *c1, CoercePredicate *p1,Constraint *c2, CoercePredicate *p2) {
65 assert(canrepairpredicate(p1));
66 if(comparepredicates(c1,p1,c2,p2))
67 return false; /*same predicates don't conflict*/
68 Setexpr *pse=p1->getpredicate()->getsetexpr();
69 switch(pse->gettype()) {
71 /* Compute bounding set if there is one */
72 char *boundname=calculatebound(c1,p1->getpredicate()->getlabel());
73 /* Check conflicts arrising from addition to set */
75 WorkSet *ws=domrelation->conflictaddsets(pse->getsetlabel()->getname(),boundname,globalmodel);
76 DomainSet *ds=(DomainSet *) ws->firstelement();
78 if (conflictwithaddtoset(ds->getname(),c2,p2)) {
82 ds=(DomainSet *) ws->getnextelement(ds);
86 /* Check conflicts arrising from deletions from set */
88 WorkSet *ws=domrelation->conflictdelsets(pse->getsetlabel()->getname(), boundname);
89 DomainSet *ds=(DomainSet *) ws->firstelement();
91 if (conflictwithremovefromset(NULL,ds->getname(),c2,p2)) {
95 ds=(DomainSet *) ws->getnextelement(ds);
103 /* Compute bounding set if there is one */
104 char *boundname=calculatebound(c1,p1->getpredicate()->getlabel());
105 DomainRelation *drel=globalmodel->getdomainrelation();
106 char *insertset=drel->getrelation(pse->getrelation()->getname())->getrange();
108 /* Check conflicts arrising from addition to set */
110 WorkSet *ws=domrelation->conflictaddsets(insertset,boundname,globalmodel);
111 DomainSet *ds=(DomainSet *) ws->firstelement();
113 if (conflictwithaddtoset(ds->getname(),c2,p2)) {
117 ds=(DomainSet *) ws->getnextelement(ds);
121 /* Check conflicts arrising from deletions from set */
123 WorkSet *ws=domrelation->conflictdelsets(insertset, boundname);
124 DomainSet *ds=(DomainSet *) ws->firstelement();
126 if (conflictwithremovefromset(NULL,ds->getname(),c2,p2)) {
130 ds=(DomainSet *) ws->getnextelement(ds);
135 /* we have a in v.r */
137 return testforconflict(getset(c1,p1->getpredicate()->getsetexpr()->getlabel()->label()),
138 getset(c1,p1->getpredicate()->getlabel()->label()),
139 p1->getpredicate()->getsetexpr()->getrelation()->getname(),c2,p2);
141 case SETEXPR_INVREL: {
142 /* Compute bounding set if there is one */
143 char *boundname=calculatebound(c1,p1->getpredicate()->getlabel());
144 DomainRelation *drel=globalmodel->getdomainrelation();
145 char *insertset=drel->getrelation(pse->getrelation()->getname())->getdomain();
147 /* Check conflicts arrising from addition to set */
149 WorkSet *ws=domrelation->conflictaddsets(insertset,boundname,globalmodel);
150 DomainSet *ds=(DomainSet *) ws->firstelement();
152 if (conflictwithaddtoset(ds->getname(),c2,p2)) {
156 ds=(DomainSet *) ws->getnextelement(ds);
160 /* Check conflicts arrising from deletions from set */
162 WorkSet *ws=domrelation->conflictdelsets(insertset, boundname);
163 DomainSet *ds=(DomainSet *) ws->firstelement();
165 if (conflictwithremovefromset(NULL,ds->getname(),c2,p2)) {
169 ds=(DomainSet *) ws->getnextelement(ds);
174 return testforconflict(getset(c1,p1->getpredicate()->getlabel()->label()),
175 getset(c1,p1->getpredicate()->getsetexpr()->getlabel()->label()),
176 p1->getpredicate()->getsetexpr()->getrelation()->getname(),c2,p2);
181 bool ActionInSet::canrepairpredicate(CoercePredicate *cp) {
182 if (cp->getcoercebool()==false)
184 Predicate *p=cp->getpredicate();
187 if (p->gettype()!=PREDICATE_SET)
189 Setexpr *se=p->getsetexpr();
190 int setexprtype=se->gettype();
191 if (setexprtype==SETEXPR_REL||
192 setexprtype==SETEXPR_INVREL) {
193 DRelation *dr=domrelation->getrelation(se->getrelation()->getname());
195 return false; /* Can't change static domain relations */
198 /* Coercing set membership */