All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jason.functions.Count Maven / Gradle / Ivy

Go to download

Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language.

The newest version!
package jason.functions;

import jason.JasonException;
import jason.asSemantics.DefaultArithFunction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.LogicalFormula;
import jason.asSyntax.Term;

import java.util.Iterator;

/**
  

Function: .count(B): counts the number of occurrences of a particular belief (pattern) in the agent's belief base, as the internal action .count.

Example:

  • .count(a(2,_)): returns the number of beliefs that unify with a(2,_).
@see jason.stdlib.count internal action version @author Jomi */ public class Count extends DefaultArithFunction { public String getName() { return ".count"; } @Override public double evaluate(TransitionSystem ts, Term[] args) throws Exception { if (ts == null) { throw new JasonException("The TransitionSystem parameter of the function '.count' cannot be null."); } LogicalFormula logExpr = (LogicalFormula)args[0]; int n = 0; Iterator iu = logExpr.logicalConsequence(ts.getAg(), new Unifier()); while (iu.hasNext()) { iu.next(); n++; } return n; } @Override public boolean checkArity(int a) { return a == 1; } @Override public boolean allowUngroundTerms() { return true; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy