From: <jom...@us...> - 2008-08-10 11:06:43
|
Revision: 1353 http://jason.svn.sourceforge.net/jason/?rev=1353&view=rev Author: jomifred Date: 2008-08-10 11:06:39 +0000 (Sun, 10 Aug 2008) Log Message: ----------- automatically add source(self) in del bel (-) operator when no other source is provided. previously, it is added only no annotation is provided. Modified Paths: -------------- trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSyntax/Atom.java trunk/src/jason/bb/DefaultBeliefBase.java trunk/src/jason/stdlib/package.html Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2008-07-17 09:16:19 UTC (rev 1352) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-08-10 11:06:39 UTC (rev 1353) @@ -517,9 +517,8 @@ case delAddBel: // -+a(1,X) ===> remove a(_,_), add a(1,X) // change all vars to anon vars to remove it - if (!body.hasAnnot()) { - // do not add source(self) in case the - // programmer set some annotation + if (!body.hasSource()) { + // do not add source(self) in case the programmer set a source body.addAnnot(BeliefBase.TSelf); } Literal bc = (Literal)body.clone(); @@ -574,9 +573,8 @@ break; case delBel: - if (!body.hasAnnot()) { - // do not add source(self) in case the - // programmer set some annotation + if (!body.hasSource()) { + // do not add source(self) in case the programmer set a source body.addAnnot(BeliefBase.TSelf); } Modified: trunk/src/jason/asSyntax/Atom.java =================================================================== --- trunk/src/jason/asSyntax/Atom.java 2008-07-17 09:16:19 UTC (rev 1352) +++ trunk/src/jason/asSyntax/Atom.java 2008-08-10 11:06:39 UTC (rev 1353) @@ -35,7 +35,7 @@ /** * Represents an atom (a structure with no arguments, e.g. "tell", "a"), it is an * immutable object. It extends Literal, so can be used in place of a - * Literal, but does not allow operations on terms/atoms and can not be negated. + * Literal, but does not allow operations on terms/annots and can not be negated. */ public final class Atom extends Literal { Modified: trunk/src/jason/bb/DefaultBeliefBase.java =================================================================== --- trunk/src/jason/bb/DefaultBeliefBase.java 2008-07-17 09:16:19 UTC (rev 1352) +++ trunk/src/jason/bb/DefaultBeliefBase.java 2008-08-10 11:06:39 UTC (rev 1353) @@ -163,7 +163,9 @@ } private boolean removeFromEntry(Literal l) { - if (!l.hasSource()) { + if (l.hasSource()) { + return false; + } else { PredicateIndicator key = l.getPredicateIndicator(); BelEntry entry = belsMap.get(key); entry.remove(l); @@ -172,8 +174,6 @@ } size--; return true; - } else { - return false; } } Modified: trunk/src/jason/stdlib/package.html =================================================================== --- trunk/src/jason/stdlib/package.html 2008-07-17 09:16:19 UTC (rev 1352) +++ trunk/src/jason/stdlib/package.html 2008-08-10 11:06:39 UTC (rev 1353) @@ -96,12 +96,13 @@ <h2>Meta programming</h2> <ul> - <li>{@link jason.stdlib.atom}: check whether an argument is an atom.</li> + <li>{@link jason.stdlib.atom}: check whether an argument is an atom (p).</li> + <li>{@link jason.stdlib.structure}: check whether an argument is a structure (p(t1,t2), [a,b]).</li> + <li>{@link jason.stdlib.literal}: check whether an argument is a literal (p(t1,t2), ~p(t1,t2), p(t1,t2)[a1,a2]).</li> + <li>{@link jason.stdlib.list}: check whether an argument is a list ([a,b]).</li> <li>{@link jason.stdlib.ground}: check whether an argument is ground.</li> - <li>{@link jason.stdlib.literal}: check whether an argument is a literal.</li> - <li>{@link jason.stdlib.list}: check whether an argument is a list.</li> - <li>{@link jason.stdlib.number}: check whether an argument is a number.</li> - <li>{@link jason.stdlib.string}: check whether an argument is a string.</li> + <li>{@link jason.stdlib.number}: check whether an argument is a number (1, 2.3).</li> + <li>{@link jason.stdlib.string}: check whether an argument is a string ("s").</li> <li>{@link jason.stdlib.ground}: check whether an argument is ground.</li> <li>{@link jason.stdlib.add_annot}: add an annotation in a literal.</li> <li>{@link jason.stdlib.add_nested_source}: add a source in a literal.</li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2008-08-29 09:22:32
|
Revision: 1358 http://jason.svn.sourceforge.net/jason/?rev=1358&view=rev Author: jomifred Date: 2008-08-29 09:22:29 +0000 (Fri, 29 Aug 2008) Log Message: ----------- fix some html related issues in the documentation Modified Paths: -------------- trunk/src/jason/asSemantics/Agent.java trunk/src/jason/asSemantics/SuspendInternalAction.java trunk/src/jason/asSyntax/Literal.java trunk/src/jason/asSyntax/Pred.java trunk/src/jason/asSyntax/directives/Directive.java trunk/src/jason/bb/JDBCPersistentBB.java Modified: trunk/src/jason/asSemantics/Agent.java =================================================================== --- trunk/src/jason/asSemantics/Agent.java 2008-08-29 08:46:07 UTC (rev 1357) +++ trunk/src/jason/asSemantics/Agent.java 2008-08-29 09:22:29 UTC (rev 1358) @@ -534,7 +534,7 @@ } /** - * Returns true if BB contains the literal <i>bel</bel> (using unification to test). + * Returns true if BB contains the literal <i>bel</i> (using unification to test). * The unifier <i>un</i> is updated by the method. */ public boolean believes(LogicalFormula bel, Unifier un) { Modified: trunk/src/jason/asSemantics/SuspendInternalAction.java =================================================================== --- trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-08-29 08:46:07 UTC (rev 1357) +++ trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-08-29 09:22:29 UTC (rev 1358) @@ -39,6 +39,7 @@ /** * Suspend the current intention, put it in the PendingIntention (PI) structure and assigns it to a key. * + * @param ts the "engine" of the agent * @param basekey the base key to form final key used to get the intention back from PI (e.g. "moise", "cartago", ...) * @param timeout the max time the intention will be in PI, the value 0 means until "resume" * @return the final key used to store the intention in PI Modified: trunk/src/jason/asSyntax/Literal.java =================================================================== --- trunk/src/jason/asSyntax/Literal.java 2008-08-29 08:46:07 UTC (rev 1357) +++ trunk/src/jason/asSyntax/Literal.java 2008-08-29 09:22:29 UTC (rev 1358) @@ -272,7 +272,7 @@ return predicateIndicatorCache; } - /** returns this literal as a list [<functor>, <list of terms>, <list of annots>] */ + /** returns this literal as a list with three elements: [functor, list of terms, list of annots] */ public ListTerm getAsListOfTerms() { ListTerm l = new ListTermImpl(); l.add(new Literal(type, getFunctor())); @@ -287,7 +287,7 @@ return l; } - /** creates a literal from a list [<functor>, <list of terms>, <list of annots>] */ + /** creates a literal from a list with three elements: [functor, list of terms, list of annots] */ public static Literal newFromListOfTerms(ListTerm lt) throws JasonException { try { Iterator<Term> i = lt.iterator(); Modified: trunk/src/jason/asSyntax/Pred.java =================================================================== --- trunk/src/jason/asSyntax/Pred.java 2008-08-29 08:46:07 UTC (rev 1357) +++ trunk/src/jason/asSyntax/Pred.java 2008-08-29 09:22:29 UTC (rev 1358) @@ -414,7 +414,7 @@ /** * Replaces all variables of the term for unnamed variables (_). * - * @param changes is the map of replacements + * @param un is the unifier that containt the map of replacements */ @Override public void makeVarsAnnon(Unifier un) { Modified: trunk/src/jason/asSyntax/directives/Directive.java =================================================================== --- trunk/src/jason/asSyntax/directives/Directive.java 2008-08-29 08:46:07 UTC (rev 1357) +++ trunk/src/jason/asSyntax/directives/Directive.java 2008-08-29 09:22:29 UTC (rev 1358) @@ -9,39 +9,39 @@ * <p>There are two kinds of directives: single directive and begin/end directive. * The single directive does not have inner plans, as, for instance, the * include: - * <blockquote><code> + * <br/><code> * ...<br> * { include("a.asl") } <br> * ...<br> - * </code></blockquote> + * </code><br/> * * <p>begin/end directives have inner plans, as used in goal patterns: - * <blockquote><code> + * <br/><code> * ...<br> * { begin ebdg(g) } <br> * +!g : bel <- action1. <br> * +!g <- action2. <br> * { end } <br> * ...<br> - * </code></blockquote> + * </code><br/> * This pattern will change these two plans to: - * <blockquote><code> + * <br/><code> * +!g : g. <br> * +!g : not (p__1(g)) & bel <- +p__1(g); action1; ?g. <br> * +!g : not (p__2(g)) <- +p__2(g); action2; ?g. <br> * -!g <- !g. <br> * +g <- -p__1(g); -p__2(g); .dropGoal(g,true). <br> - * </code></blockquote> + * </code><br/> * * Goal patterns are proposed in the paper: <br> - * <blockquote> + * <br/> * Jomi Fred Hubner, Rafael H. Bordini, and Michael Wooldridge. <br> * Programming declarative goals using plan patterns. <br> In Matteo * Baldoni and Ulle Endriss, editors, <i>Proceedings of the Fourth * International Workshop on Declarative Agent Languages and * Technologies</i> (DALT 2006), held with AAMAS 2006, 8th May, Hakodate, * Japan, pages 65-81. Springer, 2006. <br> - * </blockquote> + * <br/> * * @author jomi */ Modified: trunk/src/jason/bb/JDBCPersistentBB.java =================================================================== --- trunk/src/jason/bb/JDBCPersistentBB.java 2008-08-29 08:46:07 UTC (rev 1357) +++ trunk/src/jason/bb/JDBCPersistentBB.java 2008-08-29 09:22:29 UTC (rev 1358) @@ -29,49 +29,53 @@ import java.util.logging.Logger; /** - * Implementation of BB that stores some beliefs in a relational data base. - * - * <p>The parameters for this customisation are: - * <ul> - * <li>args[0] is the Database Engine JDBC drive - * <li>args[1] is the JDBC URL connection string <br/> - * The url can use the agent name as parameter as in "jdbc:mysql://localhost/%s". - * In this case, %s will be replaced by the agent's name. - * <li>args[2] is the username - * <li>args[3] is the password - * <li>args[4] is an AS list with all beliefs that are mapped to DB. - * Each element of the list is in the form - * <blockquote> - * <code>predicate(arity [, table_name [, columns]])</code> - * </blockquote> - * and columns is in the form - * <blockquote> - * <code>columns( col_name(col_type), col_name(col_type), ....)</code> - * </blockquote> - * </ul> - * - * <p>Example in .mas2j project:<br> - * <blockquote> - * <pre> + Implementation of BB that stores some beliefs in a relational data base. + + <p>The parameters for this customisation are: + <ul> + <li>args[0] is the Database Engine JDBC drive + <li>args[1] is the JDBC URL connection string <br/> + The url can use the agent name as parameter as in "jdbc:mysql://localhost/%s". + In this case, %s will be replaced by the agent's name. + <li>args[2] is the username + <li>args[3] is the password + <li>args[4] is an AS list with all beliefs that are mapped to DB. + Each element of the list is in the form + <br/><br/> + <code>predicate(arity [, table_name [, columns]])</code> + <br/><br/> + and columns is in the form + <br/><br/> + <code>columns( col_name(col_type), col_name(col_type), ....)</code> + <br/><br/> + </ul> + + <p>Example in .mas2j project, the agent c uses a JDBC belief base:<br> + <br/> + <pre> agents: c beliefBaseClass jason.bb.JDBCPersistentBB( "org.hsqldb.jdbcDriver", // driver for HSQLDB "jdbc:hsqldb:bookstore", // URL connection "sa", // user "", // 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 - // have to be created; - // if no column name/type is provided, an arbitrary name is used with type varchar(256) - // predicate book (with arity 5) is mapped to a table called "book" - // if no table name is provided the predicate name is used for the table name - // the columns for author are "id" (an integer) and "name" (char); - // and so on... + "[a(1,tablea,columns(runs(integer))), + book(5), + book_author(2), + author(2,author,columns(id(integer),name(varchar(30)))), + publisher(2)]"); </pre> - * </blockquote> - * - * @author Jomi + + <p>The predicate <code>a/1</code> is mapped to a table called "tablea" with an integer column called runs; + predicate <code>book</code> (with arity 5) is mapped to a table called "book"; and so on. + + + <p>The name and type of the columns are used only if the table does not exits and have to be created. + If no column name/type is provided, an arbitrary name is used with type varchar(256). + If no table name is provided, the predicate name is used for the table name. + <br/> + + @author Jomi */ public class JDBCPersistentBB extends DefaultBeliefBase { private static Logger logger = Logger.getLogger(JDBCPersistentBB.class.getName()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2008-09-10 09:42:30
|
Revision: 1363 http://jason.svn.sourceforge.net/jason/?rev=1363&view=rev Author: jomifred Date: 2008-09-10 09:42:28 +0000 (Wed, 10 Sep 2008) Log Message: ----------- use agent scheduler instead of a new thread for send ask with timeout Modified Paths: -------------- trunk/src/jason/asSemantics/SuspendInternalAction.java trunk/src/jason/stdlib/send.java Modified: trunk/src/jason/asSemantics/SuspendInternalAction.java =================================================================== --- trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-09-09 11:44:01 UTC (rev 1362) +++ trunk/src/jason/asSemantics/SuspendInternalAction.java 2008-09-10 09:42:28 UTC (rev 1363) @@ -10,11 +10,11 @@ /** - This class can be used in place of DefaultInternalAction to create IA that - suspend/resume the intention. + This class can be used in place of DefaultInternalAction to create an IA that + suspend the intention while it is being executed. - Example: a plan should to ask something to an user and wait until he/she answer some. - If DefaultInternalAction is used for that, all the agent thread is suspended until + Example: a plan may ask something to an user and wait the answer. + If DefaultInternalAction is used for that, all the agent thread is blocked until the answer. With SuspendInternalAction, only the intention using the IA is suspended. See demos/gui/gui1. Modified: trunk/src/jason/stdlib/send.java =================================================================== --- trunk/src/jason/stdlib/send.java 2008-09-09 11:44:01 UTC (rev 1362) +++ trunk/src/jason/stdlib/send.java 2008-09-10 09:42:28 UTC (rev 1363) @@ -25,18 +25,20 @@ package jason.stdlib; import jason.JasonException; -import jason.asSemantics.Circumstance; import jason.asSemantics.DefaultInternalAction; import jason.asSemantics.Intention; import jason.asSemantics.Message; import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; +import jason.asSyntax.Atom; import jason.asSyntax.ListTerm; import jason.asSyntax.NumberTerm; import jason.asSyntax.StringTerm; import jason.asSyntax.Structure; import jason.asSyntax.Term; +import java.util.concurrent.TimeUnit; + /** <p>Internal action: <b><code>.send</code></b>. @@ -121,18 +123,15 @@ private boolean lastSendWasSynAsk = false; @Override - public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception { - Term to = null; - Term ilf = null; - Term pcnt = null; - // check parameters + public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception { try { - to = args[0]; - ilf = args[1]; - pcnt = args[2]; + // check parameters + Term to = args[0]; + Term ilf = args[1]; + Term pcnt = args[2]; if (!to.isAtom() && !to.isList() && !to.isString()) { - throw new JasonException("The TO parameter ('"+to+"') of the internal action 'send' is not an atom or list of atoms!"); + throw new JasonException("The TO parameter ('"+to+"') of the internal action 'send' is not an atom, a string nor a list of receivers!"); } if (! ilf.isAtom()) { @@ -145,28 +144,26 @@ // ((Pred)pcnt).delSources(); //} catch (Exception e) {} - } catch (ArrayIndexOutOfBoundsException e) { - throw new JasonException("The internal action 'send' to '"+to+"' has not received three arguments."); - } - Message m = new Message(ilf.toString(), ts.getUserAgArch().getAgName(), null, pcnt); - - // async ask has a fourth argument and should suspend the intention - lastSendWasSynAsk = m.isAsk() && args.length > 3; - if (lastSendWasSynAsk) { - ts.getC().getPendingIntentions().put(m.getMsgId(), ts.getC().getSelectedIntention()); - } - - // (un)tell or unknown performative with 4 args is a reply to - if ( (m.isTell() || m.isUnTell() || !m.isKnownPerformative()) && args.length > 3) { - Term mid = args[3]; - if (! mid.isAtom()) { - throw new JasonException("The Message ID ('"+mid+"') parameter of the internal action 'send' is not an atom!"); + + // create a message to be sent + final Message m = new Message(ilf.toString(), ts.getUserAgArch().getAgName(), null, pcnt); + + // async ask has a fourth argument and should suspend the intention + lastSendWasSynAsk = m.isAsk() && args.length > 3; + if (lastSendWasSynAsk) { + ts.getC().getPendingIntentions().put(m.getMsgId(), ts.getC().getSelectedIntention()); } - m.setInReplyTo(mid.toString()); - } + + // (un)tell or unknown performative with 4 args is a reply to + if ( (m.isTell() || m.isUnTell() || !m.isKnownPerformative()) && args.length > 3) { + Term mid = args[3]; + if (! mid.isAtom()) { + throw new JasonException("The Message ID ('"+mid+"') parameter of the internal action 'send' is not an atom!"); + } + m.setInReplyTo(mid.toString()); + } - // send the message - try { + // send the message if (to.isList()) { if (m.isAsk() && args.length > 3) { throw new JasonException("Cannot send 'ask' to a list of receivers!"); @@ -197,54 +194,37 @@ // get the timeout deadline Term tto = (Term)args[4]; if (tto.isNumeric()) { - new CheckTimeout((long)((NumberTerm)tto).solve(), m.getMsgId(), ts.getC()).start(); + ts.getAg().getScheduler().schedule( new Runnable() { + public void run() { + // if the intention is still in PI, brings it back to C.I + Intention intention = ts.getC().getPendingIntentions().remove(m.getMsgId()); + if (intention != null) { + // unify "timeout" with the fourth parameter of .send + Structure send = (Structure)intention.peek().removeCurrentStep(); + intention.peek().getUnif().unifies(send.getTerm(3), new Atom("timeout")); + // add the intention back in C.I + ts.getC().addIntention(intention); + System.out.println("OK"); + } + } + }, (long)((NumberTerm)tto).solve(), TimeUnit.MILLISECONDS); } else { throw new JasonException("The 5th parameter of send must be a number (timeout) and not '"+tto+"'!"); } } return true; + } catch (ArrayIndexOutOfBoundsException e) { + throw new JasonException("The internal action 'send' to '"+args[0]+"' has not received three arguments."); + } catch (JasonException e) { + throw e; } catch (Exception e) { - throw new JasonException("Error sending message " + m + "\nError: "+e, e); + throw new JasonException("Error sending message " + args + "\nError: "+e, e); } } @Override public boolean suspendIntention() { return lastSendWasSynAsk; - } - - - private static Structure timeoutTerm = new Structure("timeout"); - - class CheckTimeout extends Thread { - - private long timeout = 0; - private String idInPending; - private Circumstance c; - - public CheckTimeout(long to, String rw, Circumstance c) { - this.timeout = to; - this.idInPending = rw; - this.c = c; - } - - public void run() { - try { - sleep(timeout); - - // if the intention is still in PI, brings it back to C.I - Intention intention = c.getPendingIntentions().remove(idInPending); - if (intention != null) { - // unify "timeout" with the fourth parameter of .send - Structure send = (Structure)intention.peek().removeCurrentStep(); - intention.peek().getUnif().unifies(send.getTerm(3), timeoutTerm); - // add the intention back in C.I - c.addIntention(intention); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2008-09-22 09:01:36
|
Revision: 1376 http://jason.svn.sourceforge.net/jason/?rev=1376&view=rev Author: jomifred Date: 2008-09-22 09:01:15 +0000 (Mon, 22 Sep 2008) Log Message: ----------- change name of method copyOnlyBody in Plan.java Modified Paths: -------------- trunk/src/jason/asSemantics/IntendedMeans.java trunk/src/jason/asSyntax/Plan.java Modified: trunk/src/jason/asSemantics/IntendedMeans.java =================================================================== --- trunk/src/jason/asSemantics/IntendedMeans.java 2008-09-21 19:45:01 UTC (rev 1375) +++ trunk/src/jason/asSemantics/IntendedMeans.java 2008-09-22 09:01:15 UTC (rev 1376) @@ -48,7 +48,7 @@ private Trigger trigger; // the trigger which created this IM public IntendedMeans(Option opt, Trigger te) { - plan = opt.getPlan().copyOnlyBody(); + plan = opt.getPlan().cloneOnlyBody(); unif = opt.getUnifier(); //(Unifier)opt.getUnifier().clone(); // REMOVED: experimental Modified: trunk/src/jason/asSyntax/Plan.java =================================================================== --- trunk/src/jason/asSyntax/Plan.java 2008-09-21 19:45:01 UTC (rev 1375) +++ trunk/src/jason/asSyntax/Plan.java 2008-09-22 09:01:15 UTC (rev 1376) @@ -208,13 +208,8 @@ return p; } - /** @deprecated use copyOnlyBody */ - public Plan cloneOnlyBody() { - return copyOnlyBody(); - } - /** used to create a plan clone in a new IM */ - public Plan copyOnlyBody() { + public Plan cloneOnlyBody() { Plan p = new Plan(); if (label != null) { p.label = label; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2008-10-15 13:29:29
|
Revision: 1394 http://jason.svn.sourceforge.net/jason/?rev=1394&view=rev Author: jomifred Date: 2008-10-15 13:29:18 +0000 (Wed, 15 Oct 2008) Log Message: ----------- include a setIlForce method in Message class Modified Paths: -------------- trunk/src/jason/asSemantics/Message.java trunk/src/jason/mas2j/AgentParameters.java trunk/src/jason/runtime/Settings.java Modified: trunk/src/jason/asSemantics/Message.java =================================================================== --- trunk/src/jason/asSemantics/Message.java 2008-10-06 23:54:26 UTC (rev 1393) +++ trunk/src/jason/asSemantics/Message.java 2008-10-15 13:29:18 UTC (rev 1394) @@ -72,6 +72,10 @@ return ilForce; } + public void setIlForce(String ilf) { + ilForce = ilf; + } + public boolean isAsk() { return ilForce.startsWith("ask"); } Modified: trunk/src/jason/mas2j/AgentParameters.java =================================================================== --- trunk/src/jason/mas2j/AgentParameters.java 2008-10-06 23:54:26 UTC (rev 1393) +++ trunk/src/jason/mas2j/AgentParameters.java 2008-10-15 13:29:18 UTC (rev 1394) @@ -64,6 +64,9 @@ public void setArchClass(String c) { if (c != null) archClass = new ClassParameters(c); } + public void setArchClass(ClassParameters c) { + archClass = c; + } public void setBB(ClassParameters c) { if (c != null) bbClass = c; } Modified: trunk/src/jason/runtime/Settings.java =================================================================== --- trunk/src/jason/runtime/Settings.java 2008-10-06 23:54:26 UTC (rev 1393) +++ trunk/src/jason/runtime/Settings.java 2008-10-15 13:29:18 UTC (rev 1394) @@ -199,6 +199,9 @@ sync = pSync; } + public Map<String,Object> getUserParameters() { + return userParameters; + } public String getUserParameter(String key) { return (String)userParameters.get(key); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2008-11-24 10:59:13
|
Revision: 1411 http://jason.svn.sourceforge.net/jason/?rev=1411&view=rev Author: jomifred Date: 2008-11-24 10:59:08 +0000 (Mon, 24 Nov 2008) Log Message: ----------- update About screen Modified Paths: -------------- trunk/src/jason/control/ExecutionControl.java trunk/src/jason/control/ExecutionControlGUI.java trunk/src/jason/jeditplugin/AboutGUI.java Modified: trunk/src/jason/control/ExecutionControl.java =================================================================== --- trunk/src/jason/control/ExecutionControl.java 2008-11-23 22:00:29 UTC (rev 1410) +++ trunk/src/jason/control/ExecutionControl.java 2008-11-24 10:59:08 UTC (rev 1411) @@ -137,7 +137,7 @@ lock.lock(); try { if (logger.isLoggable(Level.FINE)) { - logger.fine("Agent "+agName+" has finished the cycle "+cycle+", # of finished agents is "+(finished.size()+1)+"/"+nbAgs); + logger.fine("Agent "+agName+" has finished cycle "+cycle+", # of finished agents is "+(finished.size()+1)+"/"+nbAgs); if (breakpoint) logger.fine("Agent "+agName+" reached a breakpoint"); } Modified: trunk/src/jason/control/ExecutionControlGUI.java =================================================================== --- trunk/src/jason/control/ExecutionControlGUI.java 2008-11-23 22:00:29 UTC (rev 1410) +++ trunk/src/jason/control/ExecutionControlGUI.java 2008-11-24 10:59:08 UTC (rev 1411) @@ -463,7 +463,7 @@ this.breakpoint = breakpoint; if (waitSelectedAg) { countCycles++; - logger.info("Agent "+agName+" has finished the cycle "+cycle); + logger.info("Agent "+agName+" has finished cycle "+cycle); if (testStop()) { stopRun(); } else { @@ -479,7 +479,7 @@ /** called when all agents have finished the current cycle */ protected void allAgsFinished() { if (waitAllAgs) { - logger.fine("All agents have finished the cycle "+getCycleNumber()); + logger.fine("All agents have finished cycle "+getCycleNumber()); countCycles++; if (testStop()) { stopRun(); Modified: trunk/src/jason/jeditplugin/AboutGUI.java =================================================================== --- trunk/src/jason/jeditplugin/AboutGUI.java 2008-11-23 22:00:29 UTC (rev 1410) +++ trunk/src/jason/jeditplugin/AboutGUI.java 2008-11-24 10:59:08 UTC (rev 1411) @@ -23,7 +23,7 @@ JOptionPane.showMessageDialog(parent, version + build+ - "Copyright (C) 2003-2008 Rafael H. Bordini, Jomi F. Hubner, et al.\n\n"+ + "Copyright (C) 2003-2008 Jomi F. Hubner & Rafael H. Bordini.\n\n"+ "This library is free software; you can redistribute it and/or\n"+ "modify it under the terms of the GNU Lesser General Public\n"+ "License as published by the Free Software Foundation; either\n"+ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2008-11-24 13:06:19
|
Revision: 1412 http://jason.svn.sourceforge.net/jason/?rev=1412&view=rev Author: jomifred Date: 2008-11-24 13:06:14 +0000 (Mon, 24 Nov 2008) Log Message: ----------- add default source code for new agents created from the list of agents in jEdit Modified Paths: -------------- trunk/src/jason/jeditplugin/JasonID.java trunk/src/jason/mas2j/AgentParameters.java Modified: trunk/src/jason/jeditplugin/JasonID.java =================================================================== --- trunk/src/jason/jeditplugin/JasonID.java 2008-11-24 10:59:08 UTC (rev 1411) +++ trunk/src/jason/jeditplugin/JasonID.java 2008-11-24 13:06:14 UTC (rev 1412) @@ -269,10 +269,24 @@ void openAgentBuffer(AgentParameters ap) { try { - org.gjt.sp.jedit.jEdit.openFile(view, ap.asSource.getAbsolutePath()); + boolean newFile = !(new File(ap.asSource.getAbsolutePath()).exists()); + Buffer nb = org.gjt.sp.jedit.jEdit.openFile(view, ap.asSource.getAbsolutePath()); // textArea.append(lstAgs.getSelectedValue()+""); - } catch (Exception ex) { - } + if (newFile) { + try { + Buffer projectb = getProjectBuffer(); + ap.asSource = new File(projectb.getDirectory() + ap.name + "." + MAS2JProject.AS_EXT); + String agcode = Config.get().getTemplate("agent.asl"); + agcode = agcode.replace("<AG_NAME>", ap.getAgName()); + agcode = agcode.replace("<PROJECT_NAME>", projectb.getName()); + nb.writeLock(); + nb.insert(0, agcode); + nb.save(view, ap.asSource.getAbsolutePath()); + } finally { + nb.writeUnlock(); + } + } + } catch (Exception ex) {} } public void handleMessage(EBMessage message) { Modified: trunk/src/jason/mas2j/AgentParameters.java =================================================================== --- trunk/src/jason/mas2j/AgentParameters.java 2008-11-24 10:59:08 UTC (rev 1411) +++ trunk/src/jason/mas2j/AgentParameters.java 2008-11-24 13:06:14 UTC (rev 1412) @@ -127,5 +127,9 @@ } return stts; - } + } + + public String getAgName() { + return name; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2008-11-27 18:40:39
|
Revision: 1416 http://jason.svn.sourceforge.net/jason/?rev=1416&view=rev Author: jomifred Date: 2008-11-27 18:40:36 +0000 (Thu, 27 Nov 2008) Log Message: ----------- deprecate the old name of the method Modified Paths: -------------- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java trunk/src/jason/infra/jade/JadeRuntimeServices.java trunk/src/jason/infra/saci/SaciRuntimeServices.java trunk/src/jason/runtime/RuntimeServicesInfraTier.java Modified: trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2008-11-27 18:27:11 UTC (rev 1415) +++ trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2008-11-27 18:40:36 UTC (rev 1416) @@ -77,7 +77,13 @@ public Set<String> getAgentsNames() { return masRunner.getAgs().keySet(); } + + /** @deprecated use getAgentsNames() */ + public Set<String> getAgentsName() { + return getAgentsNames(); + } + public int getAgentsQty() { return masRunner.getAgs().keySet().size(); } Modified: trunk/src/jason/infra/jade/JadeRuntimeServices.java =================================================================== --- trunk/src/jason/infra/jade/JadeRuntimeServices.java 2008-11-27 18:27:11 UTC (rev 1415) +++ trunk/src/jason/infra/jade/JadeRuntimeServices.java 2008-11-27 18:40:36 UTC (rev 1416) @@ -99,6 +99,11 @@ return null; } + /** @deprecated use getAgentsNames() */ + public Set<String> getAgentsName() { + return getAgentsNames(); + } + public int getAgentsQty() { try { return getAgentsNames().size(); Modified: trunk/src/jason/infra/saci/SaciRuntimeServices.java =================================================================== --- trunk/src/jason/infra/saci/SaciRuntimeServices.java 2008-11-27 18:27:11 UTC (rev 1415) +++ trunk/src/jason/infra/saci/SaciRuntimeServices.java 2008-11-27 18:40:36 UTC (rev 1416) @@ -94,7 +94,13 @@ } return null; } + + /** @deprecated use getAgentsNames() */ + public Set<String> getAgentsName() { + return getAgentsNames(); + } + public int getAgentsQty() { try { return facilitator.getAgQty() - 3; // do not include controller, Modified: trunk/src/jason/runtime/RuntimeServicesInfraTier.java =================================================================== --- trunk/src/jason/runtime/RuntimeServicesInfraTier.java 2008-11-27 18:27:11 UTC (rev 1415) +++ trunk/src/jason/runtime/RuntimeServicesInfraTier.java 2008-11-27 18:40:36 UTC (rev 1416) @@ -47,6 +47,9 @@ /** Returns a set of all agents' name */ public Set<String> getAgentsNames(); + /** @deprecated use getAgentsNames */ + public Set<String> getAgentsName(); + /** Gets the number of agents in the MAS. */ public int getAgentsQty(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2009-02-15 11:13:24
|
Revision: 1445 http://jason.svn.sourceforge.net/jason/?rev=1445&view=rev Author: jomifred Date: 2009-02-15 11:13:20 +0000 (Sun, 15 Feb 2009) Log Message: ----------- for messages send to itself, the sender is 'self' now, and not the agent's name Modified Paths: -------------- trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSyntax/VarTerm.java Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-14 18:08:49 UTC (rev 1444) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-15 11:13:20 UTC (rev 1445) @@ -23,7 +23,6 @@ package jason.asSemantics; -import jade.domain.introspection.GetValue; import jason.JasonException; import jason.RevisionFailedException; import jason.architecture.AgArch; @@ -194,8 +193,11 @@ } else if (conf.ag.socAcc(m)) { // generate an event + String sender = m.getSender(); + if (sender.equals(agArch.getAgName())) + sender = "self"; Literal received = new LiteralImpl("kqml_received").addTerms( - new Atom(m.getSender()), + new Atom(sender), new Atom(m.getIlForce()), content, new Atom(m.getMsgId())); Modified: trunk/src/jason/asSyntax/VarTerm.java =================================================================== --- trunk/src/jason/asSyntax/VarTerm.java 2009-02-14 18:08:49 UTC (rev 1444) +++ trunk/src/jason/asSyntax/VarTerm.java 2009-02-15 11:13:20 UTC (rev 1445) @@ -271,9 +271,11 @@ @Override public void addTerm(Term t) { - if (value != null && value.isStructure()) { - ((Structure)getValue()).addTerm(t); - } + if (value != null) + if (value.isStructure()) + ((Structure)getValue()).addTerm(t); + else + logger.log(Level.WARNING, "The addTerm '"+t+"' in "+this+" was lost, since this var value is not a Structure. The value's class is "+getValue().getClass().getName(), new Exception()); } @Override @@ -296,8 +298,13 @@ @Override public Literal setTerms(List<Term> l) { - if (value != null && value.isStructure()) { - return ((Structure)getValue()).setTerms(l); + if (value != null) { + if (value.isStructure()) { + return ((Structure)getValue()).setTerms(l); + } else { + logger.log(Level.WARNING, "The setTerms '"+l+"' in "+this+" was lost, since this var value is not a Structure. The value's class is "+getValue().getClass().getName(), new Exception()); + return null; + } } else { return this; } @@ -305,16 +312,20 @@ @Override public void setTerm(int i, Term t) { - if (value != null && value.isStructure()) { - ((Structure)getValue()).setTerm(i,t); - } + if (value != null) + if (value.isStructure()) + ((Structure)getValue()).setTerm(i,t); + else + logger.log(Level.WARNING, "The setTerm '"+t+"' in "+this+" was lost, since this var value is not a Structure. The value's class is "+getValue().getClass().getName(), new Exception()); } @Override public Literal addTerms(List<Term> l) { - if (value != null && value.isStructure()) { - return ((Structure)getValue()).addTerms(l); - } + if (value != null) + if (value.isStructure()) + return ((Structure)getValue()).addTerms(l); + else + logger.log(Level.WARNING, "The addTerms '"+l+"' in "+this+" was lost, since this var value is not a Structure. The value's class is "+getValue().getClass().getName(), new Exception()); return this; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2009-02-18 13:17:13
|
Revision: 1447 http://jason.svn.sourceforge.net/jason/?rev=1447&view=rev Author: jomifred Date: 2009-02-18 13:17:08 +0000 (Wed, 18 Feb 2009) Log Message: ----------- improve constructor of PlanBodyImpl to deal with Atom arguments Modified Paths: -------------- trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSyntax/Literal.java trunk/src/jason/asSyntax/PlanBodyImpl.java trunk/src/jason/stdlib/add_annot.java trunk/src/jason/stdlib/remove_plan.java Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-16 09:17:07 UTC (rev 1446) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-18 13:17:08 UTC (rev 1447) @@ -626,8 +626,8 @@ // manage the case of var unified with atom if (body instanceof VarTerm) { Term v = ((VarTerm)body).getValue(); - if (v != null && v instanceof Atom) - body = new LiteralImpl((Atom)v); + if (v != null && v instanceof Literal) + body = ((Literal)v).forceLiteralImplClass(); } if (!body.hasSource()) { // do not add source(self) in case the Modified: trunk/src/jason/asSyntax/Literal.java =================================================================== --- trunk/src/jason/asSyntax/Literal.java 2009-02-16 09:17:07 UTC (rev 1446) +++ trunk/src/jason/asSyntax/Literal.java 2009-02-18 13:17:08 UTC (rev 1447) @@ -379,6 +379,17 @@ } } + /** + * Returns 'this' if this class is LiteralImpl, otherwise, create a new instance of LiteralImpl based on 'this'. + * This method is useful to translate Atoms to LiteralImpl. + */ + public Literal forceLiteralImplClass() { + if (this instanceof LiteralImpl) + return this; + else // it is Atom, Structure, Pred but not LiteralImpl + return new LiteralImpl(this); + } + @SuppressWarnings("serial") static final class TrueLiteral extends LiteralImpl { public TrueLiteral() { Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java =================================================================== --- trunk/src/jason/asSyntax/PlanBodyImpl.java 2009-02-16 09:17:07 UTC (rev 1446) +++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2009-02-18 13:17:08 UTC (rev 1447) @@ -38,10 +38,14 @@ public PlanBodyImpl(BodyType t, Term b) { super(BODY_PLAN_FUNCTOR, 0); - term = b; formType = t; - if (b != null) + if (b != null) { srcInfo = b.getSrcInfo(); + if (b instanceof Literal) { + b = ((Literal)b).forceLiteralImplClass(); + } + } + term = b; } public void setBodyNext(PlanBody next) { Modified: trunk/src/jason/stdlib/add_annot.java =================================================================== --- trunk/src/jason/stdlib/add_annot.java 2009-02-16 09:17:07 UTC (rev 1446) +++ trunk/src/jason/stdlib/add_annot.java 2009-02-18 13:17:08 UTC (rev 1447) @@ -29,11 +29,9 @@ import jason.asSemantics.InternalAction; import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; -import jason.asSyntax.Atom; import jason.asSyntax.ListTerm; import jason.asSyntax.ListTermImpl; import jason.asSyntax.Literal; -import jason.asSyntax.LiteralImpl; import jason.asSyntax.Term; /** @@ -88,7 +86,7 @@ return un.unifies(result,args[2]); } - public Term addAnnotToList(Unifier unif, Term l, Term annot) throws JasonException { + protected Term addAnnotToList(Unifier unif, Term l, Term annot) throws JasonException { if (l.isList()) { ListTerm result = new ListTermImpl(); for (Term lTerm: (ListTerm)l) { @@ -99,14 +97,7 @@ } return result; } else if (l.isLiteral()) { - Literal result; - if (l.isAtom()) { - result = new LiteralImpl((Atom)l); - } else { - result = (Literal)l.clone(); - } - result.addAnnot(annot); - return result; + return ((Literal)l).forceLiteralImplClass().copy().addAnnots(annot); } return l; } Modified: trunk/src/jason/stdlib/remove_plan.java =================================================================== --- trunk/src/jason/stdlib/remove_plan.java 2009-02-16 09:17:07 UTC (rev 1446) +++ trunk/src/jason/stdlib/remove_plan.java 2009-02-18 13:17:08 UTC (rev 1447) @@ -86,18 +86,18 @@ Term source = BeliefBase.ASelf; if (args.length > 1) { - source = (Atom)args[1]; + source = (Atom)args[1]; } if (label.isList()) { // arg[0] is a list - boolean r = true; - ListTerm lt = (ListTerm)args[0]; + boolean r = true; + ListTerm lt = (ListTerm)args[0]; for (Term t: lt) { - r = r && ts.getAg().getPL().remove((Atom)t, source); - } - return r; + r = r && ts.getAg().getPL().remove((Atom)t, source); + } + return r; } else { // args[0] is a plan label - return ts.getAg().getPL().remove((Atom)label, source); + return ts.getAg().getPL().remove((Atom)label, source); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2009-02-19 16:00:22
|
Revision: 1451 http://jason.svn.sourceforge.net/jason/?rev=1451&view=rev Author: jomifred Date: 2009-02-19 16:00:17 +0000 (Thu, 19 Feb 2009) Log Message: ----------- another solution for the problem fixed in previous commit: changes in C are postponed to the begin of next reasoning cycle, so that only the TS thread changes C Modified Paths: -------------- trunk/src/jason/asSemantics/ConcurrentInternalAction.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/stdlib/drop_all_intentions.java trunk/src/jason/stdlib/drop_intention.java trunk/src/jason/stdlib/intend.java trunk/src/jason/stdlib/wait.java Modified: trunk/src/jason/asSemantics/ConcurrentInternalAction.java =================================================================== --- trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2009-02-19 10:50:55 UTC (rev 1450) +++ trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2009-02-19 16:00:17 UTC (rev 1451) @@ -113,24 +113,29 @@ resume(ts, intentionKey, true); } - synchronized private void resume(TransitionSystem ts, String intentionKey, boolean abort) { - Circumstance C = ts.getC(); - Intention pi = C.getPendingIntentions().remove(intentionKey); - if (pi != null) { - pi.setSuspended(false); - try { - if (abort) { - // fail the IA - ts.generateGoalDeletion(pi, null); - } else { - pi.peek().removeCurrentStep(); // remove the internal action that put the intention in suspend - ts.applyClrInt(pi); - C.addIntention(pi); // add it back in I + synchronized private void resume(final TransitionSystem ts, final String intentionKey, final boolean abort) { + // invoke changes in C latter, so to avoid concurrent changes in C + ts.runAtBeginOfNextCycle(new Runnable() { + public void run() { + Circumstance C = ts.getC(); + Intention pi = C.getPendingIntentions().remove(intentionKey); + if (pi != null) { + pi.setSuspended(false); + try { + if (abort) { + // fail the IA + ts.generateGoalDeletion(pi, null); + } else { + pi.peek().removeCurrentStep(); // remove the internal action that put the intention in suspend + ts.applyClrInt(pi); + C.addIntention(pi); // add it back in I + } + } catch (JasonException e) { + ts.getLogger().log(Level.SEVERE, "Error resuming intention", e); + } } - } catch (JasonException e) { - ts.getLogger().log(Level.SEVERE, "Error resuming intention", e); } - ts.getUserAgArch().getArchInfraTier().wake(); - } + }); + ts.getUserAgArch().getArchInfraTier().wake(); } } Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-19 10:50:55 UTC (rev 1450) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-19 16:00:17 UTC (rev 1451) @@ -52,6 +52,8 @@ import java.util.LinkedList; import java.util.List; import java.util.ListIterator; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.logging.Level; import java.util.logging.Logger; @@ -80,6 +82,8 @@ // object, this is just to make it look more like the SOS private TransitionSystem conf; + private Queue<Runnable> taskForBeginOfCycle = new ConcurrentLinkedQueue<Runnable>(); + public TransitionSystem(Agent a, Circumstance c, Settings s, AgArch ar) { ag = a; C = c; @@ -912,6 +916,14 @@ agArch.canSleep(); } + /** + * Schedule a task to be executed in the begin of the next reasoning cycle. + * It is used mostly to change the C only by the TS thread (e.g. by .wait) + */ + public void runAtBeginOfNextCycle(Runnable r) { + taskForBeginOfCycle.offer(r); + } + /**********************************************************************/ /* MAIN LOOP */ /**********************************************************************/ @@ -923,6 +935,13 @@ try { C.reset(); + // run tasks allocated to be performed in the begin of the cycle + Runnable r = taskForBeginOfCycle.poll(); + while (r != null) { + r.run(); + r = taskForBeginOfCycle.poll(); + } + if (nrcslbr >= setts.nrcbp()) { nrcslbr = 0; ag.buf(agArch.perceive()); Modified: trunk/src/jason/stdlib/drop_all_intentions.java =================================================================== --- trunk/src/jason/stdlib/drop_all_intentions.java 2009-02-19 10:50:55 UTC (rev 1450) +++ trunk/src/jason/stdlib/drop_all_intentions.java 2009-02-19 16:00:17 UTC (rev 1451) @@ -74,10 +74,8 @@ checkArguments(args); Circumstance C = ts.getC(); - synchronized (C) { // do not allow other threads (.wait) to change C meanwhile - C.clearIntentions(); - C.clearPendingIntentions(); - } + C.clearIntentions(); + C.clearPendingIntentions(); C.clearPendingActions(); // drop intentions in E Modified: trunk/src/jason/stdlib/drop_intention.java =================================================================== --- trunk/src/jason/stdlib/drop_intention.java 2009-02-19 10:50:55 UTC (rev 1450) +++ trunk/src/jason/stdlib/drop_intention.java 2009-02-19 16:00:17 UTC (rev 1451) @@ -107,20 +107,18 @@ } } - synchronized (C) { // do not allow other threads (.wait) to change the C meanwhile - for (Intention i: C.getIntentions()) { - if (i.hasTrigger(g, un)) { - C.removeIntention(i); - un = bak.clone(); - } + for (Intention i: C.getIntentions()) { + if (i.hasTrigger(g, un)) { + C.removeIntention(i); + un = bak.clone(); } - - // intention may be suspended in PI! (in the new semantics) - for (Intention i: C.getPendingIntentions().values()) { - if (i.hasTrigger(g, un)) { - C.dropPendingIntention(i); - un = bak.clone(); - } + } + + // intention may be suspended in PI! (in the new semantics) + for (Intention i: C.getPendingIntentions().values()) { + if (i.hasTrigger(g, un)) { + C.dropPendingIntention(i); + un = bak.clone(); } } } Modified: trunk/src/jason/stdlib/intend.java =================================================================== --- trunk/src/jason/stdlib/intend.java 2009-02-19 10:50:55 UTC (rev 1450) +++ trunk/src/jason/stdlib/intend.java 2009-02-19 16:00:17 UTC (rev 1451) @@ -117,21 +117,19 @@ } } - synchronized (C) { // do not allow other threads (.wait) to change C meanwhile - // intention may be suspended in PI! (in the new semantics) - if (C.hasPendingIntention()) { - for (Intention intention: C.getPendingIntentions().values()) { - if (intention.hasTrigger(g, un)) - return true; - } - } - - for (Intention i : C.getIntentions()) { - if (i.hasTrigger(g, un)) + // intention may be suspended in PI! (in the new semantics) + if (C.hasPendingIntention()) { + for (Intention intention: C.getPendingIntentions().values()) { + if (intention.hasTrigger(g, un)) return true; } } + for (Intention i : C.getIntentions()) { + if (i.hasTrigger(g, un)) + return true; + } + return false; } Modified: trunk/src/jason/stdlib/wait.java =================================================================== --- trunk/src/jason/stdlib/wait.java 2009-02-19 10:50:55 UTC (rev 1450) +++ trunk/src/jason/stdlib/wait.java 2009-02-19 16:00:17 UTC (rev 1451) @@ -162,44 +162,45 @@ } } - void resume(boolean stopByTimeout) { - try { - // unregister (for not to receive intentionAdded again) - c.removeEventListener(this); + void resume(final boolean stopByTimeout) { + // unregister (for not to receive intentionAdded again) + c.removeEventListener(this); - synchronized (c) { // block access to C, so that .drop_desire, for instance, will wait this operation to finish; - // otherwise the intention disappears between 'remove from PI' and 'add back to I' - - // add SI again in C.I if it was not removed and this wait was not dropped - if (c.getPendingIntentions().remove(sTE) == si && !c.getIntentions().contains(si) && !dropped) { - if (stopByTimeout && te != null && elapsedTimeTerm == null) { - // fail the .wait by timeout - if (si.isSuspended()) { // if the intention was suspended by .suspend - PlanBody body = si.peek().getPlan().getBody(); - body.add(1, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail"))); - c.getPendingIntentions().put(suspend.SUSPENDED_INT+si.getId(), si); + // invoke changes in C latter, so to avoid concurrent changes in C + ts.runAtBeginOfNextCycle(new Runnable() { + public void run() { + try { + // add SI again in C.I if it was not removed and this wait was not dropped + if (c.getPendingIntentions().remove(sTE) == si && !c.getIntentions().contains(si) && !dropped) { + if (stopByTimeout && te != null && elapsedTimeTerm == null) { + // fail the .wait by timeout + if (si.isSuspended()) { // if the intention was suspended by .suspend + PlanBody body = si.peek().getPlan().getBody(); + body.add(1, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail"))); + c.getPendingIntentions().put(suspend.SUSPENDED_INT+si.getId(), si); + } else { + ts.generateGoalDeletion(si, JasonException.createBasicErrorAnnots("wait_timeout", "timeout in .wait")); + } } else { - ts.generateGoalDeletion(si, JasonException.createBasicErrorAnnots("wait_timeout", "timeout in .wait")); + si.peek().removeCurrentStep(); + + if (elapsedTimeTerm != null) { + long elapsedTime = System.currentTimeMillis() - startTime; + un.unifies(elapsedTimeTerm, new NumberTermImpl(elapsedTime)); + } + if (si.isSuspended()) { // if the intention was suspended by .suspend + c.getPendingIntentions().put(suspend.SUSPENDED_INT+si.getId(), si); + } else { + c.addIntention(si); + } } - } else { - si.peek().removeCurrentStep(); - - if (elapsedTimeTerm != null) { - long elapsedTime = System.currentTimeMillis() - startTime; - un.unifies(elapsedTimeTerm, new NumberTermImpl(elapsedTime)); - } - if (si.isSuspended()) { // if the intention was suspended by .suspend - c.getPendingIntentions().put(suspend.SUSPENDED_INT+si.getId(), si); - } else { - c.addIntention(si); - } - } - ts.getUserAgArch().getArchInfraTier().wake(); + } + } catch (Exception e) { + ts.getLogger().log(Level.SEVERE, "Error at .wait thread", e); } } - } catch (Exception e) { - ts.getLogger().log(Level.SEVERE, "Error at .wait thread", e); - } + }); + ts.getUserAgArch().getArchInfraTier().wake(); } public void eventAdded(Event e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2009-12-05 19:01:17
|
Revision: 1560 http://jason.svn.sourceforge.net/jason/?rev=1560&view=rev Author: jomifred Date: 2009-12-05 19:01:10 +0000 (Sat, 05 Dec 2009) Log Message: ----------- Lists are not literals Modified Paths: -------------- trunk/src/jason/asSemantics/Unifier.java trunk/src/jason/asSyntax/ListTermImpl.java Modified: trunk/src/jason/asSemantics/Unifier.java =================================================================== --- trunk/src/jason/asSemantics/Unifier.java 2009-12-04 18:08:36 UTC (rev 1559) +++ trunk/src/jason/asSemantics/Unifier.java 2009-12-05 19:01:10 UTC (rev 1560) @@ -210,8 +210,9 @@ // if any of the terms is not a literal (is a number or a // string), they must be equal - if (!t1g.isLiteral() || !t2g.isLiteral()) - return t1g.equals(t2g); + // (for unification, lists are literals) + if (!t1g.isLiteral() && !t1g.isList() || !t2g.isLiteral() && !t2g.isList()) + return t1g.equals(t2g); // both terms are literal Modified: trunk/src/jason/asSyntax/ListTermImpl.java =================================================================== --- trunk/src/jason/asSyntax/ListTermImpl.java 2009-12-04 18:08:36 UTC (rev 1559) +++ trunk/src/jason/asSyntax/ListTermImpl.java 2009-12-05 19:01:10 UTC (rev 1560) @@ -198,6 +198,11 @@ return true; } + @Override + public boolean isLiteral() { + return false; + } + public boolean isEmpty() { return term == null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2010-07-22 13:57:01
|
Revision: 1604 http://jason.svn.sourceforge.net/jason/?rev=1604&view=rev Author: jomifred Date: 2010-07-22 13:56:55 +0000 (Thu, 22 Jul 2010) Log Message: ----------- add a method in environment to consult the percept list of agents Modified Paths: -------------- trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/environment/Environment.java Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2010-07-03 20:38:32 UTC (rev 1603) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2010-07-22 13:56:55 UTC (rev 1604) @@ -518,7 +518,7 @@ //System.out.println("*** "+bTerm+"="+bValue+" "+bTerm.isGround()+" "+u); if (bValue == null) { // the case of !A with A not ground String msg = h.getSrcInfo()+": "+ "Variable '"+bTerm+"' must be ground."; - if (!generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("body_var_unground", msg))) + if (!generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("body_var_without_value", msg))) logger.log(Level.SEVERE, msg); return; } Modified: trunk/src/jason/environment/Environment.java =================================================================== --- trunk/src/jason/environment/Environment.java 2010-07-03 20:38:32 UTC (rev 1603) +++ trunk/src/jason/environment/Environment.java 2010-07-22 13:56:55 UTC (rev 1604) @@ -140,8 +140,14 @@ /** * Returns percepts for an agent. A full copy of both common * and agent's percepts lists is returned. + * + * It returns null if the agent's perception doesn't changed since + * last call. + * + * This method is to be called by TS and should not be called + * by other objects. */ - public List<Literal> getPercepts(String agName) { + public List<Literal> getPercepts(String agName) { // TODO in a future release, call this method doPerception, and get simply returns the list // check whether this agent needs the current version of perception if (uptodateAgs.contains(agName)) { @@ -172,7 +178,36 @@ return p; } - + + /** + * Returns a copy of the perception for an agent. + * + * It is the same list returned by getPercepts, but + * doesn't consider the last call of the method. + */ + public List<Literal> consultPercepts(String agName) { + int size = percepts.size(); + List<Literal> agl = agPercepts.get(agName); + if (agl != null) { + size += agl.size(); + } + List<Literal> p = new ArrayList<Literal>(size); + + if (! percepts.isEmpty()) { // has global perception? + synchronized (percepts) { + // make a local copy of the environment percepts + // Note: a deep copy will be done by BB.add + p.addAll(percepts); + } + } + if (agl != null) { // add agent personal perception + synchronized (agl) { + p.addAll(agl); + } + } + return p; + } + /** Adds a perception for all agents */ public void addPercept(Literal per) { if (per != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2010-08-18 22:25:03
|
Revision: 1608 http://jason.svn.sourceforge.net/jason/?rev=1608&view=rev Author: jomifred Date: 2010-08-18 22:24:57 +0000 (Wed, 18 Aug 2010) Log Message: ----------- change the CircListener methods Modified Paths: -------------- trunk/src/jason/asSemantics/Circumstance.java trunk/src/jason/bb/IndexedBB.java Modified: trunk/src/jason/asSemantics/Circumstance.java =================================================================== --- trunk/src/jason/asSemantics/Circumstance.java 2010-08-10 21:46:04 UTC (rev 1607) +++ trunk/src/jason/asSemantics/Circumstance.java 2010-08-18 22:24:57 UTC (rev 1608) @@ -65,7 +65,7 @@ private Map<String, Intention> PI; // pending intentions, intentions suspended by any other reason - private List<CircumstanceListener> listeners = null; + private List<CircumstanceListener> listeners = new CopyOnWriteArrayList<CircumstanceListener>(); public Circumstance() { create(); @@ -152,21 +152,22 @@ /** Listeners */ public void addEventListener(CircumstanceListener el) { - if (listeners == null) - listeners = new CopyOnWriteArrayList<CircumstanceListener>(); + //if (listeners == null) + // listeners = new CopyOnWriteArrayList<CircumstanceListener>(); listeners.add(el); } public void removeEventListener(CircumstanceListener el) { if (el != null) { listeners.remove(el); - if (listeners.isEmpty()) - listeners = null; + //if (listeners.isEmpty()) + // listeners = null; } } public boolean hasListener() { - return listeners != null && !listeners.isEmpty(); + //return listeners != null && !listeners.isEmpty(); + return !listeners.isEmpty(); } public Collection<CircumstanceListener> getListeners() { Modified: trunk/src/jason/bb/IndexedBB.java =================================================================== --- trunk/src/jason/bb/IndexedBB.java 2010-08-10 21:46:04 UTC (rev 1607) +++ trunk/src/jason/bb/IndexedBB.java 2010-08-18 22:24:57 UTC (rev 1608) @@ -17,7 +17,7 @@ * indexed for faster access. * * <p>E.g. in a .mas2j project file:<br/> - * <code>agents: bob beliefBaseClass agent.IndexedBB("student(key,_)", "depot(_,_,_)")</code> + * <code>agents: bob beliefBaseClass jason.bb.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. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2010-08-31 14:19:39
|
Revision: 1612 http://jason.svn.sourceforge.net/jason/?rev=1612&view=rev Author: jomifred Date: 2010-08-31 14:19:32 +0000 (Tue, 31 Aug 2010) Log Message: ----------- add StdDev function (form Francisco) Modified Paths: -------------- trunk/src/jason/asSyntax/directives/FunctionRegister.java trunk/src/jason/control/ExecutionControlGUI.java Added Paths: ----------- trunk/src/jason/functions/StdDev.java Modified: trunk/src/jason/asSyntax/directives/FunctionRegister.java =================================================================== --- trunk/src/jason/asSyntax/directives/FunctionRegister.java 2010-08-30 22:23:30 UTC (rev 1611) +++ trunk/src/jason/asSyntax/directives/FunctionRegister.java 2010-08-31 14:19:32 UTC (rev 1612) @@ -13,6 +13,7 @@ import jason.functions.Random; import jason.functions.Round; import jason.functions.Sqrt; +import jason.functions.StdDev; import jason.functions.Sum; import jason.functions.ceil; import jason.functions.e; @@ -42,6 +43,7 @@ addFunction(Max.class); addFunction(Min.class); addFunction(Sum.class); + addFunction(StdDev.class); addFunction(Average.class); addFunction(Length.class); addFunction(Random.class); Modified: trunk/src/jason/control/ExecutionControlGUI.java =================================================================== --- trunk/src/jason/control/ExecutionControlGUI.java 2010-08-30 22:23:30 UTC (rev 1611) +++ trunk/src/jason/control/ExecutionControlGUI.java 2010-08-31 14:19:32 UTC (rev 1612) @@ -189,7 +189,9 @@ jTA.setText("<html><body>Select the agent to inspect.</body></html>"); JPanel spTA = new JPanel(new BorderLayout()); - spTA.add(BorderLayout.CENTER, new JScrollPane(jTA)); + JScrollPane scpTA = new JScrollPane(jTA); + //scpTA.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); + spTA.add(BorderLayout.CENTER, scpTA); spTA.setBorder(BorderFactory.createTitledBorder(BorderFactory .createEtchedBorder(), "Agent Inspection", TitledBorder.LEFT, TitledBorder.TOP)); Added: trunk/src/jason/functions/StdDev.java =================================================================== --- trunk/src/jason/functions/StdDev.java (rev 0) +++ trunk/src/jason/functions/StdDev.java 2010-08-31 14:19:32 UTC (rev 1612) @@ -0,0 +1,60 @@ +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; + +/** +<p>Function: <b><code>math.std_dev(L)</code></b>: returns the standard deviation of all values of L. + +<p>Examples:<ul> +<li> <code>math.std_dev([1,2,3])</code>: returns 1.</li> +<li> <code>math.std_dev([])</code>: returns 0.</li> +</ul> + +@author Francisco Grimaldo + +@see jason.functions.Min +@see jason.functions.Max +@see jason.functions.Sum +@see jason.functions.Average + +*/ +public class StdDev extends DefaultArithFunction { + + public String getName() { + return "math.std_dev"; + } + + @Override + public double evaluate(TransitionSystem ts, Term[] args) throws Exception { + if (args[0].isList()) { + double sum = 0, squareSum = 0, num; + int n = 0; + for (Term t: (ListTerm)args[0]) + if (t.isNumeric()) { + if (t.isNumeric()) { + num = ((NumberTerm)t).solve(); + sum += num; + n++; + } + } + double mean = sum / n; + for (Term t: (ListTerm)args[0]) + if (t.isNumeric()) { + num = ((NumberTerm)t).solve(); + squareSum += (num - mean) * (num - mean); + } + return Math.sqrt( squareSum/(n - 1) ); + } + throw new JasonException(getName()+" is not implemented for type '"+args[0]+"'."); + } + + @Override + public boolean checkArity(int a) { + return a == 1; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2010-10-19 10:16:20
|
Revision: 1620 http://jason.svn.sourceforge.net/jason/?rev=1620&view=rev Author: jomifred Date: 2010-10-19 10:16:14 +0000 (Tue, 19 Oct 2010) Log Message: ----------- fix logging problem: if verbose is not set, leave the current logging conf and do not override with INFO level. Modified Paths: -------------- trunk/src/jason/asSemantics/Agent.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/infra/centralised/CentralisedAgArch.java trunk/src/jason/infra/jade/JadeAgArch.java trunk/src/jason/infra/saci/SaciAgArch.java trunk/src/jason/runtime/Settings.java Modified: trunk/src/jason/asSemantics/Agent.java =================================================================== --- trunk/src/jason/asSemantics/Agent.java 2010-10-18 17:34:32 UTC (rev 1619) +++ trunk/src/jason/asSemantics/Agent.java 2010-10-19 10:16:14 UTC (rev 1620) @@ -207,7 +207,8 @@ Agent a = new Agent(); a.setLogger(arch); - a.logger.setLevel(this.getTS().getSettings().logLevel()); + if (this.getTS().getSettings().verbose() >= 0) + a.logger.setLevel(this.getTS().getSettings().logLevel()); a.bb = this.bb.clone(); a.pl = this.pl.clone(); @@ -519,7 +520,8 @@ public void setTS(TransitionSystem ts) { this.ts = ts; setLogger(ts.getUserAgArch()); - logger.setLevel(ts.getSettings().logLevel()); + if (ts.getSettings().verbose() >= 0) + logger.setLevel(ts.getSettings().logLevel()); } public TransitionSystem getTS() { Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2010-10-18 17:34:32 UTC (rev 1619) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2010-10-19 10:16:14 UTC (rev 1620) @@ -103,7 +103,7 @@ nrcslbr = setts.nrcbp(); // to do BR to start with setLogger(agArch); - if (setts != null) + if (setts != null && setts.verbose() >= 0) logger.setLevel(setts.logLevel()); if (a != null) Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2010-10-18 17:34:32 UTC (rev 1619) +++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2010-10-19 10:16:14 UTC (rev 1620) @@ -118,7 +118,8 @@ public void setLogger() { logger = Logger.getLogger(CentralisedAgArch.class.getName() + "." + getAgName()); - logger.setLevel(userAgArch.getTS().getSettings().logLevel()); + if (userAgArch.getTS().getSettings().verbose() >= 0) + logger.setLevel(userAgArch.getTS().getSettings().logLevel()); } public Logger getLogger() { Modified: trunk/src/jason/infra/jade/JadeAgArch.java =================================================================== --- trunk/src/jason/infra/jade/JadeAgArch.java 2010-10-18 17:34:32 UTC (rev 1619) +++ trunk/src/jason/infra/jade/JadeAgArch.java 2010-10-19 10:16:14 UTC (rev 1620) @@ -83,7 +83,8 @@ userAgArch = (AgArch) Class.forName(ap.archClass.getClassName()).newInstance(); userAgArch.setArchInfraTier(this); userAgArch.initAg(ap.agClass.getClassName(), ap.getBBClass(), ap.asSource.getAbsolutePath(), ap.getAsSetts(false, false)); - logger.setLevel(userAgArch.getTS().getSettings().logLevel()); + if (userAgArch.getTS().getSettings().verbose() >= 0) + logger.setLevel(userAgArch.getTS().getSettings().logLevel()); registerAgInDF(); Modified: trunk/src/jason/infra/saci/SaciAgArch.java =================================================================== --- trunk/src/jason/infra/saci/SaciAgArch.java 2010-10-18 17:34:32 UTC (rev 1619) +++ trunk/src/jason/infra/saci/SaciAgArch.java 2010-10-19 10:16:14 UTC (rev 1620) @@ -131,7 +131,8 @@ userAgArch = (AgArch) Class.forName(archClassName).newInstance(); userAgArch.setArchInfraTier(this); userAgArch.initAg(agClassName, bbPars, asSource, stts); - logger.setLevel(userAgArch.getTS().getSettings().logLevel()); + if (userAgArch.getTS().getSettings().verbose() >= 0) + logger.setLevel(userAgArch.getTS().getSettings().logLevel()); } catch (Exception e) { running = false; throw new JasonException("as2j: error creating the agent class! - " + e.getMessage()); Modified: trunk/src/jason/runtime/Settings.java =================================================================== --- trunk/src/jason/runtime/Settings.java 2010-10-18 17:34:32 UTC (rev 1619) +++ trunk/src/jason/runtime/Settings.java 2010-10-19 10:16:14 UTC (rev 1620) @@ -40,7 +40,7 @@ public static final boolean OSameFocus = true; public static final boolean ONewFocus = false; public static final int ODefaultNRC = 1; - public static final int ODefaultVerbose = 1; + public static final int ODefaultVerbose = -1; public static final boolean ODefaultSync = false; private static Logger logger = Logger.getLogger(Settings.class.getName()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2011-03-01 19:56:36
|
Revision: 1631 http://jason.svn.sourceforge.net/jason/?rev=1631&view=rev Author: jomifred Date: 2011-03-01 19:56:30 +0000 (Tue, 01 Mar 2011) Log Message: ----------- fix a bug reported by Francisco Grimaldo related to Execution Control Modified Paths: -------------- trunk/src/jason/control/ExecutionControl.java trunk/src/jason/infra/centralised/CentralisedExecutionControl.java Modified: trunk/src/jason/control/ExecutionControl.java =================================================================== --- trunk/src/jason/control/ExecutionControl.java 2011-02-22 11:52:25 UTC (rev 1630) +++ trunk/src/jason/control/ExecutionControl.java 2011-03-01 19:56:30 UTC (rev 1631) @@ -81,8 +81,10 @@ } // update number of agents if finished by timeout - if (to) + if (to) { + if (logger.isLoggable(Level.FINE)) logger.fine("Cycle "+getCycleNumber()+" finished by timeout!"); updateNumberOfAgents(); + } } catch (Exception e) { e.printStackTrace(); } @@ -130,7 +132,7 @@ * annotation. */ public void receiveFinishedCycle(String agName, boolean breakpoint, int cycle) { - if (nbAgs < 0 || cycle != this.cycleNumber) { + if (nbAgs < 0 || cycle != this.cycleNumber || finished.size()+1 > nbAgs) { updateNumberOfAgents(); } if (cycle == this.cycleNumber && runningCycle) { // the agent finished the current cycle Modified: trunk/src/jason/infra/centralised/CentralisedExecutionControl.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedExecutionControl.java 2011-02-22 11:52:25 UTC (rev 1630) +++ trunk/src/jason/infra/centralised/CentralisedExecutionControl.java 2011-03-01 19:56:30 UTC (rev 1631) @@ -30,6 +30,8 @@ import jason.mas2j.ClassParameters; import jason.runtime.RuntimeServicesInfraTier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; @@ -47,6 +49,8 @@ private static Logger logger = Logger.getLogger(CentralisedExecutionControl.class.getName()); + protected ExecutorService executor = Executors.newSingleThreadExecutor(); + public CentralisedExecutionControl(ClassParameters userControlClass, RunCentralisedMAS masRunner) throws JasonException { this.masRunner = masRunner; try { @@ -80,13 +84,17 @@ infraArch.receiveSyncSignal(); } - public void informAllAgsToPerformCycle(int cycle) { - synchronized (masRunner.getAgs()) { - for (CentralisedAgArch ag: masRunner.getAgs().values()) { - ag.getUserAgArch().setCycleNumber(cycle); - ag.receiveSyncSignal(); + public void informAllAgsToPerformCycle(final int cycle) { + executor.execute(new Runnable() { + public void run() { + synchronized (masRunner.getAgs()) { + for (CentralisedAgArch ag: masRunner.getAgs().values()) { + ag.getUserAgArch().setCycleNumber(cycle); + ag.receiveSyncSignal(); + } + } } - } + }); } public Document getAgState(String agName) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2011-03-08 23:39:29
|
Revision: 1634 http://jason.svn.sourceforge.net/jason/?rev=1634&view=rev Author: jomifred Date: 2011-03-08 23:39:22 +0000 (Tue, 08 Mar 2011) Log Message: ----------- Ignore tell messages answering a synchronous ask if it is received after timeout Modified Paths: -------------- trunk/src/jason/asSemantics/Message.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/stdlib/send.java Modified: trunk/src/jason/asSemantics/Message.java =================================================================== --- trunk/src/jason/asSemantics/Message.java 2011-03-08 23:00:33 UTC (rev 1633) +++ trunk/src/jason/asSemantics/Message.java 2011-03-08 23:39:22 UTC (rev 1634) @@ -43,11 +43,14 @@ public final static String[] knownPerformatives = {"tell","untell","achieve","unachieve","askOne","askAll","tellHow", "untellHow","askHow"}; + public final static String msgIdPrefix = "mid"; + public final static String msgIdSyncAskPrefix = "midsa"; + public Message() { } public Message(String ilf, String s, String r, Object c) { - this(ilf, s, r, c, "mid"+(idCount++)); + this(ilf, s, r, c, msgIdPrefix+(idCount++)); } public Message(String ilf, String s, String r, Object c, String id) { @@ -57,7 +60,6 @@ propCont = c; msgId = id; } - public Message(Message m) { ilForce = m.ilForce; @@ -67,6 +69,10 @@ msgId = m.msgId; inReplyTo= m.inReplyTo; } + + public void setSyncAskMsgId() { + msgId = msgIdSyncAskPrefix+(idCount++); + } public String getIlForce() { return ilForce; @@ -90,6 +96,10 @@ public boolean isUnTell() { return ilForce.startsWith("untell"); } + + public boolean isReplyToSyncAsk() { + return inReplyTo != null && inReplyTo.startsWith(msgIdSyncAskPrefix); + } public boolean isKnownPerformative() { for (String s: knownPerformatives) { Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2011-03-08 23:00:33 UTC (rev 1633) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2011-03-08 23:39:22 UTC (rev 1634) @@ -286,17 +286,21 @@ // the message is not an ask answer } else if (conf.ag.socAcc(m)) { - // generate an event - String sender = m.getSender(); - if (sender.equals(agArch.getAgName())) - sender = "self"; - Literal received = new LiteralImpl("kqml_received").addTerms( - new Atom(sender), - new Atom(m.getIlForce()), - content, - new Atom(m.getMsgId())); - - updateEvents(new Event(new Trigger(TEOperator.add, TEType.achieve, received), Intention.EmptyInt)); + if (! m.isReplyToSyncAsk()) { // ignore answer after the timeout + // generate an event + String sender = m.getSender(); + if (sender.equals(agArch.getAgName())) + sender = "self"; + Literal received = new LiteralImpl("kqml_received").addTerms( + new Atom(sender), + new Atom(m.getIlForce()), + content, + new Atom(m.getMsgId())); + + updateEvents(new Event(new Trigger(TEOperator.add, TEType.achieve, received), Intention.EmptyInt)); + } else { + logger.fine("Ignoring message "+m+" because it is received after the timeout."); + } } } } Modified: trunk/src/jason/stdlib/send.java =================================================================== --- trunk/src/jason/stdlib/send.java 2011-03-08 23:00:33 UTC (rev 1633) +++ trunk/src/jason/stdlib/send.java 2011-03-08 23:39:22 UTC (rev 1634) @@ -157,6 +157,7 @@ // async ask has a fourth argument and should suspend the intention lastSendWasSynAsk = m.isAsk() && args.length > 3; if (lastSendWasSynAsk) { + m.setSyncAskMsgId(); ts.getC().addPendingIntention(m.getMsgId(), ts.getC().getSelectedIntention()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2011-03-30 14:36:25
|
Revision: 1638 http://jason.svn.sourceforge.net/jason/?rev=1638&view=rev Author: jomifred Date: 2011-03-30 14:36:18 +0000 (Wed, 30 Mar 2011) Log Message: ----------- fix bug in initial beliefs with strings Modified Paths: -------------- trunk/src/jason/asSemantics/Agent.java trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc trunk/src/jason/runtime/Settings.java Modified: trunk/src/jason/asSemantics/Agent.java =================================================================== --- trunk/src/jason/asSemantics/Agent.java 2011-03-21 20:36:42 UTC (rev 1637) +++ trunk/src/jason/asSemantics/Agent.java 2011-03-30 14:36:18 UTC (rev 1638) @@ -439,8 +439,6 @@ protected void addInitialBelsFromProjectInBB() { String sBels = getTS().getSettings().getUserParameter("beliefs"); if (sBels != null) { - if (sBels.startsWith("\"") && sBels.endsWith("\"")) - sBels = sBels.substring(1, sBels.length()-1); try { for (Term t: ASSyntax.parseList("["+sBels+"]")) { getBB().add((Literal)t); @@ -470,8 +468,6 @@ protected void addInitialGoalsFromProjectInBB() { String sGoals = getTS().getSettings().getUserParameter("goals"); if (sGoals != null) { - if (sGoals.startsWith("\"") && sGoals.endsWith("\"")) - sGoals = sGoals.substring(1, sGoals.length()-1); try { for (Term t: ASSyntax.parseList("["+sGoals+"]")) { Literal g = (Literal)t; Modified: trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc =================================================================== --- trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2011-03-21 20:36:42 UTC (rev 1637) +++ trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2011-03-30 14:36:18 UTC (rev 1638) @@ -139,11 +139,20 @@ | <NUMBER: ["0"-"9"] (["0"-"9"])* > // Strings -| <STRING: "\"" ( ~["\"","\\","\n","\r"] - | "\\" ( ["n","t","b","r","f","\\","\'","\""] - | ["0"-"7"] (["0"-"7"])? - | ["0"-"3"] ["0"-"7"] ["0"-"7"]))* "\""> +| <STRING: + "\"" + ( (~["\"","\\","\n","\r"]) + | ("\\" + ( ["n","t","b","r","f","\\","'","\""] + | ["0"-"7"] ( ["0"-"7"] )? + | ["0"-"3"] ["0"-"7"] ["0"-"7"] + ) + ) + )* + "\"" + > + // Identifiers | <ASID: <LC_LETTER> (<LETTER>|<DIGIT>|"_")* > | <ID: <LETTER> (<LETTER>|<DIGIT>|"_")* > Modified: trunk/src/jason/runtime/Settings.java =================================================================== --- trunk/src/jason/runtime/Settings.java 2011-03-21 20:36:42 UTC (rev 1637) +++ trunk/src/jason/runtime/Settings.java 2011-03-30 14:36:18 UTC (rev 1638) @@ -204,8 +204,10 @@ } public String getUserParameter(String key) { String vl = (String)userParameters.get(key); - if (vl != null && vl.startsWith("\"") && vl.endsWith("\"")) + if (vl != null && vl.startsWith("\"") && vl.endsWith("\"")) { vl = vl.substring(1, vl.length()-1); + vl = vl.replaceAll("\\\\\"", "\""); + } return vl; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2011-07-18 10:10:00
|
Revision: 1652 http://jason.svn.sourceforge.net/jason/?rev=1652&view=rev Author: jomifred Date: 2011-07-18 10:09:53 +0000 (Mon, 18 Jul 2011) Log Message: ----------- implementation of backtracking for .intend and .desire Modified Paths: -------------- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc trunk/src/jason/asSyntax/parser/as2j.java trunk/src/jason/stdlib/desire.java trunk/src/jason/stdlib/intend.java Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc =================================================================== --- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2011-06-24 13:39:37 UTC (rev 1651) +++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2011-07-18 10:09:53 UTC (rev 1652) @@ -805,7 +805,7 @@ StringTerm string():{ Token k; StringTermImpl s; } { - k = <STRING> { s = new StringTermImpl(k.image.substring(1,k.image.length()-1)); + k = <STRING> { s = new StringTermImpl(k.image.substring(1,k.image.length()-1).replaceAll("\\\\n", "\n")); s.setSrcInfo(new SourceInfo(asSource,k.beginLine)); return s; } Modified: trunk/src/jason/asSyntax/parser/as2j.java =================================================================== --- trunk/src/jason/asSyntax/parser/as2j.java 2011-06-24 13:39:37 UTC (rev 1651) +++ trunk/src/jason/asSyntax/parser/as2j.java 2011-07-18 10:09:53 UTC (rev 1652) @@ -1446,7 +1446,7 @@ final public StringTerm string() throws ParseException { Token k; StringTermImpl s; k = jj_consume_token(STRING); - s = new StringTermImpl(k.image.substring(1,k.image.length()-1)); + s = new StringTermImpl(k.image.substring(1,k.image.length()-1).replaceAll("\\\\n", "\n")); s.setSrcInfo(new SourceInfo(asSource,k.beginLine)); {if (true) return s;} throw new Error("Missing return statement in function"); Modified: trunk/src/jason/stdlib/desire.java =================================================================== --- trunk/src/jason/stdlib/desire.java 2011-06-24 13:39:37 UTC (rev 1651) +++ trunk/src/jason/stdlib/desire.java 2011-07-18 10:09:53 UTC (rev 1652) @@ -35,6 +35,8 @@ import jason.asSyntax.Trigger.TEOperator; import jason.asSyntax.Trigger.TEType; +import java.util.Iterator; + /** <p>Internal action: <b><code>.desire(<i>D</i>)</code></b>. @@ -68,10 +70,15 @@ @Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception { checkArguments(args); - return desires(ts.getC(),(Literal)args[0],un); + if (args[0].isGround()) + return desires(ts.getC(),(Literal)args[0],un); + else + return allDesires(ts.getC(),(Literal)args[0],un); } public boolean desires(Circumstance C, Literal l, Unifier un) { + return allDesires(C, l, un).hasNext(); + /* Trigger teFromL = new Trigger(TEOperator.add, TEType.achieve, l); // we need to check the selected event in this cycle (already removed from E) @@ -100,5 +107,90 @@ } return super.intends(C, l, un); // Int subset Des (see the formal definitions) + */ } + + enum Step { selEvt, evt, useIntends, end } + + protected Iterator<Unifier> allDesires(final Circumstance C, final Literal l, final Unifier un) { + final Trigger teFromL = new Trigger(TEOperator.add, TEType.achieve, l); + + return new Iterator<Unifier>() { + Step curStep = Step.selEvt; + Unifier solution = null; // the current response (which is an unifier) + Iterator<Event> evtIterator = null; + Iterator<Unifier> intendInterator = null; + + public boolean hasNext() { + if (solution == null) // the first call of hasNext should find the first response + find(); + return solution != null; + } + + public Unifier next() { + if (solution == null) find(); + Unifier b = solution; + find(); // find next response + return b; + } + public void remove() {} + + void find() { + switch (curStep) { + + case selEvt: + curStep = Step.evt; // set next step + + // we need to check the selected event in this cycle (already removed from E) + if (C.getSelectedEvent() != null) { + Trigger t = C.getSelectedEvent().getTrigger(); + Intention i = C.getSelectedEvent().getIntention(); + if (i != Intention.EmptyInt && i.size() > 0) { + t = t.clone(); + t.apply(i.peek().getUnif()); + } + solution = un.clone(); + if (solution.unifiesNoUndo(teFromL, t)) { + return; + } + } + find(); + return; + + case evt: + if (evtIterator == null) + evtIterator = C.getEvents().iterator(); + + if (evtIterator.hasNext()) { + Event ei = evtIterator.next(); + Trigger t = ei.getTrigger(); + Intention i = ei.getIntention(); + if (i != Intention.EmptyInt && i.size() > 0) { + t = t.clone(); + t.apply(i.peek().getUnif()); + } + solution = un.clone(); + if (solution.unifiesNoUndo(teFromL, t)) { + return; + } + } + curStep = Step.useIntends; // set next step + find(); + return; + + case useIntends: + if (intendInterator == null) + intendInterator = allIntentions(C,l,un); + + if (intendInterator.hasNext()) { + solution = intendInterator.next(); + return; + } + curStep = Step.end; // set next step + + } + solution = null; // nothing found + } + }; + } } Modified: trunk/src/jason/stdlib/intend.java =================================================================== --- trunk/src/jason/stdlib/intend.java 2011-06-24 13:39:37 UTC (rev 1651) +++ trunk/src/jason/stdlib/intend.java 2011-07-18 10:09:53 UTC (rev 1652) @@ -24,6 +24,8 @@ package jason.stdlib; +import java.util.Iterator; + import jason.JasonException; import jason.asSemantics.ActionExec; import jason.asSemantics.Circumstance; @@ -75,17 +77,22 @@ @Override protected void checkArguments(Term[] args) throws JasonException { super.checkArguments(args); // check number of arguments - if (!args[0].isLiteral()) - throw JasonException.createWrongArgument(this,"first argument must be a literal"); + if (!args[0].isLiteral() && !args[0].isVar()) + throw JasonException.createWrongArgument(this,"first argument must be a literal or variable"); } @Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception { checkArguments(args); - return intends(ts.getC(),(Literal)args[0],un); + if (args[0].isGround()) + return intends(ts.getC(),(Literal)args[0],un); + else + return allIntentions(ts.getC(),(Literal)args[0],un); } public boolean intends(Circumstance C, Literal l, Unifier un) { + return allIntentions(C, l, un).hasNext(); + /* Trigger g = new Trigger(TEOperator.add, TEType.achieve, l); // we need to check the intention in the selected event in this cycle!!! @@ -97,7 +104,7 @@ return true; } - // we need to check the slected intention in this cycle too!!! + // we need to check the selected intention in this cycle too!!! if (C.getSelectedIntention() != null) { // logger.log(Level.SEVERE,"Int: "+g+" unif "+ts.C.SI); if (C.getSelectedIntention().hasTrigger(g, un)) @@ -138,6 +145,145 @@ } return false; + */ } + + enum Step { selEvt, selInt, evt, pendEvt, pendAct, pendInt, intentions, end } + + protected Iterator<Unifier> allIntentions(final Circumstance C, final Literal l, final Unifier un) { + final Trigger g = new Trigger(TEOperator.add, TEType.achieve, l); + + return new Iterator<Unifier>() { + Step curStep = Step.selEvt; + Unifier solution = null; // the current response (which is an unifier) + Iterator<Event> evtIterator = null; + Iterator<Event> pendEvtIterator = null; + Iterator<ActionExec> pendActIterator = null; + Iterator<Intention> pendIntIterator = null; + Iterator<Intention> intInterator = null; + + public boolean hasNext() { + if (solution == null) // the first call of hasNext should find the first response + find(); + return solution != null; + } + + public Unifier next() { + if (solution == null) find(); + Unifier b = solution; + find(); // find next response + return b; + } + public void remove() {} + + void find() { + switch (curStep) { + + case selEvt: + curStep = Step.selInt; // set next step + // we need to check the intention in the selected event in this cycle!!! + // (as it was already removed from E) + if (C.getSelectedEvent() != null) { + // logger.log(Level.SEVERE,"Int: "+g+" unif "+ts.C.SE); + if (C.getSelectedEvent().getIntention() != null) { + solution = un.clone(); + if (C.getSelectedEvent().getIntention().hasTrigger(g, solution)) + return; + } + } + find(); + return; + + case selInt: + curStep = Step.evt; // set next step + // we need to check the selected intention in this cycle too!!! + if (C.getSelectedIntention() != null) { + // logger.log(Level.SEVERE,"Int: "+g+" unif "+ts.C.SI); + solution = un.clone(); + if (C.getSelectedIntention().hasTrigger(g, solution)) + return; + } + find(); + return; + + case evt: + if (evtIterator == null) + evtIterator = C.getEvents().iterator(); + + if (evtIterator.hasNext()) { + solution = un.clone(); + Event e = evtIterator.next(); + if (e.getIntention() != null && e.getIntention().hasTrigger(g, solution)) + return; + } + curStep = Step.pendEvt; // set next step + find(); + return; + + case pendEvt: + if (pendEvtIterator == null) + pendEvtIterator = C.getPendingEvents().values().iterator(); + + if (pendEvtIterator.hasNext()) { + solution = un.clone(); + Event e = pendEvtIterator.next(); + if (e.getIntention() != null && e.getIntention().hasTrigger(g, solution)) + return; + } + curStep = Step.pendAct; // set next step + find(); + return; + + case pendAct: + // intention may be suspended in PA! (in the new semantics) + if (C.hasPendingAction()) { + if (pendActIterator == null) + pendActIterator = C.getPendingActions().values().iterator(); + + if (pendActIterator.hasNext()) { + solution = un.clone(); + ActionExec ac = pendActIterator.next(); + if (ac.getIntention().hasTrigger(g, solution)) + return; + } + } + curStep = Step.pendInt; // set next step + find(); + return; + + case pendInt: + // intention may be suspended in PI! (in the new semantics) + if (C.hasPendingIntention()) { + if (pendIntIterator == null) + pendIntIterator = C.getPendingIntentions().values().iterator(); + + if (pendIntIterator.hasNext()) { + solution = un.clone(); + Intention i = pendIntIterator.next(); + if (i.hasTrigger(g, solution)) + return; + } + } + curStep = Step.intentions; // set next step + find(); + return; + + case intentions: + if (intInterator == null) + intInterator = C.getIntentions().iterator(); + + if (intInterator.hasNext()) { + solution = un.clone(); + Intention i = intInterator.next(); + if (i.hasTrigger(g, solution)) + return; + } + curStep = Step.end; // set next step + + } + solution = null; // nothing found + } + }; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2011-09-30 23:09:21
|
Revision: 1663 http://jason.svn.sourceforge.net/jason/?rev=1663&view=rev Author: jomifred Date: 2011-09-30 23:09:14 +0000 (Fri, 30 Sep 2011) Log Message: ----------- better ratio for jason windows Modified Paths: -------------- trunk/src/jason/architecture/AgArch.java trunk/src/jason/control/ExecutionControlGUI.java trunk/src/jason/runtime/MASConsoleGUI.java Modified: trunk/src/jason/architecture/AgArch.java =================================================================== --- trunk/src/jason/architecture/AgArch.java 2011-09-29 18:18:41 UTC (rev 1662) +++ trunk/src/jason/architecture/AgArch.java 2011-09-30 23:09:14 UTC (rev 1663) @@ -195,6 +195,8 @@ * Executes the action <i>action</i> and, when finished, add it back in * <i>feedback</i> actions. */ + // TODO: remove feedback parameter and use getTS().addFeedbackAction + // for jason 2.0 to avoid backward compatibility problems public void act(ActionExec action, List<ActionExec> feedback) { if (successor != null) successor.act(action, feedback); Modified: trunk/src/jason/control/ExecutionControlGUI.java =================================================================== --- trunk/src/jason/control/ExecutionControlGUI.java 2011-09-29 18:18:41 UTC (rev 1662) +++ trunk/src/jason/control/ExecutionControlGUI.java 2011-09-30 23:09:14 UTC (rev 1663) @@ -267,7 +267,7 @@ frame.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int height = (int)(screenSize.height * 0.618); - frame.setBounds(80, 30, (int)(height*1.2), height); + frame.setBounds(80, 30, (int)(height*1.618), height); //splitPaneVer.setDividerLocation((int)(splitPaneVer.getHeight()*0.618)); //splitPaneVer.setDividerLocation(height - 200); Modified: trunk/src/jason/runtime/MASConsoleGUI.java =================================================================== --- trunk/src/jason/runtime/MASConsoleGUI.java 2011-09-29 18:18:41 UTC (rev 1662) +++ trunk/src/jason/runtime/MASConsoleGUI.java 2011-09-30 23:09:14 UTC (rev 1663) @@ -113,7 +113,9 @@ addButton(btClean); - frame.setBounds(200, 20, 824, 500); + int h = 500; + int w = (int)(h*1.618); + frame.setBounds((int)(h*0.618), 20, w, h); } public void setTitle(String s) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2011-10-10 20:28:20
|
Revision: 1665 http://jason.svn.sourceforge.net/jason/?rev=1665&view=rev Author: jomifred Date: 2011-10-10 20:28:14 +0000 (Mon, 10 Oct 2011) Log Message: ----------- improve error message when creating a project Modified Paths: -------------- trunk/src/jason/jeditplugin/NewProjectGUI.java trunk/src/jason/runtime/MASConsoleColorGUI.java Modified: trunk/src/jason/jeditplugin/NewProjectGUI.java =================================================================== --- trunk/src/jason/jeditplugin/NewProjectGUI.java 2011-10-10 20:08:20 UTC (rev 1664) +++ trunk/src/jason/jeditplugin/NewProjectGUI.java 2011-10-10 20:28:14 UTC (rev 1665) @@ -121,6 +121,7 @@ } protected boolean ok() { + System.out.println("******"); String projDecl = getProjDecl(); if (projDecl == null) { return false; @@ -129,10 +130,12 @@ File finalDir = new File(projFinalDir.getText().trim()); try { if (!finalDir.exists()) { - finalDir.mkdirs(); + boolean ok = finalDir.mkdirs(); + if (!ok) + JOptionPane.showMessageDialog(this, "Error creating project directory: "+finalDir); } } catch (Exception e) { - JOptionPane.showMessageDialog(this, "Error creating project directory: " + e); + JOptionPane.showMessageDialog(this, "Error creating project directory: "+finalDir+": " + e); return false; } Modified: trunk/src/jason/runtime/MASConsoleColorGUI.java =================================================================== --- trunk/src/jason/runtime/MASConsoleColorGUI.java 2011-10-10 20:08:20 UTC (rev 1664) +++ trunk/src/jason/runtime/MASConsoleColorGUI.java 2011-10-10 20:28:14 UTC (rev 1665) @@ -110,10 +110,11 @@ Color.gray, Color.cyan, Color.magenta, - Color.orange, - Color.pink, - Color.green, - Color.yellow}; + //Color.orange, + //Color.pink, + //Color.yellow, + Color.green + }; protected static int change = 0; protected static int lastColor = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2012-07-02 14:19:10
|
Revision: 1698 http://jason.svn.sourceforge.net/jason/?rev=1698&view=rev Author: jomifred Date: 2012-07-02 14:18:59 +0000 (Mon, 02 Jul 2012) Log Message: ----------- include clone() in IndexedBB Modified Paths: -------------- trunk/src/jason/architecture/AgArch.java trunk/src/jason/bb/ChainBB.java trunk/src/jason/bb/ChainBBAdapter.java trunk/src/jason/bb/IndexedBB.java Modified: trunk/src/jason/architecture/AgArch.java =================================================================== --- trunk/src/jason/architecture/AgArch.java 2012-06-15 17:47:19 UTC (rev 1697) +++ trunk/src/jason/architecture/AgArch.java 2012-07-02 14:18:59 UTC (rev 1698) @@ -50,7 +50,7 @@ * Each member of the chain is a subclass of AgArch. The last arch in the chain is the infrastructure tier (Centralised, JADE, Saci, ...). * The getUserAgArch method returns the first arch in the chain. * - * Users can customise the architecture by overriding some this class methods. + * Users can customise the architecture by overriding some methods of this class. */ public class AgArch implements AgArchInfraTier { @@ -250,7 +250,7 @@ return successor == null || successor.isRunning(); } - /** sets the number of the current cycle in the sync execution mode */ + /** sets the number of the current cycle */ public void setCycleNumber(int cycle) { cycleNumber = cycle; if (successor != null) @@ -261,7 +261,7 @@ setCycleNumber(cycleNumber+1); } - /** gets the current cycle number in case of running in sync execution mode */ + /** gets the current cycle number */ public int getCycleNumber() { return cycleNumber; } Modified: trunk/src/jason/bb/ChainBB.java =================================================================== --- trunk/src/jason/bb/ChainBB.java 2012-06-15 17:47:19 UTC (rev 1697) +++ trunk/src/jason/bb/ChainBB.java 2012-07-02 14:18:59 UTC (rev 1698) @@ -19,7 +19,7 @@ * * jason.bb.ChainBB( bb1, bb2, bb3, ... ) * - * where each BB is bbclass(bb paramters) + * where each BB is bbclass(bb parameters) * * e.g.: * <pre> @@ -76,7 +76,7 @@ } } - @SuppressWarnings("unchecked") + @SuppressWarnings("rawtypes") public List<Class> getChainClasses() { List<Class> r = new ArrayList<Class>(); ChainBBAdapter c = getNextAdapter(); Modified: trunk/src/jason/bb/ChainBBAdapter.java =================================================================== --- trunk/src/jason/bb/ChainBBAdapter.java 2012-06-15 17:47:19 UTC (rev 1697) +++ trunk/src/jason/bb/ChainBBAdapter.java 2012-07-02 14:18:59 UTC (rev 1698) @@ -52,7 +52,7 @@ */ @SuppressWarnings("deprecation") -public class ChainBBAdapter implements BeliefBase { +public abstract class ChainBBAdapter implements BeliefBase { protected BeliefBase nextBB = null; // the next BB in the chain Modified: trunk/src/jason/bb/IndexedBB.java =================================================================== --- trunk/src/jason/bb/IndexedBB.java 2012-06-15 17:47:19 UTC (rev 1697) +++ trunk/src/jason/bb/IndexedBB.java 2012-07-02 14:18:59 UTC (rev 1698) @@ -88,6 +88,13 @@ remove(linbb); } } - return nextBB.add(bel); + return super.add(bel); } + + @Override + public BeliefBase clone() { + IndexedBB nbb = new IndexedBB(nextBB.clone()); + nbb.indexedBels = new HashMap<String,Structure>(this.indexedBels); + return nbb; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2012-07-31 19:07:18
|
Revision: 1704 http://jason.svn.sourceforge.net/jason/?rev=1704&view=rev Author: jomifred Date: 2012-07-31 19:07:11 +0000 (Tue, 31 Jul 2012) Log Message: ----------- refactor some methods in Circumstance Modified Paths: -------------- trunk/src/jason/asSemantics/Circumstance.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/control/ExecutionControlGUI.java trunk/src/jason/infra/centralised/CentralisedAgArch.java trunk/src/jason/infra/centralised/RunCentralisedMAS.java Modified: trunk/src/jason/asSemantics/Circumstance.java =================================================================== --- trunk/src/jason/asSemantics/Circumstance.java 2012-07-15 03:02:41 UTC (rev 1703) +++ trunk/src/jason/asSemantics/Circumstance.java 2012-07-31 19:07:11 UTC (rev 1704) @@ -33,7 +33,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; @@ -51,7 +50,7 @@ private Queue<Event> E; private Queue<Intention> I; protected ActionExec A; - protected Queue<Message> MB; + private Queue<Message> MB; protected List<Option> RP; protected List<Option> AP; protected Event SE; @@ -78,7 +77,7 @@ // use LinkedList since we use a lot of remove(0) in selectEvent E = new ConcurrentLinkedQueue<Event>(); I = new ConcurrentLinkedQueue<Intention>(); - MB = new LinkedList<Message>(); + MB = new ConcurrentLinkedQueue<Message>(); PA = new ConcurrentHashMap<Integer, ActionExec>(); PI = new ConcurrentHashMap<String, Intention>(); PE = new ConcurrentHashMap<String, Event>(); @@ -201,6 +200,14 @@ public Queue<Message> getMailBox() { return MB; } + + public void addMsg(Message m) { + MB.offer(m); + } + + public boolean hasMsg() { + return !MB.isEmpty(); + } /** Intentions */ @@ -553,9 +560,9 @@ Element e; // MB - if (getMailBox() != null && !getMailBox().isEmpty()) { + if (MB != null && hasMsg()) { Element ms = (Element) document.createElement("mailbox"); - for (Message m: getMailBox()) { + for (Message m: MB) { e = (Element) document.createElement("message"); e.appendChild(document.createTextNode(m.toString())); ms.appendChild(e); Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2012-07-15 03:02:41 UTC (rev 1703) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2012-07-31 19:07:11 UTC (rev 1704) @@ -219,8 +219,8 @@ private void applyProcMsg() throws JasonException { confP.step = State.SelEv; - if (!conf.C.MB.isEmpty()) { - Message m = conf.ag.selectMessage(conf.C.MB); + if (conf.C.hasMsg()) { + Message m = conf.ag.selectMessage(conf.C.getMailBox()); if (m == null) return; // get the content, it can be any term (literal, list, number, ...; see ask) @@ -296,6 +296,9 @@ String sender = m.getSender(); if (sender.equals(getUserAgArch().getAgName())) sender = "self"; + if (m.getIlForce().equals("achieve") && content.isLiteral()) { + updateEvents(new Event(new Trigger(TEOperator.add, TEType.achieve, (Literal)content), Intention.EmptyInt)); + } else { Literal received = new LiteralImpl("kqml_received").addTerms( new Atom(sender), new Atom(m.getIlForce()), @@ -303,6 +306,7 @@ new Atom(m.getMsgId())); updateEvents(new Event(new Trigger(TEOperator.add, TEType.achieve, received), Intention.EmptyInt)); + } } else { logger.fine("Ignoring message "+m+" because it is received after the timeout."); } @@ -1080,10 +1084,10 @@ } public boolean canSleep() { - return (C.isAtomicIntentionSuspended() && conf.C.MB.isEmpty()) + return (C.isAtomicIntentionSuspended() && !conf.C.hasMsg()) || (!conf.C.hasEvent() && !conf.C.hasIntention() && !conf.C.hasFeedbackAction() && - conf.C.MB.isEmpty() && + !conf.C.hasMsg() && //taskForBeginOfCycle.isEmpty() && getUserAgArch().canSleep()); } Modified: trunk/src/jason/control/ExecutionControlGUI.java =================================================================== --- trunk/src/jason/control/ExecutionControlGUI.java 2012-07-15 03:02:41 UTC (rev 1703) +++ trunk/src/jason/control/ExecutionControlGUI.java 2012-07-31 19:07:11 UTC (rev 1704) @@ -42,6 +42,8 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; @@ -291,7 +293,8 @@ void setListOfAgsFromInfra() { try { - for (String ag: getExecutionControlInfraTier().getRuntimeServices().getAgentsNames()) { + Set<String> ags = new TreeSet<String>(getExecutionControlInfraTier().getRuntimeServices().getAgentsNames()); + for (String ag: ags) { //getExecutionControlInfraTier().getRuntimeServices().getAgentsNames()) { listModel.addElement(ag); } } catch (Exception e) { Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2012-07-15 03:02:41 UTC (rev 1703) +++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2012-07-31 19:07:11 UTC (rev 1704) @@ -29,6 +29,7 @@ import jason.architecture.MindInspectorAgArch; import jason.asSemantics.ActionExec; import jason.asSemantics.Agent; +import jason.asSemantics.Circumstance; import jason.asSemantics.Message; import jason.asSemantics.TransitionSystem; import jason.asSyntax.Literal; @@ -245,7 +246,7 @@ if (m.getSender() == null) m.setSender(getAgName()); CentralisedAgArch rec = masRunner.getAg(m.getReceiver()); - + if (rec == null) { if (isRunning()) throw new ReceiverNotFoundException("Receiver '" + m.getReceiver() + "' does not exists! Could not send " + m); @@ -276,11 +277,12 @@ // Default procedure for checking messages, move message from local mbox to C.mbox public void checkMail() { - Queue<Message> tsmb = getTS().getC().getMailBox(); - while (!mbox.isEmpty()) { - Message im = mbox.poll(); - tsmb.offer(im); + Circumstance C = getTS().getC(); + Message im = mbox.poll(); + while (im != null) { + C.addMsg(im); if (logger.isLoggable(Level.FINE)) logger.fine("received message: " + im); + im = mbox.poll(); } } Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java =================================================================== --- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2012-07-15 03:02:41 UTC (rev 1703) +++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2012-07-31 19:07:11 UTC (rev 1704) @@ -526,7 +526,6 @@ } @Override - //synchronized public void run() { if (isRunning()) { if (getTS().reasoningCycle()) { // the agent run a cycle (did not enter in sleep) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2012-12-07 10:51:18
|
Revision: 1715 http://jason.svn.sourceforge.net/jason/?rev=1715&view=rev Author: jomifred Date: 2012-12-07 10:51:06 +0000 (Fri, 07 Dec 2012) Log Message: ----------- add missing classes (related to chache query) Modified Paths: -------------- trunk/src/jason/asSemantics/QueryCacheAdv.java trunk/src/jason/asSemantics/QueryCacheSimple.java trunk/src/jason/asSyntax/InternalActionLiteral.java Added Paths: ----------- trunk/src/jason/asSemantics/QueryCacheKey.java Modified: trunk/src/jason/asSemantics/QueryCacheAdv.java =================================================================== --- trunk/src/jason/asSemantics/QueryCacheAdv.java 2012-10-17 20:21:33 UTC (rev 1714) +++ trunk/src/jason/asSemantics/QueryCacheAdv.java 2012-12-07 10:51:06 UTC (rev 1715) @@ -19,7 +19,7 @@ private Agent ag; private Map<PredicateIndicator, List<Pair<Literal,List<Unifier>>>> cache = null; private Map<PredicateIndicator, List<Pair<Literal,List<Unifier>>>> tmp = null; - private Set<CacheKey> noCache = null; + private Set<QueryCacheKey> noCache = null; private QueryProfiling prof; @@ -31,7 +31,7 @@ logger = Logger.getLogger(QueryCacheAdv.class.getName()+"-"+ag.getTS().getUserAgArch().getAgName()); cache = new HashMap<PredicateIndicator, List<Pair<Literal,List<Unifier>>>>(); tmp = new HashMap<PredicateIndicator, List<Pair<Literal,List<Unifier>>>>(); - noCache = new HashSet<CacheKey>(); + noCache = new HashSet<QueryCacheKey>(); } public void reset() { @@ -58,7 +58,7 @@ } List<Pair<Literal,List<Unifier>>> optsTmp = tmp.get(f.getPredicateIndicator()); - if (optsTmp != null && !noCache.contains(new CacheKey(f))) { + if (optsTmp != null && !noCache.contains(new QueryCacheKey(f))) { for (Pair<Literal,List<Unifier>> ic: optsTmp) { // for each possible entry in the cache //System.out.println(" try opt tmp "+ic+" "+new Unifier().unifies(f, ic.getFirst()) + " "+f.subsumes(ic.getFirst())); if (new Unifier().unifies(f, ic.getFirst()) && ic.getFirst().subsumes(f)) { @@ -69,7 +69,7 @@ final List<Unifier> listTmp = ic.getSecond(); final int listSize = listTmp.size(); - noCache.add(new CacheKey(lTmp)); + noCache.add(new QueryCacheKey(lTmp)); // use already obtained solutions return new Pair<Literal,Iterator<Unifier>>(lTmp,new Iterator<Unifier>() { @@ -118,7 +118,7 @@ } public void addAnswer(Literal f, Unifier a) { - if (noCache.contains(new CacheKey(f))) + if (noCache.contains(new QueryCacheKey(f))) return; List<Unifier> ans = null; Added: trunk/src/jason/asSemantics/QueryCacheKey.java =================================================================== --- trunk/src/jason/asSemantics/QueryCacheKey.java (rev 0) +++ trunk/src/jason/asSemantics/QueryCacheKey.java 2012-12-07 10:51:06 UTC (rev 1715) @@ -0,0 +1,61 @@ +package jason.asSemantics; + +import jason.asSyntax.Literal; + +public class QueryCacheKey { + final Literal l; + //final Unifier u; + + public QueryCacheKey(Literal o1) { + this.l = o1; + //this.u = o2; + } + + @Override + public int hashCode() { + return l.getPredicateIndicator().hashCode(); + } + + public Literal getLiteral() { + return l; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) return false; + if (obj == this) return true; + if (obj instanceof QueryCacheKey) { + if (obj.hashCode() != this.hashCode()) return false; + QueryCacheKey o = (QueryCacheKey)obj; + //System.out.println("* try cache "+o.l+" for "+this.l + " :: "+o.l.compareTo(this.l)); + return new Unifier().unifies(this.l, o.l) && o.l.subsumes(this.l); // the compare is here to avoid using p(10,Y) as cache for p(X,Y). + /* + if (!o.l.getPredicateIndicator().equals(this.l.getPredicateIndicator())) return false; // compares functor & arity + + // compare only terms ignoring unbound vars + for (int i=0; i<l.getArity(); i++) { + Term t1 = l.getTerm(i); + Term t2 = o.l.getTerm(i); + + if (t2.isVar()) { + if (o.u == null) { + continue; + } + t2 = o.u.get((VarTerm)t2); + if (t2 == null) + continue; // do not compare + } + if (!t1.equals(t2)) // TODO: it is not equals here, should be unification! + return false; + } + return true; + */ + } + return false; + } + + @Override + public String toString() { + return "<"+l+">"; + } +} Modified: trunk/src/jason/asSemantics/QueryCacheSimple.java =================================================================== --- trunk/src/jason/asSemantics/QueryCacheSimple.java 2012-10-17 20:21:33 UTC (rev 1714) +++ trunk/src/jason/asSemantics/QueryCacheSimple.java 2012-12-07 10:51:06 UTC (rev 1715) @@ -11,33 +11,12 @@ public class QueryCacheSimple { - //private Agent ag; private QueryProfiling prof; private Map<Literal, List<Unifier>> cache = null; - - /* - private int nbUpdateCycles = 0; - private int nbUpdates = 0; - private int nbReasoningCycles = 0; - private int uses = 0; - private int nbQueries = 0; - private int nbUniqueQueries = 0; - private int nbQueriesNoCache = 0; - private long timeForQueries = 0; - private long timeForUpdates = 0; - - private float p = 0; - private Set<String> uniqueQueries = new HashSet<String>(); - private Set<String> lastUniqueQueries = null; - - private static int nbAgs = -1; - */ - protected Logger logger = null; public QueryCacheSimple(Agent ag, QueryProfiling p) { - //this.ag = ag; this.prof = p; logger = Logger.getLogger(QueryCacheSimple.class.getName()+"-"+ag.getTS().getUserAgArch().getAgName()); cache = new HashMap<Literal,List<Unifier>>(); @@ -61,124 +40,4 @@ cache.put(f, r); } - /* - public void newReasoningCycle(int n) { - nbReasoningCycles = n; - } - - public void newUpdateCycle(int n, int u, long time) { - nbUpdateCycles++; // = n; - nbUpdates += u; - - timeForUpdates += time; - - //System.out.println("counting "+uniqueQueries+" cache="+cache); - - int uqSize = uniqueQueries.size(); - //System.out.println(lastUniqueQueries+" intersect "+uniqueQueries); - if (lastUniqueQueries != null) { - if (uqSize != 0) { - lastUniqueQueries.retainAll(uniqueQueries); - p += (float)lastUniqueQueries.size()/uqSize; - //System.out.println("******* "+lastUniqueQueries.size()+"/"+uqSize+"="+(float)lastUniqueQueries.size()/uqSize+ " : "+p); - //if (lastUniqueQueries.size() > uqSize) { - // System.out.println(" ***** "+lastUniqueQueries+" intersect "+uniqueQueries); - //} - } - } - nbUniqueQueries += uqSize; - - lastUniqueQueries = uniqueQueries; - cache.clear(); - uniqueQueries = new HashSet<String>(); - - if (nbAgs < 0) - try { - nbAgs = ag.getTS().getUserAgArch().getRuntimeServices().getAgentsQty(); - } catch (Exception e) { - logger.fine("Error getting number of agents: "+e); - } - } -*/ - - /* - public static int nbStops = 0; - public static float nT = 0; - public static float pT = 0; - public static float uT = 0; - public static float cqryT = 0; - public static float cupdT = 0; - //private static int nbCyclesT = 0; - private static float usesT = 0; - private static float nbQueriesT = 0; - private static float nbUniqueQueriesT = 0; - private static int nbAgsT = 0; - private static int nbupdateCyclesT = 0; - - public int getNbUses() { - return uses; - } - - public float getP() { - return p; - } - - public void newQueryStared(Literal l) { - uniqueQueries.add(l.toString()); - nbQueries++; - } - - public void addQueryTime(long ns) { - nbQueriesNoCache++; - timeForQueries += ns; - } - - public void stop() { - float N = (float)nbQueries/nbUpdateCycles; - float K = (float)nbUniqueQueries/nbUpdateCycles; - float n = N/K; - float u = (float)nbUpdates/nbUpdateCycles; - float cqry = (float)timeForQueries/nbQueriesNoCache; - float cupd = (float)timeForUpdates/nbUpdateCycles; - - p = p / nbUpdateCycles; - - if (K>0) { - nbAgsT++; - nbQueriesT += N; - nbUniqueQueriesT += K; - nT += n; - pT += p; - uT += u; - cqryT += cqry; - cupdT += cupd; - usesT += ((float)uses/nbUpdateCycles); - nbupdateCyclesT += nbUpdateCycles; - } - - logger.info("Number of update cycles : "+nbUpdateCycles); - logger.info("Number of reasoning cycles : "+nbReasoningCycles); - logger.info("Queries by cycle (N) : "+ N); - logger.info("Number of unique queries by cycle (K) : "+ K); - logger.info("N/K (n) : "+ n); - logger.info("% queries from last cycle (p) : "+ p); - logger.info("Query cost (Cqry) : "+ cqry+ " ns"); - logger.info("Number of updates by cycle (U) : "+ u); - logger.info("Update cost (Cupd) : "+ cupd+ " ns"); - logger.info("Query cache reused by cycle : "+ (float)uses/nbUpdateCycles); - - nbStops++; - if (nbStops == nbAgs) { - logger.info("* Number of reasoning cycles : "+ nbupdateCyclesT/nbAgsT); - logger.info("* Queries by cycle (N) : "+ nbQueriesT/nbAgsT); - logger.info("* Number of unique queries by cycle (K) : "+ nbUniqueQueriesT/nbAgsT); - logger.info("* N/K (n) : "+ nT/nbAgsT); - logger.info("* % queries from last cycle (p) : "+ pT/nbAgsT); - logger.info("* Query cost (Cqry) : "+ (cqry/nbAgsT)+ " ns"); - logger.info("* Number of updates by cycle (U) : "+ uT/nbAgsT); - logger.info("* Update cost (Cupd) : "+ (cupdT/nbAgsT)+ " ns"); - logger.info("* Query cache reused by cycle : "+ usesT/nbAgsT); - } - - } */ } Modified: trunk/src/jason/asSyntax/InternalActionLiteral.java =================================================================== --- trunk/src/jason/asSyntax/InternalActionLiteral.java 2012-10-17 20:21:33 UTC (rev 1714) +++ trunk/src/jason/asSyntax/InternalActionLiteral.java 2012-12-07 10:51:06 UTC (rev 1715) @@ -24,7 +24,7 @@ package jason.asSyntax; import jason.asSemantics.Agent; -import jason.asSemantics.CacheKey; +import jason.asSemantics.QueryCacheKey; import jason.asSemantics.InternalAction; import jason.asSemantics.QueryCacheAdv; import jason.asSemantics.Unifier; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |