|
From: <jom...@us...> - 2008-04-25 14:39:46
|
Revision: 1259
http://jason.svn.sourceforge.net/jason/?rev=1259&view=rev
Author: jomifred
Date: 2008-04-25 07:39:27 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
add .while internal action
Modified Paths:
--------------
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSyntax/ArithFunctionTerm.java
trunk/src/jason/asSyntax/InternalActionLiteral.java
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/stdlib/wait.java
Added Paths:
-----------
trunk/src/jason/ReceiverDoesNotExistException.java
trunk/src/jason/stdlib/loop.java
Added: trunk/src/jason/ReceiverDoesNotExistException.java
===================================================================
--- trunk/src/jason/ReceiverDoesNotExistException.java (rev 0)
+++ trunk/src/jason/ReceiverDoesNotExistException.java 2008-04-25 14:39:27 UTC (rev 1259)
@@ -0,0 +1,44 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.dur.ac.uk/r.bordini
+// http://www.inf.furb.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+
+package jason;
+
+
+public class ReceiverDoesNotExistException extends java.lang.Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public ReceiverDoesNotExistException() {
+ }
+
+ public ReceiverDoesNotExistException(String msg) {
+ super(msg);
+ }
+
+ public ReceiverDoesNotExistException(String msg, Exception cause) {
+ super(msg);
+ initCause(cause);
+ }
+
+}
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-04-25 13:29:38 UTC (rev 1258)
+++ trunk/src/jason/asSemantics/Agent.java 2008-04-25 14:39:27 UTC (rev 1259)
@@ -45,6 +45,7 @@
import jason.functions.RuleToFunction;
import jason.runtime.Settings;
import jason.stdlib.conditional;
+import jason.stdlib.loop;
import java.io.File;
import java.io.FileInputStream;
@@ -244,6 +245,8 @@
String iaName = action.getFunctor();
if (iaName.equals(".if"))
return conditional.create();
+ if (iaName.equals(".while"))
+ return loop.create();
if (iaName.charAt(0) == '.')
iaName = "jason.stdlib" + iaName;
InternalAction objIA = internalActions.get(iaName);
Modified: trunk/src/jason/asSyntax/ArithFunctionTerm.java
===================================================================
--- trunk/src/jason/asSyntax/ArithFunctionTerm.java 2008-04-25 13:29:38 UTC (rev 1258)
+++ trunk/src/jason/asSyntax/ArithFunctionTerm.java 2008-04-25 14:39:27 UTC (rev 1259)
@@ -99,8 +99,8 @@
} catch (Exception e) {
logger.log(Level.SEVERE, getErrorMsg()+ " -- "+ e);
}
- } else {
- logger.warning(getErrorMsg()+ " -- this function has unground arguments and can not be evaluated!");
+ //} else {
+ // logger.warning(getErrorMsg()+ " -- this function has unground arguments and can not be evaluated! Unifier is "+u);
}
return false;
Modified: trunk/src/jason/asSyntax/InternalActionLiteral.java
===================================================================
--- trunk/src/jason/asSyntax/InternalActionLiteral.java 2008-04-25 13:29:38 UTC (rev 1258)
+++ trunk/src/jason/asSyntax/InternalActionLiteral.java 2008-04-25 14:39:27 UTC (rev 1259)
@@ -26,6 +26,7 @@
import jason.asSemantics.Agent;
import jason.asSemantics.InternalAction;
import jason.asSemantics.Unifier;
+import jason.stdlib.loop;
import java.util.Iterator;
import java.util.logging.Level;
@@ -61,7 +62,7 @@
if (ag != null)
ia = ag.getIA(this);
}
-
+
@Override
public boolean isInternalAction() {
return true;
@@ -76,7 +77,16 @@
public boolean canBeAddedInBB() {
return false;
}
-
+
+ @Override
+ public boolean apply(Unifier u) {
+ if (this.ia != null && this.ia instanceof loop)
+ return false;
+ else
+ return super.apply(u);
+ }
+
+
@SuppressWarnings("unchecked")
public Iterator<Unifier> logicalConsequence(Agent ag, Unifier un) {
if (ag.getTS().getUserAgArch().isRunning()) {
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-04-25 13:29:38 UTC (rev 1258)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-04-25 14:39:27 UTC (rev 1259)
@@ -24,6 +24,7 @@
package jason.infra.centralised;
import jason.JasonException;
+import jason.ReceiverDoesNotExistException;
import jason.architecture.AgArch;
import jason.architecture.AgArchInfraTier;
import jason.asSemantics.ActionExec;
@@ -230,14 +231,14 @@
}
// this is used by the .send internal action in stdlib
- public void sendMsg(Message m) throws Exception {
+ public void sendMsg(Message m) throws ReceiverDoesNotExistException {
// actually send the message
m.setSender(getAgName());
CentralisedAgArch rec = masRunner.getAg(m.getReceiver());
if (rec == null) {
if (isRunning())
- throw new JasonException("Receiver '" + m.getReceiver() + "' does not exists! Could not send " + m);
+ throw new ReceiverDoesNotExistException("Receiver '" + m.getReceiver() + "' does not exists! Could not send " + m);
else
return;
}
Added: trunk/src/jason/stdlib/loop.java
===================================================================
--- trunk/src/jason/stdlib/loop.java (rev 0)
+++ trunk/src/jason/stdlib/loop.java 2008-04-25 14:39:27 UTC (rev 1259)
@@ -0,0 +1,103 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.dur.ac.uk/r.bordini
+// http://www.inf.furb.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+package jason.stdlib;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.IntendedMeans;
+import jason.asSemantics.InternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.LogicalFormula;
+import jason.asSyntax.ObjectTerm;
+import jason.asSyntax.ObjectTermImpl;
+import jason.asSyntax.PlanBody;
+import jason.asSyntax.PlanBodyImpl;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+import jason.asSyntax.PlanBody.BodyType;
+
+import java.util.Iterator;
+
+// TODO: comments
+public class loop extends DefaultInternalAction {
+
+ private static InternalAction singleton = null;
+ public static InternalAction create() {
+ if (singleton == null)
+ singleton = new loop();
+ return singleton;
+ }
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ if ( !(args[0] instanceof LogicalFormula))
+ throw new JasonException("The first argument of .while must be a logical formula.");
+
+ IntendedMeans im = ts.getC().getSelectedIntention().peek();
+ PlanBody whileia = im.getCurrentStep();
+
+ // store a backup of the unifier for the next iteration
+
+ // if the IA has a backup unifier, use that (it is an object term)
+ if (args.length == 3) {
+ // restore the unifier of previous iterations
+ Unifier ubak = (Unifier)((ObjectTerm)args[2]).getObject();
+ un.clear();
+ un.compose(ubak);
+ } else {
+ // add backup unifier in the IA
+ //ubak = (Unifier)un.clone();
+ ((Structure)whileia.getBodyTerm()).addTerm(new ObjectTermImpl(un.clone()));
+ }
+
+ LogicalFormula logExpr = (LogicalFormula)args[0].clone();
+ logExpr.apply(un); // need to apply since the internal action literal for while does not apply
+ Iterator<Unifier> iu = logExpr.logicalConsequence(ts.getAg(), un); //(Unifier)un.clone());
+ if (iu.hasNext()) {
+ if ( !args[1].isPlanBody())
+ throw new JasonException("The second argument of .while must be a plan body term.");
+
+ un.compose(iu.next());
+
+ PlanBody whattoadd = (PlanBody)args[1]; //.clone();
+ whattoadd.add(new PlanBodyImpl(BodyType.internalAction, (Term)whileia.getBodyTerm().clone())); //(PlanBody)whileia.clone()); // add the while after
+ whattoadd.setAsBodyTerm(false);
+ if (whileia.getPlanSize() == 1)
+ whileia.add(whattoadd);
+ else
+ whileia.add(1,whattoadd);
+ //System.out.println("new body="+whileia.getBodyNext());
+ }
+ return true;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new JasonException("The internal action 'while' has not received the required arguments.");
+ } catch (JasonException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JasonException("Error in internal action 'while': " + e, e);
+ }
+ }
+}
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java 2008-04-25 13:29:38 UTC (rev 1258)
+++ trunk/src/jason/stdlib/wait.java 2008-04-25 14:39:27 UTC (rev 1259)
@@ -67,8 +67,12 @@
<li> <code>.wait("+!g", 2000)</code>: suspend the intention until the goal
<code>g</code> is triggered or 2 seconds have passed, whatever happens
first. In case the event does not happens in two seconds, the internal action
- fails.
+ fails.
+ <li> <code>.wait("+!g", 2000, nofail)</code>: suspend the intention until the goal
+ <code>g</code> is triggered or 2 seconds have passed, whatever happens
+ first. In case the event does not happens in two seconds, the internal action does not
+ fail.
</ul>
@see jason.stdlib.at
@@ -88,6 +92,8 @@
public Object execute(final TransitionSystem ts, Unifier un, Term[] args) throws Exception {
long timeout = -1;
Trigger te = null;
+
+ boolean failontimeout = true;
try {
if (args[0].isNumeric()) {
// time in milliseconds
@@ -101,8 +107,9 @@
te = Trigger.parseTrigger(st.getString());
if (args.length == 2) {
- NumberTerm tot = (NumberTerm) args[1];
- timeout = (long) tot.solve();
+ timeout = (long) ((NumberTerm) args[1]).solve();
+ if (args.length == 3 && args[2].toString().equals("nofail"));
+ failontimeout = false;
}
}
@@ -110,7 +117,7 @@
ts.getLogger().log(Level.SEVERE, "Error at .wait.", e);
return false;
}
- WaitEvent wet = new WaitEvent(te, un, ts, timeout);
+ WaitEvent wet = new WaitEvent(te, un, ts, timeout, failontimeout);
wet.start();
return true;
}
@@ -139,9 +146,10 @@
boolean ok = false;
boolean drop = false;
boolean stopByTimeout = false;
+ boolean failontimeout;
long timeout = -1;
- WaitEvent(Trigger te, Unifier un, TransitionSystem ts, long to) {
+ WaitEvent(Trigger te, Unifier un, TransitionSystem ts, long to, boolean failontimeout) {
super("wait "+te);
this.te = te;
this.un = un;
@@ -149,6 +157,7 @@
c = ts.getC();
si = c.getSelectedIntention();
this.timeout = to;
+ this.failontimeout = failontimeout;
// register listener
c.addEventListener(this);
@@ -175,7 +184,7 @@
// wait was not dropped
if (c.getPendingIntentions().remove(sTE) == si && !c.getIntentions().contains(si) && !drop) {
si.peek().removeCurrentStep();
- if (stopByTimeout && te != null) {
+ if (stopByTimeout && te != null && failontimeout) {
// fail the .wait
si.peek().getPlan().getBody().add(0, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-25 20:06:11
|
Revision: 1261
http://jason.svn.sourceforge.net/jason/?rev=1261&view=rev
Author: jomifred
Date: 2008-04-25 13:05:54 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
fix bug in .wait (it does not fail by timeout)
Modified Paths:
--------------
trunk/src/jason/asSyntax/PlanBodyImpl.java
trunk/src/jason/stdlib/conditional.java
trunk/src/jason/stdlib/wait.java
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-25 17:33:58 UTC (rev 1260)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-25 20:05:54 UTC (rev 1261)
@@ -153,9 +153,10 @@
}
public boolean add(PlanBody bl) {
- if (term == null)
+ if (term == null) {
swap(bl);
- else if (next == null)
+ this.next = bl.getBodyNext();
+ } else if (next == null)
next = bl;
else
next.add(bl);
@@ -178,6 +179,8 @@
this.getLastBody().setBodyNext(newpb);
} else if (next != null) {
next.add(index - 1, bl);
+ } else {
+ next = bl;
}
return true;
}
Modified: trunk/src/jason/stdlib/conditional.java
===================================================================
--- trunk/src/jason/stdlib/conditional.java 2008-04-25 17:33:58 UTC (rev 1260)
+++ trunk/src/jason/stdlib/conditional.java 2008-04-25 20:05:54 UTC (rev 1261)
@@ -70,10 +70,7 @@
IntendedMeans im = ts.getC().getSelectedIntention().peek();
PlanBody ifia = im.getCurrentStep();
whattoadd.setAsBodyTerm(false);
- if (ifia.getPlanSize() == 1)
- ifia.add(whattoadd);
- else
- ifia.add(1,whattoadd);
+ ifia.add(1,whattoadd);
}
return true;
} catch (ArrayIndexOutOfBoundsException e) {
Modified: trunk/src/jason/stdlib/wait.java
===================================================================
--- trunk/src/jason/stdlib/wait.java 2008-04-25 17:33:58 UTC (rev 1260)
+++ trunk/src/jason/stdlib/wait.java 2008-04-25 20:05:54 UTC (rev 1261)
@@ -33,6 +33,7 @@
import jason.asSyntax.Atom;
import jason.asSyntax.InternalActionLiteral;
import jason.asSyntax.NumberTerm;
+import jason.asSyntax.PlanBody;
import jason.asSyntax.PlanBodyImpl;
import jason.asSyntax.StringTerm;
import jason.asSyntax.Term;
@@ -108,8 +109,8 @@
if (args.length == 2) {
timeout = (long) ((NumberTerm) args[1]).solve();
- if (args.length == 3 && args[2].toString().equals("nofail"));
- failontimeout = false;
+ if (args.length == 3 && args[2].toString().equals("nofail"))
+ failontimeout = false;
}
}
@@ -183,11 +184,12 @@
// 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) && !drop) {
- si.peek().removeCurrentStep();
if (stopByTimeout && te != null && failontimeout) {
// fail the .wait
- si.peek().getPlan().getBody().add(0, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
+ PlanBody body = si.peek().getPlan().getBody();
+ body.add(1, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
}
+ si.peek().removeCurrentStep();
if (si.isSuspended()) { // if the intention was suspended by .suspend
String k = suspend.SUSPENDED_INT+si.getId();
c.getPendingIntentions().put(k, si);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-04-27 13:22:44
|
Revision: 1267
http://jason.svn.sourceforge.net/jason/?rev=1267&view=rev
Author: jomifred
Date: 2008-04-27 06:22:40 -0700 (Sun, 27 Apr 2008)
Log Message:
-----------
add method addTerms in structure
Modified Paths:
--------------
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/asSyntax/ArithExpr.java
trunk/src/jason/asSyntax/BinaryStructure.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/jason/functions/RuleToFunction.java
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-26 21:45:22 UTC (rev 1266)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2008-04-27 13:22:40 UTC (rev 1267)
@@ -179,10 +179,11 @@
// generate an event
Literal received = new Literal("kqml_received");
- received.addTerm(new Atom(m.getSender()));
- received.addTerm(new Atom(m.getIlForce()));
- received.addTerm(content);
- received.addTerm(new Atom(m.getMsgId()));
+ received.addTerms(
+ new Atom(m.getSender()),
+ new Atom(m.getIlForce()),
+ content,
+ new Atom(m.getMsgId()));
updateEvents(new Event(new Trigger(TEOperator.add, TEType.achieve, received), Intention.EmptyInt));
}
Modified: trunk/src/jason/asSyntax/ArithExpr.java
===================================================================
--- trunk/src/jason/asSyntax/ArithExpr.java 2008-04-26 21:45:22 UTC (rev 1266)
+++ trunk/src/jason/asSyntax/ArithExpr.java 2008-04-27 13:22:40 UTC (rev 1267)
@@ -122,8 +122,7 @@
public ArithExpr(NumberTerm t1, ArithmeticOp oper, NumberTerm t2) {
super(oper.toString(),2);
- addTerm(t1);
- addTerm(t2);
+ addTerms(t1, t2);
op = oper;
if (t1 instanceof SourceInfo) setSrc((SourceInfo)t1);
else if (t2 instanceof SourceInfo) setSrc((SourceInfo)t2);
Modified: trunk/src/jason/asSyntax/BinaryStructure.java
===================================================================
--- trunk/src/jason/asSyntax/BinaryStructure.java 2008-04-26 21:45:22 UTC (rev 1266)
+++ trunk/src/jason/asSyntax/BinaryStructure.java 2008-04-27 13:22:40 UTC (rev 1267)
@@ -35,8 +35,7 @@
/** Constructor for binary operator */
public BinaryStructure(Term t1, String id, Term t2) {
super(id,2);
- addTerm( t1 );
- addTerm( t2 );
+ addTerms( t1, t2 );
if (t1 instanceof SourceInfo) setSrc((SourceInfo)t1);
else if (t2 instanceof SourceInfo) setSrc((SourceInfo)t2);
}
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2008-04-26 21:45:22 UTC (rev 1266)
+++ trunk/src/jason/asSyntax/Structure.java 2008-04-27 13:22:40 UTC (rev 1267)
@@ -224,10 +224,20 @@
resetHashCodeCache();
}
+ public void addTerms(Term ... ts ) {
+ for (Term t: ts) {
+ terms.add(t);
+ }
+ predicateIndicatorCache = null;
+ resetHashCodeCache();
+ }
+
public void addTerms(List<Term> l) {
for (Term t: l) {
- addTerm(t);
+ terms.add(t);
}
+ predicateIndicatorCache = null;
+ resetHashCodeCache();
}
public void setTerms(List<Term> l) {
Modified: trunk/src/jason/functions/RuleToFunction.java
===================================================================
--- trunk/src/jason/functions/RuleToFunction.java 2008-04-26 21:45:22 UTC (rev 1266)
+++ trunk/src/jason/functions/RuleToFunction.java 2008-04-27 13:22:40 UTC (rev 1267)
@@ -56,8 +56,8 @@
r = new InternalActionLiteral(literal);
else
r = new Literal(literal);
- for (Term t: args)
- r.addTerm(t);
+
+ r.addTerms(args);
VarTerm answer = new VarTerm("__RuleToFunctionResult");
r.addTerm(answer);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-06-26 15:02:53
|
Revision: 1345
http://jason.svn.sourceforge.net/jason/?rev=1345&view=rev
Author: jomifred
Date: 2008-06-26 08:02:50 -0700 (Thu, 26 Jun 2008)
Log Message:
-----------
add a new setupLogger in RunCentMAS
Modified Paths:
--------------
trunk/src/jason/asSemantics/Agent.java
trunk/src/jason/asSyntax/UnnamedVar.java
trunk/src/jason/functions/Random.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
trunk/src/jason/stdlib/nth.java
Modified: trunk/src/jason/asSemantics/Agent.java
===================================================================
--- trunk/src/jason/asSemantics/Agent.java 2008-06-24 16:19:11 UTC (rev 1344)
+++ trunk/src/jason/asSemantics/Agent.java 2008-06-26 15:02:50 UTC (rev 1345)
@@ -146,15 +146,22 @@
}
}
}
-
- // kqml Plans at the end of the ag PS
- setASLSrc("kqmlPlans.asl");
- parseAS(JasonException.class.getResource("/asl/kqmlPlans.asl"));
- setASLSrc(asSrc);
+
if (parsingOk) {
addInitialBelsInBB();
addInitialGoalsInTS();
}
+
+ // kqml Plans at the end of the ag PS
+ if (JasonException.class.getResource("/asl/kqmlPlans.asl") != null) {
+ setASLSrc("kqmlPlans.asl");
+ parseAS(JasonException.class.getResource("/asl/kqmlPlans.asl"));
+ setASLSrc(asSrc);
+ } else {
+ logger.warning("The kqmlPlans.asl was not found!");
+ }
+
+
return ts;
} catch (Exception e) {
logger.log(Level.SEVERE, "Error creating the agent class!", e);
Modified: trunk/src/jason/asSyntax/UnnamedVar.java
===================================================================
--- trunk/src/jason/asSyntax/UnnamedVar.java 2008-06-24 16:19:11 UTC (rev 1344)
+++ trunk/src/jason/asSyntax/UnnamedVar.java 2008-06-26 15:02:50 UTC (rev 1345)
@@ -42,7 +42,7 @@
public UnnamedVar(String name) {
super( name.length() == 1 ? "_" + (varCont++) : name);
- myId = varCont;
+ myId = varCont++;
}
public UnnamedVar(int id) {
Modified: trunk/src/jason/functions/Random.java
===================================================================
--- trunk/src/jason/functions/Random.java 2008-06-24 16:19:11 UTC (rev 1344)
+++ trunk/src/jason/functions/Random.java 2008-06-26 15:02:50 UTC (rev 1345)
@@ -12,7 +12,7 @@
<p>Examples:<ul>
<li> <code>math.random</code>: returns the random number between 0 and 1.</li>
- <li> <code>math.random(10)</code>: returns the random number between 0 and 10.</li>
+ <li> <code>math.random(10)</code>: returns the random number between 0 and 9.9999.</li>
</ul>
@author Jomi
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2008-06-24 16:19:11 UTC (rev 1344)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2008-06-26 15:02:50 UTC (rev 1345)
@@ -52,6 +52,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
@@ -212,10 +213,22 @@
LogManager.getLogManager().readConfiguration(RunCentralisedMAS.class.getResource("/templates/" + logPropFile).openStream());
} catch (Exception e) {
System.err.println("Error setting up logger:" + e);
+ e.printStackTrace();
}
}
}
}
+
+ public static void setupDefaultConsoleLogger() {
+ Handler[] hs = Logger.getLogger("").getHandlers();
+ for (int i = 0; i < hs.length; i++) {
+ Logger.getLogger("").removeHandler(hs[i]);
+ }
+ Handler h = new ConsoleHandler();
+ h.setFormatter(new MASConsoleLogFormatter());
+ Logger.getLogger("").addHandler(h);
+ Logger.getLogger("").setLevel(Level.INFO);
+ }
protected void createButtons() {
createStopButton();
Modified: trunk/src/jason/stdlib/nth.java
===================================================================
--- trunk/src/jason/stdlib/nth.java 2008-06-24 16:19:11 UTC (rev 1344)
+++ trunk/src/jason/stdlib/nth.java 2008-06-26 15:02:50 UTC (rev 1345)
@@ -51,12 +51,12 @@
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
if (!args[0].isNumeric()) {
- throw new JasonException("nth: the first argument should be numeric!");
+ throw new JasonException("nth: the first argument should be numeric and not '"+args[0]+"'.");
}
int index = (int)((NumberTerm)args[0]).solve();
if (!args[1].isList()) {
- throw new JasonException("nth: the second argument should be a list!");
+ throw new JasonException("nth: the second argument should be a list and not '"+args[1]+"'.");
}
ListTerm list = (ListTerm)args[1];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2008-07-02 10:14:00
|
Revision: 1346
http://jason.svn.sourceforge.net/jason/?rev=1346&view=rev
Author: jomifred
Date: 2008-07-02 03:13:59 -0700 (Wed, 02 Jul 2008)
Log Message:
-----------
set sender of messages in .send and .broadcast
Modified Paths:
--------------
trunk/src/jason/asSemantics/Message.java
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/stdlib/broadcast.java
trunk/src/jason/stdlib/send.java
Modified: trunk/src/jason/asSemantics/Message.java
===================================================================
--- trunk/src/jason/asSemantics/Message.java 2008-06-26 15:02:50 UTC (rev 1345)
+++ trunk/src/jason/asSemantics/Message.java 2008-07-02 10:13:59 UTC (rev 1346)
@@ -119,9 +119,12 @@
this.inReplyTo = inReplyTo;
}
- public Object clone() {
+ public Message copy() {
return new Message(this);
}
+ public Object clone() {
+ return new Message(this);
+ }
public String toString() {
String irt = (inReplyTo == null ? "" : "->"+inReplyTo);
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-06-26 15:02:50 UTC (rev 1345)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2008-07-02 10:13:59 UTC (rev 1346)
@@ -233,7 +233,6 @@
// this is used by the .send internal action in stdlib
public void sendMsg(Message m) throws ReceiverNotFoundException {
// actually send the message
- m.setSender(getAgName());
CentralisedAgArch rec = masRunner.getAg(m.getReceiver());
if (rec == null) {
@@ -242,14 +241,12 @@
else
return;
}
- rec.receiveMsg(new Message(m)); // send a cloned message
+ rec.receiveMsg(m.copy()); // send a cloned message
// notify listeners
- if (msgListeners != null) {
- for (MsgListener l: msgListeners) {
+ if (msgListeners != null)
+ for (MsgListener l: msgListeners)
l.msgSent(m);
- }
- }
}
public void receiveMsg(Message m) {
Modified: trunk/src/jason/stdlib/broadcast.java
===================================================================
--- trunk/src/jason/stdlib/broadcast.java 2008-06-26 15:02:50 UTC (rev 1345)
+++ trunk/src/jason/stdlib/broadcast.java 2008-07-02 10:13:59 UTC (rev 1346)
@@ -77,7 +77,7 @@
} catch (ArrayIndexOutOfBoundsException e) {
throw new JasonException("The internal action 'broadcast' has not received two arguments.");
}
- Message m = new Message(ilf.toString(), null, null, pcnt);
+ Message m = new Message(ilf.toString(), ts.getUserAgArch().getAgName(), null, pcnt);
try {
ts.getUserAgArch().broadcast(m);
Modified: trunk/src/jason/stdlib/send.java
===================================================================
--- trunk/src/jason/stdlib/send.java 2008-06-26 15:02:50 UTC (rev 1345)
+++ trunk/src/jason/stdlib/send.java 2008-07-02 10:13:59 UTC (rev 1346)
@@ -148,7 +148,7 @@
} catch (ArrayIndexOutOfBoundsException e) {
throw new JasonException("The internal action 'send' to '"+to+"' has not received three arguments.");
}
- Message m = new Message(ilf.toString(), null, null, pcnt);
+ 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;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|