2 #include "ActionNotInSet.h"
4 #include "normalizer.h"
9 #include "ActionInSet.h"
11 ActionNotInSet::ActionNotInSet(DomainRelation *drel, model *m) {
16 void ActionNotInSet::repairpredicate(Hashtable *env,CoercePredicate *p) {
17 Element *ele=(Element*) env->get(p->getpredicate()->getlabel()->label());
18 switch(p->getpredicate()->getsetexpr()->gettype()) {
20 domrelation->delfromsetmovetoset(ele, domrelation->getset(p->getpredicate()->getsetexpr()->getsetlabel()->getname()),globalmodel);
23 Element *key=(Element*) env->get(p->getpredicate()->getsetexpr()->getlabel()->label());
24 domrelation->getrelation(p->getpredicate()->getsetexpr()->getrelation()->getname())->getrelation()->remove(key,ele);
27 case SETEXPR_INVREL: {
28 Element *key=(Element*) env->get(p->getpredicate()->getsetexpr()->getlabel()->label());
29 domrelation->getrelation(p->getpredicate()->getsetexpr()->getrelation()->getname())->getrelation()->remove(ele,key);
38 void ActionNotInSet::breakpredicate(Hashtable *env, CoercePredicate *p)
41 printf("ActionNotInSet::breakpredicate CALLED\n");
42 p->getpredicate()->print(); printf("\n");
45 ActionInSet *a = new ActionInSet(domrelation, globalmodel);
46 a->repairpredicate(env, p);
52 bool ActionNotInSet::conflict(Constraint *c1, CoercePredicate *p1,Constraint *c2, CoercePredicate *p2) {
53 assert(canrepairpredicate(p1));
54 if(comparepredicates(c1,p1,c2,p2))
55 return false; /*same predicates don't conflict*/
56 Setexpr *pse=p1->getpredicate()->getsetexpr();
57 switch(pse->gettype()) {
59 /* Go through the sets we add something to */
61 WorkSet *ws=domrelation->removeconflictaddsets(pse->getsetlabel()->getname(),globalmodel);
62 DomainSet *ds=(DomainSet *)ws->firstelement();
64 if (conflictwithaddtoset(ds->getname(),c2,p2)) {
68 ds=(DomainSet *)ws->getnextelement(ds);
73 WorkSet *ws=domrelation->removeconflictdelsets(pse->getsetlabel()->getname());
74 DomainSet *ds=(DomainSet *)ws->firstelement();
76 if (conflictwithremovefromset(NULL,ds->getname(),c2,p2)) {
80 ds=(DomainSet *)ws->getnextelement(ds);
88 /* we have !a in v.r */
89 /* remove <v,a> to r */
90 return testforconflictremove(getset(c1,p1->getpredicate()->getsetexpr()->getlabel()->label()),
91 getset(c1,p1->getpredicate()->getlabel()->label()),
92 p1->getpredicate()->getsetexpr()->getrelation()->getname(),c2,p2);
94 /* we have !a in v.r */
95 /* remove <v,a> to r */
96 return testforconflictremove(getset(c1,p1->getpredicate()->getlabel()->label()),
97 getset(c1,p1->getpredicate()->getsetexpr()->getlabel()->label()),
98 p1->getpredicate()->getsetexpr()->getrelation()->getname(),c2,p2);
102 bool ActionNotInSet::canrepairpredicate(CoercePredicate *cp) {
103 if (cp->getcoercebool()==true)
105 Predicate *p=cp->getpredicate();
108 if (p->gettype()!=PREDICATE_SET)
110 Setexpr *se=p->getsetexpr();
111 int setexprtype=se->gettype();
112 if (setexprtype==SETEXPR_REL||
113 setexprtype==SETEXPR_INVREL) {
114 DRelation *dr=domrelation->getrelation(se->getrelation()->getname());
116 return false; /* Can't change static domain relations */
119 /* Coercing set membership */