}
- /** Thie method tells whether the repair needs to remove objects *
+ /** This method tells whether the repair needs to remove objects *
* from the relation, or whether the model definition rules make
* the remove unnecessary.*/
return !ConstraintDependence.rulesensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(), true);
}
+ /** This method tells whether the repair needs to force the
+ * relation to be function-like. */
+
+ public boolean mayNeedFunctionEnforcement(State state) {
+ assert type==MODIFYRELATION;
+ SetDescriptor sd=getPredicate().getPredicate().inverted()?getRangeSet():getDomainSet();
+ if (ConstraintDependence.rulesensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(), false))
+ return false;
+ if (ConstraintDependence.constraintsensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted()))
+ return false;
+ return true;
+ }
+
public AbstractRepair(DNFPredicate dp,int typ, Descriptor d, Sources s) {
torepair=dp;
type=typ;
if (rulesensurefunction(state,f,false))
continue; //no constraint needed to ensure
- Set s=providesfunction(f);
+ Set s=providesfunction(state,f);
if (s.size()==0) {
System.out.println("Warning: No constraint ensures that [forall v in "+f.getSet()+"], size(v."+(f.isInverse()?"~":"")+f.getRelation()+")=1");
continue;
return foundrule;
}
- private Set providesfunction(Function f) {
+ static private Set providesfunction(State state, Function f) {
HashSet set=new HashSet();
for(int i=0;i<state.vConstraints.size();i++) {
Constraint c=(Constraint)state.vConstraints.get(i);
return rulesensurefunction(state, new Function(r,sd,inverse,null),isPartial);
}
+ /** This method determines whether the model constraints ensure
+ * that the relation r (or inverse relation if inverse is true)
+ * evaluated on the domain sd is either a function (if
+ * isPartial=false) or a partial function (if isPartial=true). */
+
+ static public boolean constraintsensurefunction(State state,RelationDescriptor r, SetDescriptor sd,boolean inverse) {
+ Set constraints=providesfunction(state, new Function(r,sd,inverse,null));
+ return (!constraints.isEmpty());
+ }
+
public static class Function {
private RelationDescriptor rd;
private SetDescriptor sd;
cr.outputline("if (maybe)");
cr.startblock();
cr.outputline("printf(\"maybe fail " + escape(constraint.toString()) + ". \\n\");");
- cr.outputline("exit(1);");
+ //cr.outputline("exit(1);");
cr.endblock();
cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
}
} else {
/* Start with scheduling removal */
-
if (ar.needsRemoves(state))
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);