From: <jom...@us...> - 2008-09-11 14:22:23
|
Revision: 1365 http://jason.svn.sourceforge.net/jason/?rev=1365&view=rev Author: jomifred Date: 2008-09-11 14:22:12 +0000 (Thu, 11 Sep 2008) Log Message: ----------- add chains of BBs and a demo to illustrate (demo/chain-bb) add a new custom BB: indexedBB (developed for the JasonTeam in the AgentContest 2008) Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java trunk/build.xml trunk/demos/gui/gui1/gui/yes_no.java trunk/demos/persistent-belief-base/bookstore.properties trunk/demos/persistent-belief-base/bookstore.script trunk/demos/persistent-belief-base/c.asl trunk/demos/persistent-belief-base/custBelBase.mas2j trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java trunk/release-notes.txt trunk/src/jason/architecture/AgArch.java trunk/src/jason/asSemantics/Agent.java trunk/src/jason/asSemantics/ConcurrentInternalAction.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSyntax/LogicalFormula.java trunk/src/jason/bb/DefaultBeliefBase.java trunk/src/jason/bb/JDBCPersistentBB.java trunk/src/jason/bb/TextPersistentBB.java trunk/src/jason/infra/centralised/CentralisedAgArch.java trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java trunk/src/jason/infra/centralised/RunCentralisedMAS.java trunk/src/jason/infra/jade/JadeAgArch.java trunk/src/jason/infra/saci/SaciMASLauncherAnt.java trunk/src/jason/mas2j/AgentParameters.java trunk/src/jason/mas2j/MAS2JProject.java trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc trunk/src/jason/mas2j/parser/mas2j.java trunk/src/test/MAS2JParserTest.java Added Paths: ----------- trunk/demos/chain-bb/ trunk/demos/chain-bb/bob.asl trunk/demos/chain-bb/chain-bb.mas2j trunk/src/jason/bb/ChainBB.java trunk/src/jason/bb/ChainBBAdapter.java trunk/src/jason/bb/IndexedBB.java Modified: trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java =================================================================== --- trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/applications/as-unit-test/src/jason/asunit/TestAgent.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -4,8 +4,10 @@ import jason.JasonException; import jason.RevisionFailedException; import jason.asSemantics.Agent; +import jason.asSemantics.Circumstance; import jason.asSemantics.Event; import jason.asSemantics.Intention; +import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; import jason.asSyntax.Literal; import jason.asSyntax.LogExpr; @@ -39,7 +41,11 @@ arch = new TestArch(); else arch = new TestArch(agName); - arch.getUserAgArch().setTS(initAg(arch.getUserAgArch(), null, null, new Settings())); + + TransitionSystem ts = new TransitionSystem(this, new Circumstance(), new Settings(), arch.getUserAgArch()); + setTS(ts); + arch.getUserAgArch().setTS(ts); + initAg(null); } catch (JasonException e) { logger.log(Level.SEVERE, "Error creating TestArch", e); } Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/build.xml 2008-09-11 14:22:12 UTC (rev 1365) @@ -19,11 +19,11 @@ <property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" /> <property name="distFile" value="${env.HOME}/Jason-${version}.${release}" /> - <property name="jedit.install.dir" value="${basedir}/lib/jedit" /> + <property name="jedit.install.dir" value="${basedir}/bin/jedit" /> <property name="plugin.jar.name" value="jason-jedit-plugin.jar" /> <path id="run.classpath"> - <pathelement location="${jedit.install.dir}/jedit.jar" /> + <pathelement location="${basedir}/lib/jedit/jedit.jar" /> <pathelement location="${saciJar}" /> <pathelement location="${jadeJar}" /> <pathelement location="${jadeHttpJar}" /> @@ -36,8 +36,8 @@ <pathelement location="${basedir}/lib/ant-launcher.jar" /> <pathelement location="${basedir}/lib/ant.jar" /> <pathelement location="${basedir}/demos/persistent-belief-base/lib/hsqldb.jar" /> - <pathelement location="${jedit.install.dir}/ErrorList.jar" /> - <pathelement location="${jedit.install.dir}/SideKick.jar" /> + <pathelement location="${basedir}/lib/jedit/ErrorList.jar" /> + <pathelement location="${basedir}/lib/jedit/SideKick.jar" /> <pathelement location="${jasonJar}" /> </path> @@ -255,17 +255,18 @@ <fileset dir="${basedir}" includes="src/**/*" /> </copy> - <delete failonerror="no" includeEmptyDirs="true"> + <!--delete failonerror="no" includeEmptyDirs="true"> <fileset dir="${distDir}" includes=".settings" /> <fileset dir="${distDir}" includes=".project" /> <fileset dir="${distDir}" includes=".classpath" /> - </delete> + </delete --> <delete dir="${distDir}/bin/classes" /> + <delete dir="${distDir}/bin/classes-eclipse" /> <delete dir="${distDir}/doc/faq" /> <delete dir="${distDir}/doc/api" /> <delete dir="${distDir}/doc/mini-tutorial/src" /> - <tar compression="gzip" tarfile="${distFile}.tgz"> + <tar compression="gzip" tarfile="${distFile}.tgz" longfile="gnu"> <tarfileset dir="${distDir}/.." mode="755"> <include name="Jason-${version}.${release}/**/*.sh" /> <include name="Jason-${version}.${release}/**/asl2*" /> @@ -300,7 +301,7 @@ <fileset dir="${basedir}/examples" includes="**/MTPs-Main-Container.txt" /> <fileset dir="${basedir}/demos" includes="**/MTPs-Main-Container.txt" /> - <fileset dir="${basedir}/examples/Sniffer" includes="log.*" /> + <fileset dir="${basedir}/examples/sniffer" includes="log.*" /> <fileset dir="${basedir}/demos/persistent-belief-base" includes="a.bb" /> <fileset defaultexcludes="no" dir="${basedir}" includes="**/*~" /> Added: trunk/demos/chain-bb/bob.asl =================================================================== --- trunk/demos/chain-bb/bob.asl (rev 0) +++ trunk/demos/chain-bb/bob.asl 2008-09-11 14:22:12 UTC (rev 1365) @@ -0,0 +1,17 @@ +// Agent bob in project chainBB.mas2j + +/* Initial beliefs and rules */ + +/* Initial goals */ + +!start. + +/* Plans */ + ++!start : true + <- +boss(1,"Vercouter"); + +boss(2,"Rosine"); + +boss(2,"Boissier"); // will replace "boss(2,Rosine)" since both have the same key + +boss(math.round(math.random(10)), "Picard"); + ?boss(2,X); .print("Boss 2 is ",X). + Added: trunk/demos/chain-bb/chain-bb.mas2j =================================================================== --- trunk/demos/chain-bb/chain-bb.mas2j (rev 0) +++ trunk/demos/chain-bb/chain-bb.mas2j 2008-09-11 14:22:12 UTC (rev 1365) @@ -0,0 +1,29 @@ +/* Jason Project + + Example of chain belief bases. + + The agent bob uses two customisations of BB: + one to persist the beliefs and + another to have a king of key based BB. + + To see the effect of the two BBs, run the program + and, when finished, click on "Debug" mode and then + select "bob" agent. Notice that the boss beliefs have + unique keys. If you run the program again you will + note that beliefs added in previous executions + are persisted (they are stored in the bob.bb file). + +*/ + +MAS chainBB { + + infrastructure: Centralised + + agents: + bob beliefBaseClass jason.bb.ChainBB( + jason.bb.TextPersistentBB, + jason.bb.IndexedBB("boss(key,_)") // the first argument of boss is the key + ); + +} + Modified: trunk/demos/gui/gui1/gui/yes_no.java =================================================================== --- trunk/demos/gui/gui1/gui/yes_no.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/demos/gui/gui1/gui/yes_no.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -41,7 +41,7 @@ public void timeout(TransitionSystem ts, String intentionKey) { // this method have to decide what to do with actions finished by timeout // 1: resume - //resume(ts,intentionKey); + //resumeInt(ts,intentionKey); // 2: fail failInt(ts, intentionKey); Modified: trunk/demos/persistent-belief-base/bookstore.properties =================================================================== --- trunk/demos/persistent-belief-base/bookstore.properties 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/demos/persistent-belief-base/bookstore.properties 2008-09-11 14:22:12 UTC (rev 1365) @@ -1,5 +1,5 @@ #HSQL Database Engine -#Sat Jul 05 11:30:42 CEST 2008 +#Thu Sep 11 15:58:11 CEST 2008 hsqldb.script_format=0 runtime.gc_interval=0 sql.enforce_strict_size=false Modified: trunk/demos/persistent-belief-base/bookstore.script =================================================================== --- trunk/demos/persistent-belief-base/bookstore.script 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/demos/persistent-belief-base/bookstore.script 2008-09-11 14:22:12 UTC (rev 1365) @@ -28,4 +28,4 @@ INSERT INTO PUBLISHER VALUES(1,'Springer') INSERT INTO PUBLISHER VALUES(2,'MIT Press') INSERT INTO PUBLISHER VALUES(3,'John Wiley & Sons') -INSERT INTO TABLEA VALUES('45',FALSE,'[source(self)]') +INSERT INTO TABLEA VALUES('49',FALSE,'[source(self)]') Modified: trunk/demos/persistent-belief-base/c.asl =================================================================== --- trunk/demos/persistent-belief-base/c.asl 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/demos/persistent-belief-base/c.asl 2008-09-11 14:22:12 UTC (rev 1365) @@ -31,4 +31,4 @@ // Rules used to show all books show_all_titles :- book(_, Title, _, _Year, _ISBN) & .println("-- ", Title) & false. -show_all_titles. +show_all_titles :- true. Modified: trunk/demos/persistent-belief-base/custBelBase.mas2j =================================================================== --- trunk/demos/persistent-belief-base/custBelBase.mas2j 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/demos/persistent-belief-base/custBelBase.mas2j 2008-09-11 14:22:12 UTC (rev 1365) @@ -27,7 +27,7 @@ "org.hsqldb.jdbcDriver", // driver for HSQLDB "jdbc:hsqldb:bookstore", // URL connection "sa", // user - "", // password + "", // password "[a(1,tablea,columns(runs(integer))),book(5),book_author(2),author(2,author,columns(id(integer),name(varchar(30)))),publisher(2)]"); // predicate a/1 is mapped to a table called "tablea" with an integer column called runs; // the name and type of the columns is used only if the table does not exits and Modified: trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java =================================================================== --- trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/demos/using-only-jason-BDI-engine/SimpleJasonAgent.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -2,8 +2,9 @@ import jason.architecture.AgArch; import jason.asSemantics.ActionExec; import jason.asSemantics.Agent; +import jason.asSemantics.Circumstance; +import jason.asSemantics.TransitionSystem; import jason.asSyntax.Literal; -import jason.bb.DefaultBeliefBase; import jason.infra.centralised.RunCentralisedMAS; import jason.runtime.Settings; @@ -32,7 +33,8 @@ // set up the Jason agent try { Agent ag = new Agent(); - setTS(ag.initAg(this, new DefaultBeliefBase(), "demo.asl", new Settings())); + new TransitionSystem(ag, new Circumstance(), new Settings(), this); + ag.initAg("demo.asl"); } catch (Exception e) { logger.log(Level.SEVERE, "Init error", e); } Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/release-notes.txt 2008-09-11 14:22:12 UTC (rev 1365) @@ -2,6 +2,14 @@ version 1.1.3 ------------- +New features +. customised belief bases can be organised in a chain so + that several functionalities can be composed. For more + information + see/run the demo/chain-bb + see API doc of ChainBB and ChainBBAdapter + + New internal actions . .term2string: transform term into strings and vice-versa. Modified: trunk/src/jason/architecture/AgArch.java =================================================================== --- trunk/src/jason/architecture/AgArch.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/architecture/AgArch.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -25,6 +25,7 @@ import jason.JasonException; import jason.asSemantics.ActionExec; import jason.asSemantics.Agent; +import jason.asSemantics.Circumstance; import jason.asSemantics.Message; import jason.asSemantics.TransitionSystem; import jason.asSyntax.Literal; @@ -71,9 +72,14 @@ // set the agent try { Agent ag = (Agent) Class.forName(agClass).newInstance(); + + new TransitionSystem(ag, new Circumstance(), stts, this); + BeliefBase bb = (BeliefBase) Class.forName(bbPars.getClassName()).newInstance(); - ts = ag.initAg(this, bb, asSrc, stts); + ag.setBB(bb); // the agent's BB have to be already set for the BB initialisation bb.init(ag, bbPars.getParametersArray()); + + ag.initAg(asSrc); // load the source code of the agent } catch (Exception e) { throw new JasonException("as2j: error creating the agent class! - ", e); } Modified: trunk/src/jason/asSemantics/Agent.java =================================================================== --- trunk/src/jason/asSemantics/Agent.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/asSemantics/Agent.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -42,7 +42,6 @@ import jason.bb.DefaultBeliefBase; import jason.functions.Count; import jason.functions.RuleToFunction; -import jason.runtime.Settings; import java.io.File; import java.io.FileInputStream; @@ -103,31 +102,11 @@ checkCustomSelectOption(); } - private void checkCustomSelectOption() { - hasCustomSelOp = false; - for (Method m: this.getClass().getMethods()) { - if (!m.getDeclaringClass().equals(Agent.class) && m.getName().equals("selectOption")) { - hasCustomSelOp = true; - } - } - } - - public boolean hasCustomSelectOption() { - return hasCustomSelOp; - } - - /** Creates the TS of this agent, parses its AS source, and sets its Settings */ - public TransitionSystem initAg(AgArch arch, BeliefBase bb, String asSrc, Settings stts) throws JasonException { + /** parse and load the agent code, asSrc may be null */ + public TransitionSystem initAg(String asSrc) throws JasonException { // set the agent try { - setLogger(arch); - logger.setLevel(stts.logLevel()); - - if (bb != null) - this.bb = bb; - initDefaultFunctions(); - setTS(new TransitionSystem(this, new Circumstance(), stts, arch)); boolean parsingOk = true; if (asSrc != null) { @@ -160,7 +139,6 @@ } else { logger.warning("The kqmlPlans.asl was not found!"); } - return ts; } catch (Exception e) { @@ -444,12 +422,17 @@ /** TS Initialisation (called by the AgArch) */ public void setTS(TransitionSystem ts) { this.ts = ts; + setLogger(ts.getUserAgArch()); + logger.setLevel(ts.getSettings().logLevel()); } public TransitionSystem getTS() { return ts; } + public void setBB(BeliefBase bb) { + this.bb = bb; + } public BeliefBase getBB() { return bb; } @@ -686,6 +669,19 @@ } } + private void checkCustomSelectOption() { + hasCustomSelOp = false; + for (Method m: this.getClass().getMethods()) { + if (!m.getDeclaringClass().equals(Agent.class) && m.getName().equals("selectOption")) { + hasCustomSelOp = true; + } + } + } + + public boolean hasCustomSelectOption() { + return hasCustomSelOp; + } + static DocumentBuilder builder = null; /** Gets the agent "mind" (Beliefs, plans and circumstance) as XML */ Modified: trunk/src/jason/asSemantics/ConcurrentInternalAction.java =================================================================== --- trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -18,6 +18,38 @@ the answer. With SuspendInternalAction, only the intention using the IA is suspended. See demos/gui/gui1. + The code of an internal action that extends this class looks like: + + <pre> + public class ...... extends ConcurrentInternalAction { + + public Object execute(final TransitionSystem ts, Unifier un, final Term[] args) throws Exception { + .... + + final String key = suspendInt(ts, "gui", 5000); // suspend the intention (max 5 seconds) + + startInternalAction(ts, new Runnable() { // to not block the agent thread, start a thread that performs the task and resume the intention latter + public void run() { + + .... the code of the IA ..... + + if ( ... all Ok ...) + resumeInt(ts, key); // resume the intention with success + else + failInt(ts, key); // resume the intention with fail + } + }); + + ... + } + + public void timeout(TransitionSystem ts, String intentionKey) { // called back when the intention should be resumed/failed by timeout (after 5 seconds in this example) + ... this method have to decide what to do with actions finished by timeout: resume or fail + ... to call resumeInt(ts,intentionKey) or failInt(ts, intentionKey) + } + } + </pre> + @author jomi */ public abstract class ConcurrentInternalAction implements InternalAction { Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -96,6 +96,12 @@ setLogger(agArch); if (setts != null) logger.setLevel(setts.logLevel()); + + if (a != null) + a.setTS(this); + + if (ar != null) + ar.setTS(this); } public void setLogger(AgArch arch) { Modified: trunk/src/jason/asSyntax/LogicalFormula.java =================================================================== --- trunk/src/jason/asSyntax/LogicalFormula.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/asSyntax/LogicalFormula.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -2,7 +2,6 @@ import jason.asSemantics.Agent; import jason.asSemantics.Unifier; -import jason.util.ToDOM; import java.util.Iterator; @@ -12,7 +11,7 @@ * * @author Jomi */ -public interface LogicalFormula extends Term, Cloneable, ToDOM { +public interface LogicalFormula extends Term, Cloneable { /** * Checks whether the formula is a * logical consequence of the belief base. Added: trunk/src/jason/bb/ChainBB.java =================================================================== --- trunk/src/jason/bb/ChainBB.java (rev 0) +++ trunk/src/jason/bb/ChainBB.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -0,0 +1,91 @@ +package jason.bb; + +import jason.asSemantics.Agent; +import jason.asSyntax.StringTerm; +import jason.asSyntax.Structure; +import jason.asSyntax.Term; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + + +/** + * + * A wrapper for a chain of belief bases customisations. + * + * The arguments are the belief bases in the chain + * + * jason.bb.ChainBB( bb1, bb2, bb3, ... ) + * + * where each BB is bbclass(bb paramters) + * + * e.g.: + * <pre> + * agents: + bob beliefBaseClass jason.bb.ChainBB( + jason.bb.TextPersistentBB, + jason.bb.IndexedBB("student(key,_)", "depot(_,_,_)") + ); + * </pre> + */ +public class ChainBB extends ChainBBAdapter { + + private static Logger logger = Logger.getLogger(ChainBB.class.getSimpleName()); + + @Override + public void init(Agent ag, String[] args) { + setNext(null); // remove DefaultBB + try { + // create all chain BBs + for (String s: args) { + Structure bbs = Structure.parse(s); + BeliefBase bb = (ChainBBAdapter) Class.forName(bbs.getFunctor()).newInstance(); + addInChain(bb); + } + + // init BB + ChainBBAdapter bb = getNextAdapter(); + for (String s: args) { + // translate the terms to String[] + Structure bbs = Structure.parse(s); + String[] bbargs = new String[bbs.getArity()]; + int i = 0; + for (Term t: bbs.getTerms()) { + bbargs[i++] = t.isString() ? ((StringTerm)t).getString(): t.toString(); + } + bb.init(ag, bbargs); + bb = bb.getNextAdapter(); + } + } catch (Exception e) { + logger.log(Level.SEVERE, "Error creating ChainBB",e); + } + } + + /** add a new BB at the end of the chain */ + public void addInChain(BeliefBase bb) { + if (getNextAdapter() == null) { + setNext(bb); + } else { + ChainBBAdapter last = getNextAdapter(); + while (last.getNextAdapter() != null) { + last = last.getNextAdapter(); + } + last.setNext(bb); + } + } + + @SuppressWarnings("unchecked") + public List<Class> getChainClasses() { + List<Class> r = new ArrayList<Class>(); + ChainBBAdapter c = getNextAdapter(); + while (c != null) { + r.add(c.getClass()); + if (c.nextBB != null && c.nextBB instanceof DefaultBeliefBase) + r.add(c.nextBB.getClass()); + c = c.getNextAdapter(); + } + return r; + } +} Added: trunk/src/jason/bb/ChainBBAdapter.java =================================================================== --- trunk/src/jason/bb/ChainBBAdapter.java (rev 0) +++ trunk/src/jason/bb/ChainBBAdapter.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -0,0 +1,149 @@ +package jason.bb; + +import jason.asSemantics.Agent; +import jason.asSemantics.Unifier; +import jason.asSyntax.Literal; +import jason.asSyntax.PredicateIndicator; +import jason.bb.BeliefBase; +import jason.bb.DefaultBeliefBase; + +import java.util.Iterator; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + + This class is to be extended by customised belief bases that may be + used in chains (of responsibility). + + For example, the code + <pre> + BeliefBase bb = + new MyBB1( + new MyBB2()); + // DefaultBeliefBase is the next of the last element of the chain + </pre> + will chain 3 BBs: MyBB1, myBB2, and the DefaultBeliefBase. So, for any operation of + the BB interface, the operation is firstly called in MyBB1, then in MyBB2 and finally + in the DefaultBeliefBase. + + The code of MyBB1 looks like: + + <pre> + class MyBB1 extends ChainBBAdapter { + public MyBB1() { } + public MyBB1(BeliefBase next) { + super(next); + } + + public boolean add(Literal l) { + ... some customisation of add .... + return next.add(l); // delegate the operation for the next BB in the chain + } + + ... customisation of other operations ... + } + </pre> + + @author Jomi + + */ +@SuppressWarnings("deprecation") +public class ChainBBAdapter implements BeliefBase { + + protected BeliefBase nextBB = null; // the next BB in the chain + + public ChainBBAdapter() { + nextBB = new DefaultBeliefBase(); + } + public ChainBBAdapter(BeliefBase bb) { + nextBB = bb; + } + + public void setNext(BeliefBase bb) { + nextBB = bb; + } + + public ChainBBAdapter getNextAdapter() { + return nextBB instanceof ChainBBAdapter ? (ChainBBAdapter)nextBB : null; + } + + public BeliefBase getLastBB() { + if (nextBB == null) + return this; + else if (nextBB instanceof ChainBBAdapter) + return ((ChainBBAdapter)nextBB).getLastBB(); + else + return nextBB; + } + + // Methods of BB interface + + public void init(Agent ag, String[] args) { + nextBB.init(ag, args); + } + public void stop() { + nextBB.stop(); + } + + + public boolean add(Literal l) { + return nextBB.add(l); + } + + public boolean add(int index, Literal l) { + return nextBB.add(index, l); + } + + public Literal contains(Literal l) { + return nextBB.contains(l); + } + + public Iterator<Literal> getAll() { + return nextBB.getAll(); + } + + public Iterator<Literal> iterator() { + return nextBB.iterator(); + } + + public Iterator<Literal> getCandidateBeliefs(Literal l, Unifier u) { + return nextBB.getCandidateBeliefs(l, u); + } + + public Iterator<Literal> getPercepts() { + return nextBB.getPercepts(); + } + + public Iterator<Literal> getRelevant(Literal l) { + return nextBB.getRelevant(l); + } + + public boolean abolish(PredicateIndicator pi) { + return nextBB.abolish(pi); + } + + public boolean remove(Literal l) { + return nextBB.remove(l); + } + + public int size() { + return nextBB.size(); + } + + public Element getAsDOM(Document document) { + return nextBB.getAsDOM(document); + } + + @Override + public Object clone() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String toString() { + return nextBB.toString(); + } +} Modified: trunk/src/jason/bb/DefaultBeliefBase.java =================================================================== --- trunk/src/jason/bb/DefaultBeliefBase.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/bb/DefaultBeliefBase.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -59,7 +59,7 @@ private int size = 0; /** set of beliefs with percept annot, used to improve performance of buf */ - protected Set<Literal> percepts = new HashSet<Literal>(); + private Set<Literal> percepts = new HashSet<Literal>(); public void init(Agent ag, String[] args) { if (ag != null) { @@ -103,6 +103,10 @@ //return ((Set<Literal>)percepts.clone()).iterator(); } + Set<Literal> getPerceptsSet() { + return percepts; + } + public boolean add(Literal l) { return add(l, false); } Added: trunk/src/jason/bb/IndexedBB.java =================================================================== --- trunk/src/jason/bb/IndexedBB.java (rev 0) +++ trunk/src/jason/bb/IndexedBB.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -0,0 +1,93 @@ +package jason.bb; + +import jason.asSemantics.Agent; +import jason.asSemantics.Unifier; +import jason.asSyntax.Literal; +import jason.asSyntax.Structure; +import jason.asSyntax.Term; +import jason.bb.BeliefBase; +import jason.bb.ChainBBAdapter; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * Customised version of Belief Base where some beliefs are unique (with primary keys) and + * indexed for faster access. + * + * <p>E.g. in a .mas2j project file:<br/> + * <code>agents: bob beliefBaseClass agent.IndexedBB("student(key,_)", "depot(_,_,_)")</code> + * <br/> + * The belief "student/2" has the first argument as its key, so the BB will never has + * two students with the same key. Or, two students in the BB will have two different keys. + * The belief "depot/3" has no key, so there will be always only one "depot" in the BB. + * + * When some belief with the same key than another belief in BB is added, + * the most recent remains in the BB and the older is removed. + * + * @author jomi + */ +public class IndexedBB extends ChainBBAdapter { + + Map<String,Structure> indexedBels = new HashMap<String,Structure>(); + Unifier u = new Unifier(); + + public IndexedBB() { } + public IndexedBB(BeliefBase next) { + super(next); + } + + @Override + public void init(Agent ag, String[] args) { + for (int i=0; i<args.length; i++) { + Structure bel = Structure.parse(args[i]); + indexedBels.put(bel.getFunctor(), bel); + } + } + + // TODO: access indexes + + @Override + public boolean add(Literal bel) { + Structure kb = indexedBels.get(bel.getFunctor()); + if (kb != null && kb.getArity() == bel.getArity()) { // is a constrained bel? + + // find the bel in BB and eventually remove it + u.clear(); + Literal linbb = null; + boolean remove = false; + + Iterator<Literal> relevant = getCandidateBeliefs(bel, null); + if (relevant != null) { + final int kbArity = kb.getArity(); + while (relevant.hasNext() && !remove) { + linbb = relevant.next(); + + if (!linbb.isRule()) { + // check equality of all terms that are "key" + // if some key is different, no problem + // otherwise, remove the current bel + boolean equals = true; + for (int i = 0; i<kbArity; i++) { + Term kbt = kb.getTerm(i); + if (!kbt.isVar()) { // is key? + if (!u.unifies(bel.getTerm(i), linbb.getTerm(i))) { + equals = false; + break; + } + } + } + if (equals) { + remove = true; + } + } + } + } + if (remove) { + remove(linbb); + } + } + return nextBB.add(bel); + } +} Modified: trunk/src/jason/bb/JDBCPersistentBB.java =================================================================== --- trunk/src/jason/bb/JDBCPersistentBB.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/bb/JDBCPersistentBB.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -77,7 +78,7 @@ @author Jomi */ -public class JDBCPersistentBB extends DefaultBeliefBase { +public class JDBCPersistentBB extends ChainBBAdapter { private static Logger logger = Logger.getLogger(JDBCPersistentBB.class.getName()); static final String COL_PREFIX = "term"; @@ -94,7 +95,12 @@ public JDBCPersistentBB() { extraCols = 2; } + public JDBCPersistentBB(BeliefBase next) { + super(next); + extraCols = 2; + } + // map of bels in DB protected Map<PredicateIndicator, ResultSetMetaData> belsDB = new HashMap<PredicateIndicator, ResultSetMetaData>(); @@ -150,6 +156,7 @@ } catch (SQLException e) { logger.log(Level.SEVERE, "DB connection failure. url= " + url + ", user=" + args[2] + ", password=" + args[3], e); } + nextBB.init(ag, args); } @Override @@ -164,6 +171,7 @@ } catch (Exception e) { logger.log(Level.SEVERE, "Error in shutdown SGBD ", e); } + nextBB.stop(); } /** returns true if the literal is stored in a DB */ @@ -186,7 +194,7 @@ @Override public Literal contains(Literal l) { if (!isDB(l)) - return super.contains(l); + return nextBB.contains(l); Statement stmt = null; try { @@ -213,7 +221,7 @@ @Override public boolean add(Literal l) { if (!isDB(l)) - return super.add(l); + return nextBB.add(l); Literal bl = contains(l); Statement stmt = null; @@ -230,7 +238,7 @@ // check if it needs to be added in the percepts list if (l.hasAnnot(TPercept)) { - percepts.add(bl); + getDBBPercepts().add(bl); } // store bl annots @@ -245,7 +253,7 @@ stmt.executeUpdate(getInsert(l)); // add it in the percepts list if (l.hasAnnot(TPercept)) { - percepts.add(l); + getDBBPercepts().add(l); } return true; } @@ -261,11 +269,10 @@ return false; } - @Override public boolean remove(Literal l) { if (!isDB(l)) - return super.add(l); + return nextBB.remove(l); Literal bl = contains(l); if (bl != null) { @@ -273,7 +280,7 @@ try { if (l.hasSubsetAnnot(bl)) { if (l.hasAnnot(TPercept)) { - percepts.remove(bl); + getDBBPercepts().remove(bl); } boolean result = bl.delAnnot(l) || !bl.hasAnnot(); stmt = conn.createStatement(); @@ -299,11 +306,19 @@ return false; } + private Set<Literal> getDBBPercepts() { + BeliefBase last = getLastBB(); + if (last instanceof DefaultBeliefBase) + return ((DefaultBeliefBase)last).getPerceptsSet(); + else + return null; + } + @Override public boolean abolish(PredicateIndicator pi) { if (belsDB.get(pi) == null) - return super.abolish(pi); + return nextBB.abolish(pi); Statement stmt = null; try { @@ -326,7 +341,7 @@ public Iterator<Literal> getCandidateBeliefs(Literal l, Unifier u) { final PredicateIndicator pi = l.getPredicateIndicator(); if (belsDB.get(pi) == null) - return super.getCandidateBeliefs(l, u); + return nextBB.getCandidateBeliefs(l, u); if (l.isVar()) { // all bels are relevant @@ -401,14 +416,14 @@ logger.log(Level.WARNING, "SQL Error closing connection", e); } } - return count + super.size(); + return count + nextBB.size(); } @Override public Iterator<Literal> iterator() { List<Literal> all = new ArrayList<Literal>(size()); - Iterator<Literal> is = super.iterator(); + Iterator<Literal> is = nextBB.iterator(); while (is.hasNext()) { all.add(is.next()); } Modified: trunk/src/jason/bb/TextPersistentBB.java =================================================================== --- trunk/src/jason/bb/TextPersistentBB.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/bb/TextPersistentBB.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -1,6 +1,5 @@ package jason.bb; -import jason.RevisionFailedException; import jason.asSemantics.Agent; import jason.asSyntax.Literal; @@ -16,21 +15,28 @@ * beliefs in the file; when the agent stops, save the BB in the file. * The file name is the agent's name + ".bb". */ -public class TextPersistentBB extends DefaultBeliefBase { +public class TextPersistentBB extends ChainBBAdapter { private static Logger logger = Logger.getLogger(TextPersistentBB.class.getName()); - File file = null; + private File file = null; + + public TextPersistentBB() { } + public TextPersistentBB(BeliefBase next) { + super(next); + } public void init(Agent ag, String[] args) { - try { - file = new File(ag.getTS().getUserAgArch().getAgName() + ".bb"); - logger.fine("reading from file " + file); - if (file.exists()) { - ag.parseAS(file.getAbsoluteFile()); + if (ag != null) { + try { + file = new File(ag.getTS().getUserAgArch().getAgName() + ".bb"); + logger.fine("reading from file " + file); + if (file.exists()) { + ag.parseAS(file.getAbsoluteFile()); ag.addInitialBelsInBB(); + } + } catch (Exception e) { + logger.log(Level.SEVERE,"Error initialising TextPersistentBB.",e); } - } catch (RevisionFailedException e) { - logger.log(Level.SEVERE,"Error in init.",e); } } @@ -48,5 +54,6 @@ } catch (Exception e) { logger.log(Level.SEVERE, "Error writing BB in file " + file, e); } + nextBB.stop(); } } Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -96,7 +96,7 @@ setLogger(); } catch (Exception e) { running = false; - throw new JasonException("as2j: error creating the agent class! - ", e); + throw new JasonException("as2j: error creating the agent class! - "+e.getMessage(), e); } } Modified: trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -43,7 +43,7 @@ CentralisedAgArch agArch = new CentralisedAgArch(); agArch.setAgName(agName); - agArch.initAg(ap.archClass.getClassName(), ap.agClass.getClassName(), ap.bbClass, agSource, stts, masRunner); + agArch.initAg(ap.archClass.getClassName(), ap.agClass.getClassName(), ap.getBBClass(), agSource, stts, masRunner); agArch.setEnvInfraTier(masRunner.getEnvironmentInfraTier()); agArch.setControlInfraTier(masRunner.getControllerInfraTier()); masRunner.addAg(agArch); Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java =================================================================== --- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -370,7 +370,7 @@ agArch.initAg(ap.archClass.getClassName(), pag, this); } else { // normal creation - agArch.initAg(ap.archClass.getClassName(), ap.agClass.getClassName(), ap.bbClass, ap.asSource.toString(), ap.getAsSetts(debug, project.getControlClass() != null), this); + agArch.initAg(ap.archClass.getClassName(), ap.agClass.getClassName(), ap.getBBClass(), ap.asSource.toString(), ap.getAsSetts(debug, project.getControlClass() != null), this); } addAg(agArch); Modified: trunk/src/jason/infra/jade/JadeAgArch.java =================================================================== --- trunk/src/jason/infra/jade/JadeAgArch.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/infra/jade/JadeAgArch.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -89,7 +89,7 @@ asSource = ap.asSource.getAbsolutePath(); archClassName = ap.archClass.getClassName(); agClassName = ap.agClass.getClassName(); - bbPars = ap.bbClass; + bbPars = ap.getBBClass(); stts = ap.getAsSetts((Boolean)args[1], (Boolean)args[2]); // TODO: get this parameters } else { Modified: trunk/src/jason/infra/saci/SaciMASLauncherAnt.java =================================================================== --- trunk/src/jason/infra/saci/SaciMASLauncherAnt.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/infra/saci/SaciMASLauncherAnt.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -190,7 +190,7 @@ tmpAgArchClass = new ClassParameters(AgArch.class.getName()); } - ClassParameters tmpBBClass = agp.bbClass; + ClassParameters tmpBBClass = agp.getBBClass(); if (tmpBBClass == null) { tmpBBClass = new ClassParameters(DefaultBeliefBase.class.getName()); } Modified: trunk/src/jason/mas2j/AgentParameters.java =================================================================== --- trunk/src/jason/mas2j/AgentParameters.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/mas2j/AgentParameters.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -54,6 +54,10 @@ } } + public ClassParameters getBBClass() { + return bbClass; + } + public void setAgClass(String c) { if (c != null) agClass = new ClassParameters(c); } Modified: trunk/src/jason/mas2j/MAS2JProject.java =================================================================== --- trunk/src/jason/mas2j/MAS2JProject.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/mas2j/MAS2JProject.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -238,7 +238,7 @@ s.append("MAS " + getSocName() + " {\n"); s.append(" infrastructure: "+getInfrastructure()+"\n\n"); - if (! getEnvClass().getClassName().equals(jason.environment.Environment.class.getName())) { + if (getEnvClass() != null && ! getEnvClass().getClassName().equals(jason.environment.Environment.class.getName())) { s.append(" environment: "+getEnvClass()); if (envClass.getHost() != null) { s.append(" at "+envClass.getHost()); Modified: trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc =================================================================== --- trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2008-09-11 14:22:12 UTC (rev 1365) @@ -253,7 +253,7 @@ } -ClassParameters classDef() : { Token c; String p = ""; ClassParameters cp = new ClassParameters(); } +ClassParameters classDef() : { Token c; String s; ClassParameters cp = new ClassParameters(); } { (c = <ID> | c = <ASID>) { cp.setClassName(c.image); } ( @@ -262,9 +262,9 @@ [ "(" [ - (c=<ID> | c=<ASID> | c=<NUMBER> | c=<STRING>) { cp.addParameter(c.image); } + (s=parameter()) { cp.addParameter(s); } ( - "," (c=<ID> | c=<ASID> | c=<NUMBER> | c=<STRING>) { cp.addParameter(c.image); } + "," (s=parameter()) { cp.addParameter(s); } )* ] ")" @@ -272,14 +272,32 @@ { return cp; } } +String parameter() : { Token c; String s; ClassParameters cp; } +{ + ( cp=classDef() { return cp.toString(); } + | c=<NUMBER> { return c.image; } + | c=<STRING> { return c.image; } + | s=listParameters() { return s; } + ) +} -Map ASoptions() : { Map opts = new HashMap(); } +String listParameters() : { String s; List l = new ArrayList(); } { + "[" + (s=parameter()) { l.add(s); } + ( + "," s=parameter() { l.add(s); } + )* + "]" + { return l.toString(); } +} + + +Map ASoptions() : { Map opts = new HashMap(); } +{ [ "[" opts = procOption(opts) ( "," opts = procOption(opts) )* "]" ] - { - return opts; - } + { return opts; } } Map procOption(Map opts): { Token opt; Token oval; } Modified: trunk/src/jason/mas2j/parser/mas2j.java =================================================================== --- trunk/src/jason/mas2j/parser/mas2j.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/jason/mas2j/parser/mas2j.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -214,7 +214,7 @@ } final public ClassParameters classDef() throws ParseException { - Token c; String p = ""; ClassParameters cp = new ClassParameters(); + Token c; String s; ClassParameters cp = new ClassParameters(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ID: c = jj_consume_token(ID); @@ -261,25 +261,9 @@ case STRING: case ASID: case ID: - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - c = jj_consume_token(ID); - break; - case ASID: - c = jj_consume_token(ASID); - break; - case NUMBER: - c = jj_consume_token(NUMBER); - break; - case STRING: - c = jj_consume_token(STRING); - break; - default: - jj_la1[10] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - cp.addParameter(c.image); + case 46: + s = parameter(); + cp.addParameter(s); label_4: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -287,52 +271,87 @@ ; break; default: - jj_la1[11] = jj_gen; + jj_la1[10] = jj_gen; break label_4; } jj_consume_token(44); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ID: - c = jj_consume_token(ID); - break; - case ASID: - c = jj_consume_token(ASID); - break; - case NUMBER: - c = jj_consume_token(NUMBER); - break; - case STRING: - c = jj_consume_token(STRING); - break; - default: - jj_la1[12] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - cp.addParameter(c.image); + s = parameter(); + cp.addParameter(s); } break; default: - jj_la1[13] = jj_gen; + jj_la1[11] = jj_gen; ; } jj_consume_token(45); break; default: - jj_la1[14] = jj_gen; + jj_la1[12] = jj_gen; ; } {if (true) return cp;} throw new Error("Missing return statement in function"); } + final public String parameter() throws ParseException { + Token c; String s; ClassParameters cp; + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ASID: + case ID: + cp = classDef(); + {if (true) return cp.toString();} + break; + case NUMBER: + c = jj_consume_token(NUMBER); + {if (true) return c.image;} + break; + case STRING: + c = jj_consume_token(STRING); + {if (true) return c.image;} + break; + case 46: + s = listParameters(); + {if (true) return s;} + break; + default: + jj_la1[13] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); + } + + final public String listParameters() throws ParseException { + String s; List l = new ArrayList(); + jj_consume_token(46); + s = parameter(); + l.add(s); + label_5: + while (true) { + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case 44: + ; + break; + default: + jj_la1[14] = jj_gen; + break label_5; + } + jj_consume_token(44); + s = parameter(); + l.add(s); + } + jj_consume_token(47); + {if (true) return l.toString();} + throw new Error("Missing return statement in function"); + } + final public Map ASoptions() throws ParseException { - Map opts = new HashMap(); + Map opts = new HashMap(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 46: jj_consume_token(46); opts = procOption(opts); - label_5: + label_6: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 44: @@ -340,7 +359,7 @@ break; default: jj_la1[15] = jj_gen; - break label_5; + break label_6; } jj_consume_token(44); opts = procOption(opts); @@ -351,7 +370,7 @@ jj_la1[16] = jj_gen; ; } - {if (true) return opts;} + {if (true) return opts;} throw new Error("Missing return statement in function"); } @@ -481,7 +500,7 @@ case CLASSPATH: jj_consume_token(CLASSPATH); jj_consume_token(39); - label_6: + label_7: while (true) { cp = jj_consume_token(STRING); jj_consume_token(41); @@ -492,7 +511,7 @@ break; default: jj_la1[23] = jj_gen; - break label_6; + break label_7; } } break; @@ -508,7 +527,7 @@ case SOURCEPATH: jj_consume_token(SOURCEPATH); jj_consume_token(39); - label_7: + label_8: while (true) { cp = jj_consume_token(STRING); jj_consume_token(41); @@ -519,7 +538,7 @@ break; default: jj_la1[25] = jj_gen; - break label_7; + break label_8; } } break; @@ -535,7 +554,7 @@ case DIRECTIVE: jj_consume_token(DIRECTIVE); jj_consume_token(39); - label_8: + label_9: while (true) { directiveId = jj_consume_token(ASID); jj_consume_token(48); @@ -548,7 +567,7 @@ break; default: jj_la1[27] = jj_gen; - break label_8; + break label_9; } } break; @@ -571,10 +590,10 @@ jj_la1_1(); } private static void jj_la1_0() { - jj_la1_0 = new int[] {0x1000,0x20000000,0xa0000000,0x7000800,0x7000800,0x80000000,0x0,0x60000000,0x0,0x60000000,0x78000000,0x0,0x78000000,0x78000000,0x0,0x0,0x0,0x78000000,0x205a8000,0x800,0x200,0x800,0x400,0x10000000,0x2000,0x10000000,0x4000,0x20000000,0x200000,}; + jj_la1_0 = new int[] {0x1000,0x20000000,0xa0000000,0x7000800,0x7000800,0x80000000,0x0,0x60000000,0x0,0x60000000,0x0,0x78000000,0x0,0x78000000,0x0,0x0,0x0,0x78000000,0x205a8000,0x800,0x200,0x800,0x400,0x10000000,0x2000,0x10000000,0x4000,0x20000000,0x200000,}; } private static void jj_la1_1() { - jj_la1_1 = new int[] {0x0,0x0,0x0,0x100,0x100,0x0,0x400,0x0,0x400,0x0,0x0,0x1000,0x0,0x0,0x800,0x1000,0x4000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; + jj_la1_1 = new int[] {0x0,0x0,0x0,0x100,0x100,0x0,0x400,0x0,0x400,0x0,0x1000,0x4000,0x800,0x4000,0x1000,0x1000,0x4000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,}; } public mas2j(java.io.InputStream stream) { Modified: trunk/src/test/MAS2JParserTest.java =================================================================== --- trunk/src/test/MAS2JParserTest.java 2008-09-10 11:52:51 UTC (rev 1364) +++ trunk/src/test/MAS2JParserTest.java 2008-09-11 14:22:12 UTC (rev 1365) @@ -1,5 +1,7 @@ package test; +import jason.asSyntax.Literal; +import jason.bb.ChainBB; import jason.mas2j.MAS2JProject; import jason.mas2j.parser.mas2j; @@ -31,7 +33,7 @@ boolean ok = true; try { MAS2JProject project = parser.mas(); - System.out.println(project); + //System.out.println(project); parser = new mas2j(new StringReader(project.toString())); parser.mas(); } catch (Exception e) { @@ -43,7 +45,7 @@ } @SuppressWarnings("unchecked") - public void testParser() { + public void testParser1() { try { MAS2JProject project = parser.mas(); project.setDirectory("/tmp"); @@ -62,4 +64,22 @@ } } + public void testClassParForChainBB() throws Exception { + StringBuffer source = new StringBuffer("MAS auctionCent { "); + source.append("agents: bob beliefBaseClass jason.bb.ChainBB(jason.bb.TextPersistentBB, "); + source.append("jason.bb.IndexedBB(\"student(key,_)\", \"depot(_,_,_)\"));"); + source.append(" }"); + parser = new mas2j(new StringReader(source.toString())); + + MAS2JProject project = parser.mas(); + + assertEquals(2, project.getAg("bob").getBBClass().getParametersArray().length); + + ChainBB bb = new ChainBB(); + bb.init(null, project.getAg("bob").getBBClass().getParametersArray()); + + bb.add(Literal.parseLiteral("b(1)")); + } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |