/** * Create a new object condition with the given constraints. * Also adds mappings corresponding to bound constraints (if any). * @param type The object type. * @param constraints The constraints (if any). */ public ObjectCondition createObjectCondition(OAVObjectType type, IConstraint[] constraints) { ObjectCondition ocon = new ObjectCondition(type); for(int i=0; constraints!=null && i<constraints.length; i++) { ocon.addConstraint(constraints[i]); } addCondition(ocon); return ocon; }
/** * Push a condition on the stack. */ public void pushCondition(ConstrainableCondition con) { if(getDefiningScope(con)!=this) { if(con instanceof ObjectCondition) { // Create clone of inconsistent condition in inner scope. ObjectCondition ocon = (ObjectCondition)con; generateVariableBinding(ocon, null); // new null bound constraint to make sure that cloned condition refers to SAME object. con = createObjectCondition(ocon.getObjectType(), (IConstraint[])ocon.getConstraints().toArray(new IConstraint[ocon.getConstraints().size()])); } else { throw new RuntimeException("Wrong scope: "+con); } } if(oconstack==null) { oconstack = new ArrayList(); } oconstack.add(con); }
ret = ((ObjectCondition)cond).getObjectType();
/** * Get the string representation. * @return The string representation. */ public String toString() { StringBuffer ret = new StringBuffer(); ret.append("("); ret.append(type.getName()); for(int i=0; i<getConstraints().size(); i++) { ret.append(" "); ret.append(getConstraints().get(i).toString());//+"\n"); } ret.append(")"); return ret.toString(); } }
/** * Expressions, which are unrelated to real object * conditions should be bound to the dummy condition. * After building all constraints, the dummy condition * will be removed by reassigning its constraints to * a suitable object condition (respecting variable assignment order). */ public ObjectCondition getDummyCondition() { if(dummy==null) { dummy = new ObjectCondition(OAVJavaType.java_object_type); addCondition(dummy); } return dummy; }
/** * Test if all needed variables are available from the condition directly. * All variables must be declared as BoundConstraints with equal operator * in this object condition. * @return True, if can be evaluated in alpha network. */ protected boolean isAlphaExecutable(ICondition cond, IConstraint c) { boolean ret = cond instanceof ObjectCondition; if(ret) { Set available = new HashSet(); ObjectCondition ocond = (ObjectCondition)cond; List consts = ocond.getBoundConstraints(); for(int i = 0; i < consts.size(); i++) { BoundConstraint bc = (BoundConstraint)consts.get(i); if(bc.getOperator().equals(IOperator.EQUAL) && available.containsAll(Constraint.getVariablesForValueSource(bc.getValueSource()))) { available.addAll(bc.getBindVariables()); } } ret = available.containsAll(c.getVariables()); } return ret; }
ret = ((ObjectCondition)cond).getObjectType();
/** * Get the string representation. * @return The string representation. */ public String toString() { StringBuffer ret = new StringBuffer(); ret.append("("); ret.append(type.getName()); for(int i=0; i<getConstraints().size(); i++) { ret.append(" "); ret.append(getConstraints().get(i).toString());//+"\n"); } ret.append(")"); return ret.toString(); } }
/** * Expressions, which are unrelated to real object * conditions should be bound to the dummy condition. * After building all constraints, the dummy condition * will be removed by reassigning its constraints to * a suitable object condition (respecting variable assignment order). */ public ObjectCondition getDummyCondition() { if(dummy==null) { dummy = new ObjectCondition(OAVJavaType.java_object_type); addCondition(dummy); } return dummy; }
/** * Test if all needed variables are available from the condition directly. * All variables must be declared as BoundConstraints with equal operator * in this object condition. * @return True, if can be evaluated in alpha network. */ protected boolean isAlphaExecutable(ICondition cond, IConstraint c) { boolean ret = cond instanceof ObjectCondition; if(ret) { Set available = new HashSet(); ObjectCondition ocond = (ObjectCondition)cond; List consts = ocond.getBoundConstraints(); for(int i = 0; i < consts.size(); i++) { BoundConstraint bc = (BoundConstraint)consts.get(i); if(bc.getOperator().equals(IOperator.EQUAL) && available.containsAll(Constraint.getVariablesForValueSource(bc.getValueSource()))) { available.addAll(bc.getBindVariables()); } } ret = available.containsAll(c.getVariables()); } return ret; }
/** * Create a new object condition with the given constraints. * Also adds mappings corresponding to bound constraints (if any). * @param type The object type. * @param constraints The constraints (if any). */ public ObjectCondition createObjectCondition(OAVObjectType type, IConstraint[] constraints) { ObjectCondition ocon = new ObjectCondition(type); for(int i=0; constraints!=null && i<constraints.length; i++) { ocon.addConstraint(constraints[i]); } addCondition(ocon); return ocon; }
/** * Push a condition on the stack. */ public void pushCondition(ConstrainableCondition con) { if(getDefiningScope(con)!=this) { if(con instanceof ObjectCondition) { // Create clone of inconsistent condition in inner scope. ObjectCondition ocon = (ObjectCondition)con; generateVariableBinding(ocon, null); // new null bound constraint to make sure that cloned condition refers to SAME object. con = createObjectCondition(ocon.getObjectType(), (IConstraint[])ocon.getConstraints().toArray(new IConstraint[ocon.getConstraints().size()])); } else { throw new RuntimeException("Wrong scope: "+con); } } if(oconstack==null) { oconstack = new ArrayList(); } oconstack.add(con); }
mfv.setType(first.getObjectType()); List consts = new ArrayList(); consts.add(new BoundConstraint(null, mfv));
if(context.hasDummyCondition()) List cons = context.getDummyCondition().getConstraints(); for(int i=0; i<lcons.size(); i++)
/** * Create the goal failed rule (when no plans available). * (state = nocandidates, recur = false) */ protected static Rule createGoalFailedRule() { Variable rgoal = new Variable("?rgoal", OAVBDIRuntimeModel.goal_type); ObjectCondition goalcon = new ObjectCondition(OAVBDIRuntimeModel.goal_type); goalcon.addConstraint(new BoundConstraint(null, rgoal)); goalcon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.processableelement_has_state, OAVBDIRuntimeModel.PROCESSABLEELEMENT_NOCANDIDATES)); goalcon.addConstraint(new LiteralConstraint(new OAVAttributeType[]{OAVBDIRuntimeModel.element_has_model, OAVBDIMetaModel.goal_has_recur}, Boolean.FALSE)); Rule goal_failed = new Rule("goal_failed", goalcon, GOAL_FAILED); return goal_failed; }
OAVObjectType type = oc.getObjectType(); OAVObjectType mtype = (OAVObjectType)OAVBDIRuntimeModel.modelmap.get(type); check = type instanceof OAVJavaType || types.contains(type) List cons = oc.getConstraints(); for(int c=0; check && cons!=null && c<cons.size(); c++)
mfv.setType(first.getObjectType()); List consts = new ArrayList(); consts.add(new BoundConstraint(null, mfv));
if(context.hasDummyCondition()) List cons = context.getDummyCondition().getConstraints(); for(int i=0; i<lcons.size(); i++)
/** * Create the plan context invalid rule. * @param usercond The ADF part of the target condition. * @param mplan The plan model element. */ public static Object[] createPlanContextInvalidUserRule(Object mplan) { Variable rplan = new Variable("?rplan", OAVBDIRuntimeModel.plan_type); Variable rcapa = new Variable("?rcapa", OAVBDIRuntimeModel.capability_type); ObjectCondition plancon = new ObjectCondition(OAVBDIRuntimeModel.plan_type); plancon.addConstraint(new BoundConstraint(null, rplan)); plancon.addConstraint(new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, mplan)); ObjectCondition capcon = new ObjectCondition(OAVBDIRuntimeModel.capability_type); capcon.addConstraint(new BoundConstraint(null, rcapa)); capcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_plans, rplan, IOperator.CONTAINS)); return new Object[]{new AndCondition(new ICondition[]{plancon, capcon}), PLAN_ABORT, null, null, Boolean.TRUE}; }
List constraints = new ArrayList(((ObjectCondition)con).getConstraints()); progress = true; while(progress) BoundConstraint bc = new BoundConstraint(null, new Variable(context.generateVariableName(),((ObjectCondition)con).getObjectType(), false, true)); List constraints2 = new ArrayList(((ObjectCondition)con).getConstraints()); constraints2.removeAll(constraints); constraints.add(bc); constraints2.add(bc); context.getConditions().remove(con); context.createObjectCondition(((ObjectCondition)con).getObjectType(), (IConstraint[])constraints2.toArray(new IConstraint[constraints2.size()])); context.createObjectCondition(((ObjectCondition)con).getObjectType(), (IConstraint[])constraints.toArray(new IConstraint[constraints.size()])); shuffle(context);