4 class AbstractInterferes {
5 Termination termination;
7 public AbstractInterferes(Termination t) {
11 /** Does performing the AbstractRepair ar satisfy (or falsify if satisfy=false)
14 static public boolean interfereswithrule(AbstractRepair ar, Rule r, boolean satisfy) {
16 boolean mayremove=false;
17 switch (ar.getType()) {
18 case AbstractRepair.ADDTOSET:
19 case AbstractRepair.ADDTORELATION:
20 if (interferesquantifier(ar.getDescriptor(), true, r, satisfy))
24 case AbstractRepair.REMOVEFROMSET:
25 case AbstractRepair.REMOVEFROMRELATION:
26 if (interferesquantifier(ar.getDescriptor(), false, r, satisfy))
30 case AbstractRepair.MODIFYRELATION:
31 if (interferesquantifier(ar.getDescriptor(), true, r, satisfy))
33 if (interferesquantifier(ar.getDescriptor(), false, r, satisfy))
39 throw new Error("Unrecognized Abstract Repair");
43 drule=r.getDNFGuardExpr();
45 drule=r.getDNFNegGuardExpr();
47 for(int i=0;i<drule.size();i++) {
48 RuleConjunction rconj=drule.get(i);
49 for(int j=0;j<rconj.size();j++) {
50 DNFExpr dexpr=rconj.get(j);
51 Expr expr=dexpr.getExpr();
52 if (expr.usesDescriptor(ar.getDescriptor())) {
54 if ((mayadd&&!dexpr.getNegation())||(mayremove&&dexpr.getNegation()))
62 public boolean checkrelationconstraint(AbstractRepair ar, Constraint c) {
63 if (c.numQuantifiers()==1&&
64 (c.getQuantifier(0) instanceof RelationQuantifier)) {
65 RelationQuantifier rq=(RelationQuantifier)c.getQuantifier(0);
66 if (rq.getRelation()==ar.getDescriptor()) {
67 Hashtable ht=new Hashtable();
68 if (ar.getDomainSet()!=null)
69 ht.put(rq.x,ar.getDomainSet());
70 if (ar.getRangeSet()!=null)
71 ht.put(rq.y,ar.getRangeSet());
72 DNFConstraint dconst=c.dnfconstraint;
74 for(int i=0;i<dconst.size();i++) {
75 Conjunction conj=dconst.get(i);
77 for(int j=0;j<conj.size();j++) {
78 DNFPredicate dpred=conj.get(j);
79 Predicate p=dpred.getPredicate();
80 if ((p instanceof InclusionPredicate)&&(!dpred.isNegated())) {
81 InclusionPredicate ip=(InclusionPredicate)p;
82 if (ip.expr instanceof VarExpr&&
83 ip.setexpr.getDescriptor() instanceof SetDescriptor) {
84 VarDescriptor vd=((VarExpr)ip.expr).getVar();
85 if (ht.containsKey(vd)) {
86 SetDescriptor td=(SetDescriptor)ip.setexpr.getDescriptor();
87 SetDescriptor s=(SetDescriptor)ht.get(vd);
102 /** Does performing the AbstractRepair ar falsify the predicate dp */
104 public boolean interfereswithpredicate(AbstractRepair ar, DNFPredicate dp) {
105 if ((ar.getDescriptor()!=dp.getPredicate().getDescriptor()) &&
106 ((ar.getDescriptor() instanceof SetDescriptor)||
107 !dp.getPredicate().usesDescriptor((RelationDescriptor)ar.getDescriptor())))
110 /* This if handles all the c comparisons in the paper */
111 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
112 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
113 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
114 (dp.getPredicate() instanceof ExprPredicate)&&
115 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
116 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
117 boolean neg1=ar.getPredicate().isNegated();
118 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
119 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
120 boolean neg2=dp.isNegated();
121 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
122 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
123 op1=Opcode.translateOpcode(neg1,op1);
124 op2=Opcode.translateOpcode(neg2,op2);
126 if ((op1==Opcode.EQ)||(op1==Opcode.NE)||(op1==Opcode.GT)||op1==Opcode.GE) {
128 if((op1==Opcode.EQ)||(op1==Opcode.GE))
130 if((op1==Opcode.GT)||(op1==Opcode.NE))
133 if (((op2==Opcode.EQ)&&(size1a==size2))||
134 ((op2==Opcode.NE)&&(size1a!=size2))||
137 ((op2==Opcode.LE)&&(size1a<=size2))||
138 ((op2==Opcode.LT)&&(size1a<size2)))
142 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
143 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
144 (dp.getPredicate() instanceof ExprPredicate)&&
145 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
146 boolean neg2=dp.isNegated();
147 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
148 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
150 op2=Opcode.translateOpcode(neg2,op2);
152 int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
155 ((op2==Opcode.LT&&size2>maxsize)||
156 (op2==Opcode.LE&&size2>=maxsize)||
157 (op2==Opcode.EQ&&size2>=maxsize)))
160 if (((op2==Opcode.NE)&&(size2==0))||
165 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
166 (ar.getType()==AbstractRepair.MODIFYRELATION)&&
167 (dp.getPredicate() instanceof ExprPredicate)&&
168 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
169 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.COMPARISON)) {
171 boolean neg1=ar.getPredicate().isNegated();
172 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
173 boolean isInt1=((ExprPredicate)ar.getPredicate().getPredicate()).isRightInt();
174 int size1=isInt1?((ExprPredicate)ar.getPredicate().getPredicate()).rightSize():0;
175 Expr expr1=((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).right;
178 boolean neg2=dp.isNegated();
179 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
180 boolean isInt2=((ExprPredicate)dp.getPredicate()).isRightInt();
181 int size2=isInt2?((ExprPredicate)dp.getPredicate()).rightSize():0;
182 Expr expr2=((OpExpr)((ExprPredicate)dp.getPredicate()).expr).right;
185 Expr lexpr1=((RelationExpr)((OpExpr)((ExprPredicate)ar.getPredicate().getPredicate()).expr).getLeftExpr()).getExpr();
186 Expr lexpr2=((RelationExpr)((OpExpr)((ExprPredicate)dp.getPredicate()).expr).getLeftExpr()).getExpr();
187 SetDescriptor sd1=lexpr1.getSet();
188 SetDescriptor sd2=lexpr2.getSet();
189 if (termination.mutuallyexclusive(sd1,sd2))
193 /* Translate the opcodes */
194 op1=Opcode.translateOpcode(neg1,op1);
195 op2=Opcode.translateOpcode(neg2,op2);
197 /* Obvious cases which can't interfere */
198 if (((op1==Opcode.GT)||
203 if (((op1==Opcode.LT)||
208 if (((op1==Opcode.EQ)||(op1==Opcode.GE)||(op1==Opcode.LE))&&
209 ((op2==Opcode.EQ)||(op2==Opcode.GE)||(op2==Opcode.LE))&&
210 expr1.equals(null,expr2)) {
213 if (isInt1&&isInt2) {
214 if (((op1==Opcode.EQ)||(op1==Opcode.GE)||(op1==Opcode.LE))&&
215 ((op2==Opcode.EQ)||(op2==Opcode.GE)||(op2==Opcode.LE))&&
225 size1a++; /*FLAGNE this is current behavior for NE repairs */
231 if (((op1==Opcode.GE)||(op1==Opcode.GT))&&
232 ((op2==Opcode.LE)||(op2==Opcode.EQ)||(op2==Opcode.LT))&&
235 if (((op1==Opcode.LE)||(op1==Opcode.LT))&&
236 ((op2==Opcode.GE)||(op2==Opcode.EQ)||(op2==Opcode.GT))&&
239 if ((op1==Opcode.EQ)&&(op2==Opcode.EQ)&&
242 if ((op1==Opcode.EQ)&&
243 ((op2==Opcode.LE)||(op2==Opcode.LT))&&
246 if ((op1==Opcode.EQ)&&
247 ((op2==Opcode.GE)||(op2==Opcode.GT))&&
250 if (op2==Opcode.NE) /*FLAGNE this is current behavior for NE repairs */
253 if ((op1==Opcode.NE)&&
257 if ((op1==Opcode.NE)&& /* FLAGNE relies on increasing or decreasing by 1 */
258 ((op2==Opcode.GT)||(op2==Opcode.GE))&&
261 if ((op1==Opcode.NE)&& /* FLAGNE relies on increasing or decreasing by 1 */
262 ((op2==Opcode.LT)||(op2==Opcode.LE))&&
267 /* This handles all the c comparisons in the paper */
268 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
269 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
270 (ar.getPredicate().getPredicate() instanceof ExprPredicate)&&
271 (dp.getPredicate() instanceof ExprPredicate)&&
272 (dp.getPredicate().inverted()==ar.getPredicate().getPredicate().inverted())&&
273 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
274 boolean neg1=ar.getPredicate().isNegated();
275 Opcode op1=((ExprPredicate)ar.getPredicate().getPredicate()).getOp();
276 int size1=((ExprPredicate)ar.getPredicate().getPredicate()).rightSize();
277 boolean neg2=dp.isNegated();
278 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
279 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
280 /* Translate the opcodes */
281 op1=Opcode.translateOpcode(neg1,op1);
282 op2=Opcode.translateOpcode(neg2,op2);
284 if (((op1==Opcode.EQ)||(op1==Opcode.LT)||op1==Opcode.LE)||(op1==Opcode.NE)) {
287 if((op1==Opcode.EQ)||(op1==Opcode.LE))
289 if((op1==Opcode.LT)||(op1==Opcode.NE))
292 if (((op2==Opcode.EQ)&&(size1a==size2))||
293 ((op2==Opcode.NE)&&(size1a!=size2))||
296 ((op2==Opcode.GE)&&(size1a>=size2))||
297 ((op2==Opcode.GT)&&(size1a>size2)))
302 if (ar.getDescriptor()==dp.getPredicate().getDescriptor()&&
303 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
304 (dp.getPredicate() instanceof ExprPredicate)&&
305 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
306 boolean neg2=dp.isNegated();
307 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
308 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
309 op2=Opcode.translateOpcode(neg2,op2);
311 if (((op2==Opcode.EQ)&&(size2==0))||
316 if ((ar.getDescriptor()==dp.getPredicate().getDescriptor())&&
317 (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)&&
318 (dp.getPredicate() instanceof InclusionPredicate)&&
319 (dp.isNegated()==false))
320 return false; /* Could only satisfy this predicate */
322 if ((ar.getDescriptor()==dp.getPredicate().getDescriptor())&&
323 (ar.getType()==AbstractRepair.REMOVEFROMSET||ar.getType()==AbstractRepair.REMOVEFROMRELATION)&&
324 (dp.getPredicate() instanceof InclusionPredicate)&&
325 (dp.isNegated()==true))
326 return false; /* Could only satisfy this predicate */
330 /** Does the increase (or decrease) in scope of a model defintion
331 * rule represented by sn falsify the predicate dp. */
333 public boolean scopeinterfereswithpredicate(ScopeNode sn, DNFPredicate dp) {
334 if (!sn.getSatisfy()&&(sn.getDescriptor() instanceof SetDescriptor)) {
336 Set target=r.getInclusion().getTargetDescriptors();
338 for(int i=0;i<r.numQuantifiers();i++) {
339 Quantifier q=r.getQuantifier(i);
340 if (q instanceof SetQuantifier) {
341 SetQuantifier sq=(SetQuantifier) q;
342 if (target.contains(sq.getSet())) {
349 sn.getDescriptor()==dp.getPredicate().getDescriptor()&&
350 (dp.getPredicate() instanceof ExprPredicate)&&
351 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
352 boolean neg=dp.isNegated();
353 Opcode op=((ExprPredicate)dp.getPredicate()).getOp();
354 int size=((ExprPredicate)dp.getPredicate()).rightSize();
355 op=Opcode.translateOpcode(neg,op);
357 if ((op==Opcode.GE)&&
358 ((size==0)||(size==1)))
360 if ((op==Opcode.GT)&&
365 return interferes(sn.getDescriptor(), sn.getSatisfy(),dp);
368 /** Does increasing (or decreasing if satisfy=false) the size of
369 * the set or relation des falsify the predicate dp. */
371 private boolean interferes(Descriptor des, boolean satisfy, DNFPredicate dp) {
372 if ((des!=dp.getPredicate().getDescriptor()) &&
373 ((des instanceof SetDescriptor)||
374 !dp.getPredicate().usesDescriptor((RelationDescriptor)des)))
377 /* This if handles all the c comparisons in the paper */
378 if (des==dp.getPredicate().getDescriptor()&&
380 (dp.getPredicate() instanceof ExprPredicate)&&
381 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
382 boolean neg2=dp.isNegated();
383 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
384 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
385 op2=Opcode.translateOpcode(neg2,op2);
388 int maxsize=termination.maxsize.getsize(dp.getPredicate().getDescriptor());
391 ((op2==Opcode.LT&&size2>maxsize)||
392 (op2==Opcode.LE&&size2>=maxsize)||
393 (op2==Opcode.EQ&&size2>=maxsize)))
396 if ((op2==Opcode.GE)||
398 (op2==Opcode.NE)&&(size2==0))
402 /* This if handles all the c comparisons in the paper */
403 if (des==dp.getPredicate().getDescriptor()&&
405 (dp.getPredicate() instanceof ExprPredicate)&&
406 (((ExprPredicate)dp.getPredicate()).getType()==ExprPredicate.SIZE)) {
407 boolean neg2=dp.isNegated();
408 Opcode op2=((ExprPredicate)dp.getPredicate()).getOp();
409 int size2=((ExprPredicate)dp.getPredicate()).rightSize();
410 op2=Opcode.translateOpcode(neg2,op2);
412 if (((op2==Opcode.EQ)&&(size2==0))||
418 if ((des==dp.getPredicate().getDescriptor())&&
420 (dp.getPredicate() instanceof InclusionPredicate)&&
421 (dp.isNegated()==false))
422 return false; /* Could only satisfy this predicate */
424 if ((des==dp.getPredicate().getDescriptor())&&
426 (dp.getPredicate() instanceof InclusionPredicate)&&
427 (dp.isNegated()==true))
428 return false; /* Could only satisfy this predicate */
433 /** This method test whether satisfying (or falsifying depending
434 * on the flag satisfy) a rule that adds an object(or tuple) to
435 * the set(or relation) descriptor may increase (or decrease
436 * depending on the flag satisfyrule) the scope of a constraint or
437 * model defintion rule r. */
439 static private boolean interferesquantifier(Descriptor des, boolean satisfy, Quantifiers r, boolean satisfyrule) {
440 for(int i=0;i<r.numQuantifiers();i++) {
441 Quantifier q=r.getQuantifier(i);
442 if (q instanceof RelationQuantifier||q instanceof SetQuantifier) {
443 if (q.getRequiredDescriptors().contains(des)&&(satisfy==satisfyrule))
445 } else if (q instanceof ForQuantifier) {
446 if (q.getRequiredDescriptors().contains(des))
448 } else throw new Error("Unrecognized Quantifier");
453 static public boolean interferesquantifier(AbstractRepair ar, Quantifiers q) {
454 if (ar.getType()==AbstractRepair.ADDTOSET||ar.getType()==AbstractRepair.ADDTORELATION)
455 return interferesquantifier(ar.getDescriptor(),true,q,true);
459 static public boolean interfereswithquantifier(Descriptor des, boolean satisfy, Quantifiers q) {
460 return interferesquantifier(des, satisfy, q,true);
463 static public boolean interfereswithrule(Descriptor des, boolean satisfy, Rule r, boolean satisfyrule) {
464 if (interferesquantifier(des,satisfy,r,satisfyrule))
467 DNFRule drule=r.getDNFGuardExpr();
468 for(int i=0;i<drule.size();i++) {
469 RuleConjunction rconj=drule.get(i);
470 for(int j=0;j<rconj.size();j++) {
471 DNFExpr dexpr=rconj.get(j);
472 Expr expr=dexpr.getExpr();
473 boolean negated=dexpr.getNegation();
481 boolean satisfiesrule=(satisfy^negated);/*XOR of these */
482 if (satisfiesrule==satisfyrule) {
483 /* Effect is the one being tested for */
484 /* Only expr's to be concerned with are TupleOfExpr and
486 if (expr.getRequiredDescriptors().contains(des)) {
487 if (((expr instanceof ElementOfExpr)||
488 (expr instanceof TupleOfExpr))&&
489 (expr.getRequiredDescriptors().size()==1))
492 throw new Error("Unrecognized EXPR");