
jason.functions.Min 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 fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language.
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;
/**
Function: math.min(N1,N2)
: encapsulates java Math.min(N1,N2).
It also returns the min number of a list.
Examples:
-
math.min(1,3)
: returns 1.
-
math.min([3,a,"s",5])
: returns 3.
@author Jomi
@see jason.functions.Max
*/
public class Min extends DefaultArithFunction {
public String getName() {
return "math.min";
}
@Override
public double evaluate(TransitionSystem ts, Term[] args) throws Exception {
if (args[0].isNumeric() && args[1].isNumeric()) {
double n0 = ((NumberTerm)args[0]).solve();
double n1 = ((NumberTerm)args[1]).solve();
return Math.min(n0,n1);
} else if (args[0].isList()) {
double min = Double.MAX_VALUE;
for (Term t: (ListTerm)args[0]) {
if (t.isNumeric()) {
double n = ((NumberTerm)t).solve();
if (n < min)
min = n;
}
}
return min;
}
throw new JasonException(getName()+" is not implemented for type '"+args[0]+"'.");
}
@Override
public boolean checkArity(int a) {
return a == 1 || a == 2;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy