
jason.functions.Average Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jason Show documentation
Show all versions of jason Show documentation
Jason is a programming language to develop BDI/cognitive agents
The newest version!
package jason.functions;
import jason.JasonException;
import jason.asSemantics.DefaultArithFunction;
import jason.asSemantics.TransitionSystem;
import jason.asSyntax.ListTerm;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Term;
/**
@deprecated use function mean instead
*/
@Deprecated
public class Average extends DefaultArithFunction {
public String getName() {
return "math.average";
}
@Override
public double evaluate(TransitionSystem ts, Term[] args) throws Exception {
if (args[0].isList()) {
double sum = 0;
int n = 0;
for (Term t: (ListTerm)args[0])
if (t.isNumeric()) {
sum += ((NumberTerm)t).solve();
n++;
}
return sum / n;
}
throw new JasonException(getName()+" is not implemented for type '"+args[0]+"'.");
}
@Override
public boolean checkArity(int a) {
return a == 1;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy