/** * Create a new variable and bind it using the given object condition and value source. * @param condition The object condition. * @param name The variable name. * @param valuesource The value source. * @return The new variable. */ public Variable generateVariableBinding(ConstrainableCondition condition, String name, OAVObjectType type, Object valuesource) { Variable tmpvar = new Variable(name, type, false, true); variables.put(name, tmpvar); BoundConstraint bc = new BoundConstraint(valuesource, tmpvar); boundconstraints.put(tmpvar, bc); condition.addConstraint(bc); bcons.put(tmpvar, condition); return tmpvar; }
&& IOperator.EQUAL.equals(((BoundConstraint)c).getOperator()) && !(((BoundConstraint)c).getValueSource() instanceof MethodCall) && !(((BoundConstraint)c).getValueSource() instanceof FunctionCall) && !(((BoundConstraint)c).getValueSource() instanceof List) && !(((BoundConstraint)c).getValueSource() instanceof OAVAttributeType) OAVObjectType type = bc.getValueSource()!=null ? ((OAVAttributeType)bc.getValueSource()).getType() : cond.getObjectType(); if(!(type instanceof OAVJavaType) || OAVJavaType.KIND_VALUE.equals(((OAVJavaType)type).getKind())) List vars = bc.getBindVariables(); for(int i=0; i<vars.size(); i++) int subindex = bc.isMultiConstraint()? i: -1; IValueExtractor rightex = createValueExtractor(-1, bc.getValueSource(), subindex, context, false); ret.add(new ConstraintIndexer(leftex, rightex));
/** * Get the variables. * @return The declared variables. */ public List getVariables() { if(depvars==null) { List vfvs = getVariablesForValueSource(getValueSource()); if(vfvs.isEmpty()) { depvars = vars; } else if(!vars.isEmpty()) { depvars = new ArrayList(vfvs); depvars.addAll(vars); } else { depvars = Collections.EMPTY_LIST; } } return depvars; }
/** * Get the string representation. * @return The string representation. */ public String toString() { StringBuffer sbuf = new StringBuffer(); sbuf.append("("); sbuf.append(getValueSource()); sbuf.append(getOperator()); if(vars.size()>1) { sbuf.append("("); for(int i=0; i<vars.size(); i++) { sbuf.append(vars.get(i)); } sbuf.append(")"); } else { sbuf.append(vars.get(0)); } sbuf.append(")"); return sbuf.toString(); } }
/** * 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; }
if(bc.getOperator().equals(IOperator.EQUAL)) List bvars = bc.getBindVariables(); for(int k=0; k<bvars.size(); k++) if(c instanceof BoundConstraint && ((BoundConstraint)c).getOperator().equals(IOperator.EQUAL)) List bvars = ((BoundConstraint)c).getBindVariables(); for(int k=0; k<bvars.size(); k++) BoundConstraint bc = new BoundConstraint(null, new Variable(context.generateVariableName(),((ObjectCondition)con).getObjectType(), false, true)); List constraints2 = new ArrayList(((ObjectCondition)con).getConstraints()); constraints2.removeAll(constraints);
if(bc.isMultiConstraint()) List vars = bc.getBindVariables(); String[] binds = new String[vars.size()]; for(int j=0; j<binds.length; j++) binds[j] = ((Variable)vars.get(j)).isMulti()? SplitNode.MULTI: SplitNode.SINGLE; addSplitNode((OAVAttributeType)bc.getValueSource(), binds, context); List vars = ((BoundConstraint)c).getBindVariables(); for(int v=0; firstbound && v<vars.size(); v++)
throw new RuntimeException("Capability condition required to build belief (set) condition: "+name); BoundConstraint bc = context.getBoundConstraint(capvar); if(bc.getValueSource()!=null) throw new UnsupportedOperationException("Value source for capability object not yet supported."); context.createObjectCondition(OAVBDIRuntimeModel.belief_type, new IConstraint[]{ new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, mbel), new BoundConstraint(OAVBDIRuntimeModel.belief_has_fact, ret), new BoundConstraint(null, belvar)}); rcapcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_beliefs, belvar, IOperator.CONTAINS)); context.createObjectCondition(OAVBDIRuntimeModel.beliefset_type, new IConstraint[]{ new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, mbel), new BoundConstraint(valuesource, ret), new BoundConstraint(null, belvar)}); rcapcon.addConstraint(new BoundConstraint(OAVBDIRuntimeModel.capability_has_beliefsets, belvar, IOperator.CONTAINS)); context.createObjectCondition(OAVBDIRuntimeModel.belief_type, new IConstraint[]{ new LiteralConstraint(OAVBDIRuntimeModel.element_has_model, mbel), new BoundConstraint(OAVBDIRuntimeModel.belief_has_fact, ret), new BoundConstraint(null, belvar)}); Variable belcapvar = new Variable(name+"_belcap", OAVBDIRuntimeModel.capability_type, false, true); new BoundConstraint(null, belcapvar), new BoundConstraint(OAVBDIRuntimeModel.capability_has_beliefs, belvar, IOperator.CONTAINS), new LiteralReturnValueConstraint(Boolean.TRUE, new FunctionCall(new ResolvesTo(), new Object[]{capvar, new Constant(ref), belvar, belcapvar}))});
List bvars = bc.getBindVariables(); for(int k=0; k<bvars.size(); k++) if(bc.getOperator().equals(IOperator.EQUAL))
valuesource = context.getBoundConstraint(((VariableExpression)value).getVariable()).getValueSource(); valuesource = context.getBoundConstraint(var).getValueSource(); context.pushCondition(context.getConstrainableCondition(var));
if(bc.getOperator().equals(IOperator.EQUAL)) List bvars = bc.getBindVariables(); for(int k=0; k<bvars.size(); k++) if(c instanceof BoundConstraint && ((BoundConstraint)c).getOperator().equals(IOperator.EQUAL)) List bvars = ((BoundConstraint)c).getBindVariables(); for(int k=0; k<bvars.size(); k++) BoundConstraint bc = new BoundConstraint(null, new Variable(context.generateVariableName(),((ObjectCondition)con).getObjectType(), false, true)); List constraints2 = new ArrayList(((ObjectCondition)con).getConstraints()); constraints2.removeAll(constraints);
/** * 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; }
if(bc.isMultiConstraint()) List vars = bc.getBindVariables(); String[] binds = new String[vars.size()]; for(int j=0; j<binds.length; j++) binds[j] = ((Variable)vars.get(j)).isMulti()? SplitNode.MULTI: SplitNode.SINGLE; addSplitNode((OAVAttributeType)bc.getValueSource(), binds, context); List vars = ((BoundConstraint)c).getBindVariables(); for(int v=0; firstbound && v<vars.size(); v++)
List bvars = bc.getBindVariables(); for(int k=0; k<bvars.size(); k++) if(bc.getOperator().equals(IOperator.EQUAL))
/** * Get the string representation. * @return The string representation. */ public String toString() { StringBuffer sbuf = new StringBuffer(); sbuf.append("("); sbuf.append(getValueSource()); sbuf.append(getOperator()); if(vars.size()>1) { sbuf.append("("); for(int i=0; i<vars.size(); i++) { sbuf.append(vars.get(i)); } sbuf.append(")"); } else { sbuf.append(vars.get(0)); } sbuf.append(")"); return sbuf.toString(); } }
valuesource = context.getBoundConstraint(((VariableExpression)value).getVariable()).getValueSource(); valuesource = context.getBoundConstraint(var).getValueSource(); context.pushCondition(context.getConstrainableCondition(var));
/** * Create a new variable and bind it using the given object condition and value source. * @param condition The object condition. * @param name The variable name. * @param valuesource The value source. * @return The new variable. */ public Variable generateVariableBinding(ConstrainableCondition condition, String name, OAVObjectType type, Object valuesource) { Variable tmpvar = new Variable(name, type, false, true); variables.put(name, tmpvar); BoundConstraint bc = new BoundConstraint(valuesource, tmpvar); boundconstraints.put(tmpvar, bc); condition.addConstraint(bc); bcons.put(tmpvar, condition); return tmpvar; }
&& IOperator.EQUAL.equals(((BoundConstraint)c).getOperator()) && !(((BoundConstraint)c).getValueSource() instanceof MethodCall) && !(((BoundConstraint)c).getValueSource() instanceof FunctionCall) && !(((BoundConstraint)c).getValueSource() instanceof List) && !(((BoundConstraint)c).getValueSource() instanceof OAVAttributeType) OAVObjectType type = bc.getValueSource()!=null ? ((OAVAttributeType)bc.getValueSource()).getType() : cond.getObjectType(); if(!(type instanceof OAVJavaType) || OAVJavaType.KIND_VALUE.equals(((OAVJavaType)type).getKind())) List vars = bc.getBindVariables(); for(int i=0; i<vars.size(); i++) int subindex = bc.isMultiConstraint()? i: -1; IValueExtractor rightex = createValueExtractor(-1, bc.getValueSource(), subindex, context, false); ret.add(new ConstraintIndexer(leftex, rightex));
if(bc.getOperator().equals(IOperator.EQUAL)) List bvars = bc.getBindVariables(); for(int k=0; k<bvars.size(); k++)
/** * Get the variables. * @return The declared variables. */ public List getVariables() { if(depvars==null) { List vfvs = getVariablesForValueSource(getValueSource()); if(vfvs.isEmpty()) { depvars = vars; } else if(!vars.isEmpty()) { depvars = new ArrayList(vfvs); depvars.addAll(vars); } else { depvars = Collections.EMPTY_LIST; } } return depvars; }