/** * Returns the parameter value corresponding to the expression and the assignment of values to the * unknown parameters. */ @Override public double getValue(Assignment input) { try { return expression.evaluate(input); } catch (IllegalArgumentException e) { log.warning("cannot evaluate " + this + " given " + input + ": " + e.getMessage()); return 0.0; } }
/** * Grounds the parameter by assigning the values in the assignment to the unknown variables * * @param input the grounding assignment * @return the grounded parameter */ public Parameter ground(Assignment input) { if (input.containsVars(expression.getVariables())) { try { double result = expression.evaluate(input); return new FixedParameter(result); } catch (IllegalArgumentException e) { log.warning("cannot ground " + expression + " with " + input); } } String filled = expression.toString(); for (String u : input.getVariables()) { filled.replaceAll(u, input.getValue(u).toString()); } return new ComplexParameter(filled); }