You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
(35) |
Apr
(96) |
May
(39) |
Jun
(25) |
Jul
(7) |
Aug
(7) |
Sep
(44) |
Oct
(17) |
Nov
(14) |
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(5) |
Feb
(28) |
Mar
(26) |
Apr
(14) |
May
(3) |
Jun
(3) |
Jul
(13) |
Aug
(41) |
Sep
(12) |
Oct
|
Nov
(2) |
Dec
(17) |
2010 |
Jan
(9) |
Feb
(5) |
Mar
(11) |
Apr
(3) |
May
(4) |
Jun
(2) |
Jul
(3) |
Aug
(8) |
Sep
(2) |
Oct
(11) |
Nov
(3) |
Dec
(1) |
2011 |
Jan
|
Feb
(1) |
Mar
(8) |
Apr
(4) |
May
(4) |
Jun
(5) |
Jul
(3) |
Aug
(2) |
Sep
(7) |
Oct
(4) |
Nov
(4) |
Dec
(2) |
2012 |
Jan
|
Feb
|
Mar
(4) |
Apr
(11) |
May
(8) |
Jun
(2) |
Jul
(7) |
Aug
(6) |
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(3) |
2013 |
Jan
|
Feb
(1) |
Mar
(7) |
Apr
(3) |
May
(1) |
Jun
(4) |
Jul
(8) |
Aug
(4) |
Sep
(4) |
Oct
(6) |
Nov
(8) |
Dec
(6) |
2014 |
Jan
|
Feb
|
Mar
(2) |
Apr
(4) |
May
(6) |
Jun
(10) |
Jul
|
Aug
(7) |
Sep
(15) |
Oct
(4) |
Nov
(1) |
Dec
(1) |
2015 |
Jan
|
Feb
(1) |
Mar
(10) |
Apr
(4) |
May
(6) |
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(2) |
Oct
(5) |
Nov
(6) |
Dec
(12) |
2016 |
Jan
(1) |
Feb
(4) |
Mar
(7) |
Apr
(30) |
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <jom...@us...> - 2013-12-10 12:14:13
|
Revision: 1765 http://sourceforge.net/p/jason/svn/1765 Author: jomifred Date: 2013-12-10 12:14:10 +0000 (Tue, 10 Dec 2013) Log Message: ----------- fix a bug in the parser (true was an atom instead of an instance of LTrue) add source in plan body literals at compilation time (instead of runtime as done previously) Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/TestAll.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSyntax/Literal.java trunk/src/jason/asSyntax/PlanBodyImpl.java trunk/src/jason/asSyntax/Pred.java trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc trunk/src/jason/asSyntax/parser/as2j.java trunk/src/jason/bb/BeliefBase.java trunk/src/jason/bb/DefaultBeliefBase.java trunk/src/jason/stdlib/add_nested_source.java trunk/src/test/ASParserTest.java trunk/src/test/PlanTest.java trunk/src/test/StdLibTest.java Added Paths: ----------- trunk/applications/as-unit-test/src/jason/tests/BugEval.java trunk/src/test/TestAll.java Added: trunk/applications/as-unit-test/src/jason/tests/BugEval.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/BugEval.java (rev 0) +++ trunk/applications/as-unit-test/src/jason/tests/BugEval.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -0,0 +1,33 @@ +package jason.tests; + +import jason.asunit.TestAgent; + +import org.junit.Before; +import org.junit.Test; + +/** based on bug found by Grimaldo */ +public class BugEval { + + TestAgent ag; + + // initialisation of the agent test + @Before + public void setupAg() { + ag = new TestAgent(); + + // defines the agent's AgentSpeak code + ag.parseAScode( + "+!start <- A1 = false; B1 = true; .eval(X1, A1 | B1); jason.asunit.print(X1); "+ + " !a2(A2); !b2(B2); .eval(X2, A2 | B2); jason.asunit.print(X2). "+ + "+!a2(false). +!b2(true). " + ); + } + + @Test(timeout=2000) + public void test() { + ag.addGoal("start"); + ag.assertPrint("true", 10); + ag.assertPrint("true", 10); + } + +} Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -15,6 +15,7 @@ BugIfLength.class, BugUnamedVars.class, BugList1.class, + BugEval.class, TestAddLogExprInBB.class, TestGoalSource.class, TestIA.class, Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -51,7 +51,6 @@ import jason.asSyntax.UnnamedVar; import jason.asSyntax.VarTerm; import jason.asSyntax.parser.ParseException; -import jason.bb.BeliefBase; import jason.runtime.Settings; import jason.stdlib.add_nested_source; import jason.stdlib.desire; @@ -864,14 +863,14 @@ } if (adds != null) renamedVars.function.putAll(adds); - //System.out.println("depois "+body+" "+renamedVars+" u="+u); // end code for TRO } } - body = body.forceFullLiteralImpl(); - if (!body.hasSource()) { // do not add source(self) in case the programmer set the source - body.addAnnot(BeliefBase.TSelf); - } + //the code below is done in the PlanBody constructor + //body = body.forceFullLiteralImpl(); + //if (!body.hasSource()) { // do not add source(self) in case the programmer set the source + // body.addAnnot(BeliefBase.TSelf); + //} return body; } Modified: trunk/src/jason/asSyntax/Literal.java =================================================================== --- trunk/src/jason/asSyntax/Literal.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/asSyntax/Literal.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -278,7 +278,7 @@ qProfiling = null; startTime = 0; } - + final Iterator<Literal> il = ag.getBB().getCandidateBeliefs(this, un); if (il == null) // no relevant bels return LogExpr.EMPTY_UNIF_LIST.iterator(); Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java =================================================================== --- trunk/src/jason/asSyntax/PlanBodyImpl.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -2,6 +2,7 @@ import jason.asSemantics.Agent; import jason.asSemantics.Unifier; +import jason.bb.BeliefBase; import java.util.Iterator; import java.util.logging.Level; @@ -45,9 +46,30 @@ formType = t; if (b != null) { srcInfo = b.getSrcInfo(); - // the atom issue is solved in TS - //if (b.isAtom()) - // b = ((Atom)b).forceFullLiteralImpl(); + + // add source(self) in some commands (it is preferred to do this at compile time than runtime) + if (b instanceof Literal) { + switch (t) { + case achieve: + case achieveNF: + case addBel: + case addBelBegin: + case addBelEnd: + case addBelNewFocus: + case delBel: + case delAddBel: + + Literal l = (Literal)b; + l = l.forceFullLiteralImpl(); + if (!l.hasSource()) { // do not add source(self) in case the programmer set the source + l.addAnnot(BeliefBase.TSelf); + } + b = l; + + default: + break; + } + } } term = b; } Modified: trunk/src/jason/asSyntax/Pred.java =================================================================== --- trunk/src/jason/asSyntax/Pred.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/asSyntax/Pred.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -434,8 +434,34 @@ return false; } - public static Term createSource(Term source) { - Structure s = new Structure("source",1); + public static Pred createSource(Term source) { + Pred s; + if (source.isGround()) { + s = new Pred("source",1) { + @Override + public Term clone() { + return this; + } + @Override + public Term capply(Unifier u) { + return this; + } + @Override + public boolean isGround() { + return true; + } + @Override + public Literal makeVarsAnnon() { + return this; + } + @Override + public Literal makeVarsAnnon(Unifier un) { + return this; + } + }; + } else { // source is a var, so cannot be optimised + s = new Pred("source",1); + } s.addTerm(source); return s; } Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc =================================================================== --- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2013-12-10 12:14:10 UTC (rev 1765) @@ -108,11 +108,13 @@ private Term changeToAtom(Object o) { Term u = (Term)o; - if (u.isAtom()) { + if (u == Literal.LTrue) + return u; + if (u == Literal.LFalse) + return u; + if (u.isAtom()) return new Atom((Literal)u); - } else { - return u; - } + return u; } } Modified: trunk/src/jason/asSyntax/parser/as2j.java =================================================================== --- trunk/src/jason/asSyntax/parser/as2j.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/asSyntax/parser/as2j.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -77,11 +77,13 @@ private Term changeToAtom(Object o) { Term u = (Term)o; - if (u.isAtom()) { + if (u == Literal.LTrue) + return u; + if (u == Literal.LFalse) + return u; + if (u.isAtom()) return new Atom((Literal)u); - } else { - return u; - } + return u; } /* AgentSpeak Grammar */ @@ -1774,13 +1776,13 @@ return false; } - final private boolean jj_3R_47() { - if (jj_3R_55()) return true; + final private boolean jj_3R_39() { + if (jj_3R_31()) return true; return false; } - final private boolean jj_3R_39() { - if (jj_3R_31()) return true; + final private boolean jj_3R_47() { + if (jj_3R_55()) return true; return false; } Modified: trunk/src/jason/bb/BeliefBase.java =================================================================== --- trunk/src/jason/bb/BeliefBase.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/bb/BeliefBase.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -47,10 +47,10 @@ public static final Term APercept = new Atom("percept"); /** represents the structure 'source(percept)' */ - public static final Term TPercept = Pred.createSource(APercept); + public static final Pred TPercept = Pred.createSource(APercept); /** represents the structure 'source(self)' */ - public static final Term TSelf = Pred.createSource(ASelf); + public static final Pred TSelf = Pred.createSource(ASelf); /** * Called before the MAS execution with the agent that uses this Modified: trunk/src/jason/bb/DefaultBeliefBase.java =================================================================== --- trunk/src/jason/bb/DefaultBeliefBase.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/bb/DefaultBeliefBase.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -163,7 +163,7 @@ if (l.hasSubsetAnnot(bl)) { // e.g. removing b[a] or b[a,d] from BB b[a,b,c] // second case fails if (l.hasAnnot(TPercept)) { - boolean b = percepts.remove(bl); + percepts.remove(bl); } boolean result = bl.delAnnots(l.getAnnots()); // note that l annots can be empty, in this case, nothing is deleted! return removeFromEntry(bl) || result; Modified: trunk/src/jason/stdlib/add_nested_source.java =================================================================== --- trunk/src/jason/stdlib/add_nested_source.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/jason/stdlib/add_nested_source.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -85,8 +85,7 @@ @Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception { checkArguments(args); - Term result = addAnnotToList(args[0], args[1]); - return un.unifies(result,args[2]); + return un.unifies(addAnnotToList(args[0], args[1]),args[2]); } public static Term addAnnotToList(Term l, Term source) { @@ -108,7 +107,8 @@ } // create the source annots - Literal ts = new Pred("source",1).addTerms(source).addAnnots(result.getAnnots("source")); + //Literal ts = new Pred("source",1).addTerms(source).addAnnots(result.getAnnots("source")); + Literal ts = Pred.createSource(source).addAnnots(result.getAnnots("source")); result.delSources(); result.addAnnot(ts); Modified: trunk/src/test/ASParserTest.java =================================================================== --- trunk/src/test/ASParserTest.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/test/ASParserTest.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -53,6 +53,13 @@ assertFalse(l1.equals(l2)); } + public void testTrue() throws ParseException { + Term t = ASSyntax.parseTerm("true"); + assertEquals("jason.asSyntax.Literal$TrueLiteral", t.getClass().getName()); + t = ASSyntax.parseTerm("false"); + assertEquals("jason.asSyntax.Literal$FalseLiteral", t.getClass().getName()); + } + public void testKQML() { Agent ag = new Agent(); ag.initAg(); @@ -214,7 +221,7 @@ public void testParsingPlanBodyTerm1() throws ParseException { Literal l = ASSyntax.parseLiteral("p( {a1({f}); a2}, a3, {!g}, {?b;.print(oi) }, 10)"); - assertEquals("p({ a1({ f }); a2 },a3,{ !g },{ ?b; .print(oi) },10)", l.toString()); + assertEquals("p({ a1({ f }); a2 },a3,{ !g[source(self)] },{ ?b; .print(oi) },10)", l.toString()); assertEquals(5,l.getArity()); assertTrue(l.getTerm(0) instanceof PlanBody); assertTrue(l.getTerm(0).isPlanBody()); @@ -244,7 +251,7 @@ Unifier un = new Unifier(); Term t = ASSyntax.parseTerm("{ +a(10) }"); assertTrue(t.isPlanBody()); - assertEquals("{ +a(10) }", t.toString()); + assertEquals("{ +a(10)[source(self)] }", t.toString()); t = ASSyntax.parseTerm("{ @label(a,b,10,test,long,label) +a(10) }"); assertTrue(t instanceof Plan); @@ -252,10 +259,10 @@ t = ASSyntax.parseTerm("{ -+a(10) }"); assertTrue(t.isPlanBody()); - assertEquals("{ -+a(10) }", t.toString()); + assertEquals("{ -+a(10)[source(self)] }", t.toString()); t = ASSyntax.parseTerm("{ -a; +b }"); - assertEquals("{ -a; +b }", t.toString()); + assertEquals("{ -a[source(self)]; +b[source(self)] }", t.toString()); assertTrue(t.isPlanBody()); PlanBody pb = (PlanBody)t; assertEquals(2, pb.getPlanSize()); @@ -278,18 +285,18 @@ assertTrue(t.isPlanBody()); pb = (PlanBody)t; assertEquals(1, pb.getPlanSize()); - assertEquals("a", pb.getBodyTerm().toString()); + assertEquals("a[source(self)]", pb.getBodyTerm().toString()); assertEquals(PlanBody.BodyType.achieve, pb.getBodyType()); t = ASSyntax.parseTerm("{ +!a <- +b }"); - assertEquals("{ +!a <- +b }", t.toString()); + assertEquals("{ +!a <- +b[source(self)] }", t.toString()); assertTrue(t.isStructure()); s = (Structure)t; assertEquals(4, s.getArity()); assertEquals("plan", s.getFunctor()); t = ASSyntax.parseTerm("{ +a <- +c }"); - assertEquals("{ +a <- +c }", t.toString()); + assertEquals("{ +a <- +c[source(self)] }", t.toString()); assertTrue(t.isStructure()); s = (Structure)t; assertEquals(4, s.getArity()); Modified: trunk/src/test/PlanTest.java =================================================================== --- trunk/src/test/PlanTest.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/test/PlanTest.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -108,9 +108,9 @@ //assertEquals(p1.getBody().getArity(), bl.getArity()); Unifier u = new Unifier(); assertTrue(u.unifies(p1.getBody(), bl)); - assertEquals("a1", u.get("A1").toString()); + assertEquals("a1[source(self)]", u.get("A1").toString()); assertEquals("a2", u.get("A2").toString()); - assertEquals(".print(a); !g1", u.get("A3").toString()); + assertEquals(".print(a); !g1[source(self)]", u.get("A3").toString()); } public void testPlanTermWithVarBody() throws ParseException { Modified: trunk/src/test/StdLibTest.java =================================================================== --- trunk/src/test/StdLibTest.java 2013-12-02 18:22:10 UTC (rev 1764) +++ trunk/src/test/StdLibTest.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -104,6 +104,13 @@ VarTerm r = new VarTerm("R"); aa.execute(null, u, new Term[] { x.capply(u), annot, r }); assertEquals("a[source(jomi)]", r.capply(u).toString()); + Term t = ASSyntax.parseTerm(r.capply(u).toString()); + Term s = ASSyntax.parseTerm("bob"); + r = new VarTerm("R"); + u = new Unifier(); + aa.execute(null, u, new Term[] { t, s, r }); + assertEquals("a[source(bob)[source(jomi)]]", r.capply(u).toString()); + } public void testFindAll() throws RevisionFailedException, ParseException { Added: trunk/src/test/TestAll.java =================================================================== --- trunk/src/test/TestAll.java (rev 0) +++ trunk/src/test/TestAll.java 2013-12-10 12:14:10 UTC (rev 1765) @@ -0,0 +1,23 @@ +package test; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ + ASParserTest.class, + BeliefBaseTest.class, + ExprTermTest.class, + JadeAgTest.class, + ListTermTest.class, + MAS2JParserTest.class, + PlanTest.class, + RuleTest.class, + StdLibTest.class, + StringTermTest.class, + TermTest.class, + TSTest.class, + VarTermTest.class + }) +public class TestAll { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-12-02 18:22:13
|
Revision: 1764 http://sourceforge.net/p/jason/svn/1764 Author: jomifred Date: 2013-12-02 18:22:10 +0000 (Mon, 02 Dec 2013) Log Message: ----------- fix typos in release notes Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java trunk/release-notes.txt Modified: trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2013-11-25 10:42:24 UTC (rev 1763) +++ trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2013-12-02 18:22:10 UTC (rev 1764) @@ -31,7 +31,11 @@ "+!g({A; R}) <- A; !g(R). "+ "+!g(A) <- A." + - "+!g2(A) <- jason.asunit.print(A)." + "+!g2(A) <- jason.asunit.print(A)."+ + + "+!trl <- !myadd( { jason.asunit.print(a); jason.asunit.print(b) } ); !grl. "+ + "+!myadd(Action) <- .add_plan( {+!grl : c <- Action} ); .add_plan( {+!grl <- jason.asunit.print(ops) } )." + ); } @@ -85,4 +89,14 @@ ag.assertPrint("b200", 5); ag.assertPrint("end50", 5); } + + @Test(timeout=2000) + public void test8() { + ag.addGoal("trl"); + ag.assertPrint("ops", 5); + ag.addBel("c"); + ag.addGoal("trl"); + ag.assertPrint("a", 5); + ag.assertPrint("b", 5); + } } Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-11-25 10:42:24 UTC (rev 1763) +++ trunk/release-notes.txt 2013-12-02 18:22:10 UTC (rev 1764) @@ -125,7 +125,7 @@ --------------------------- New features -- Initial implementation of Cycled Terms +- Initial implementation of Cyclic Terms - JaCaMo infrastructure (in beta) Bugs fixed @@ -231,7 +231,7 @@ New features - creation of meta events for goal state change. States are: - - created the goal has been crated, e.g. !g in a plan + - started the goal has been started, e.g. !g in a plan - finished the goal has been achieved, e.g. a plan for !g has finished - failed e.g. the goal has failed This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-11-25 10:42:27
|
Revision: 1763 http://sourceforge.net/p/jason/svn/1763 Author: jomifred Date: 2013-11-25 10:42:24 +0000 (Mon, 25 Nov 2013) Log Message: ----------- remove isGround cache Modified Paths: -------------- trunk/src/jason/asSyntax/Structure.java Modified: trunk/src/jason/asSyntax/Structure.java =================================================================== --- trunk/src/jason/asSyntax/Structure.java 2013-11-23 15:00:39 UTC (rev 1762) +++ trunk/src/jason/asSyntax/Structure.java 2013-11-25 10:42:24 UTC (rev 1763) @@ -54,7 +54,7 @@ protected static final Term[] emptyTermArray = new Term[0]; // just to have a type for toArray in the getTermsArray method private List<Term> terms; - protected Boolean isGround = true; + //protected Boolean isGround = true; // it seems to not improve the performance public Structure(String functor) { @@ -68,7 +68,8 @@ final int tss = l.getArity(); terms = new ArrayList<Term>(tss); for (int i = 0; i < tss; i++) - addTerm(l.getTerm(i).clone()); + terms.add(l.getTerm(i).clone()); + //isGround = null; } // used by capply @@ -77,7 +78,9 @@ final int tss = l.getArity(); terms = new ArrayList<Term>(tss); for (int i = 0; i < tss; i++) - addTerm(l.getTerm(i).capply(u)); + terms.add(l.getTerm(i).capply(u)); + resetHashCodeCache(); + //isGround = null; } /** @@ -213,8 +216,8 @@ public void addTerm(Term t) { if (t == null) return; terms.add(t); - if (!t.isGround()) - isGround = false; + //if (!t.isGround()) + // isGround = false; predicateIndicatorCache = null; resetHashCodeCache(); } @@ -224,20 +227,26 @@ terms.remove(index); predicateIndicatorCache = null; resetHashCodeCache(); - isGround = null; + //isGround = null; } @Override public Literal addTerms(Term ... ts ) { for (Term t: ts) - addTerm(t); + //addTerm(t); + terms.add(t); + predicateIndicatorCache = null; + resetHashCodeCache(); return this; } @Override public Literal addTerms(List<Term> l) { for (Term t: l) - addTerm(t); + //addTerm(t); + terms.add(t); + predicateIndicatorCache = null; + resetHashCodeCache(); return this; } @@ -246,7 +255,7 @@ terms = l; predicateIndicatorCache = null; resetHashCodeCache(); - isGround = null; + //isGround = null; return this; } @@ -254,8 +263,8 @@ public void setTerm(int i, Term t) { terms.set(i,t); resetHashCodeCache(); - if (isGround() && !t.isGround()) - isGround = false; + //if (!t.isGround() && isGround()) + // isGround = false; } public Term getTerm(int i) { @@ -297,17 +306,19 @@ @Override public boolean isGround() { - if (isGround == null) { - isGround = true; + //if (isGround == null) { + // isGround = true; final int size = getArity(); for (int i=0; i<size; i++) { if (!getTerm(i).isGround()) { - isGround = false; - break; + //isGround = false; + return false; + //break; } } - } - return isGround; + //} + //return isGround; + return true; } public boolean isUnary() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-11-23 15:00:43
|
Revision: 1762 http://sourceforge.net/p/jason/svn/1762 Author: jomifred Date: 2013-11-23 15:00:39 +0000 (Sat, 23 Nov 2013) Log Message: ----------- cache isGround Modified Paths: -------------- trunk/src/jason/architecture/MindInspectorAgArch.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSyntax/ArithExpr.java trunk/src/jason/asSyntax/Structure.java trunk/src/jason/bb/DefaultBeliefBase.java trunk/src/test/TermTest.java Modified: trunk/src/jason/architecture/MindInspectorAgArch.java =================================================================== --- trunk/src/jason/architecture/MindInspectorAgArch.java 2013-11-23 14:28:34 UTC (rev 1761) +++ trunk/src/jason/architecture/MindInspectorAgArch.java 2013-11-23 15:00:39 UTC (rev 1762) @@ -22,7 +22,7 @@ package jason.architecture; -import jason.NoValueForVarException; +import jason.NoValueException; import jason.asSyntax.ASSyntax; import jason.asSyntax.NumberTerm; import jason.asSyntax.Structure; @@ -120,7 +120,7 @@ if (! hasMindInspectorByCycle) { try { updateInterval = (int)((NumberTerm)sConf.getTerm(0)).solve(); - } catch (NoValueForVarException e1) { + } catch (NoValueException e1) { e1.printStackTrace(); } new Thread("update agent mind inspector") { Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-11-23 14:28:34 UTC (rev 1761) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-11-23 15:00:39 UTC (rev 1762) @@ -24,7 +24,7 @@ package jason.asSemantics; import jason.JasonException; -import jason.NoValueForVarException; +import jason.NoValueException; import jason.RevisionFailedException; import jason.architecture.AgArch; import jason.asSyntax.ASSyntax; @@ -1216,7 +1216,7 @@ int deadline = 0; try { deadline = (int)((NumberTerm)hdl.getTerm(0)).solve(); - } catch (NoValueForVarException e1) { + } catch (NoValueException e1) { e1.printStackTrace(); } Modified: trunk/src/jason/asSyntax/ArithExpr.java =================================================================== --- trunk/src/jason/asSyntax/ArithExpr.java 2013-11-23 14:28:34 UTC (rev 1761) +++ trunk/src/jason/asSyntax/ArithExpr.java 2013-11-23 15:00:39 UTC (rev 1762) @@ -23,7 +23,7 @@ package jason.asSyntax; -import jason.NoValueForVarException; +import jason.NoValueException; import jason.asSemantics.Agent; import jason.asSemantics.Unifier; import jason.asSyntax.parser.as2j; @@ -180,7 +180,7 @@ value = new NumberTermImpl(op.eval(l, r)); } return value; - } catch (NoValueForVarException e) { + } catch (NoValueException e) { return clone(); } } Modified: trunk/src/jason/asSyntax/Structure.java =================================================================== --- trunk/src/jason/asSyntax/Structure.java 2013-11-23 14:28:34 UTC (rev 1761) +++ trunk/src/jason/asSyntax/Structure.java 2013-11-23 15:00:39 UTC (rev 1762) @@ -54,7 +54,9 @@ protected static final Term[] emptyTermArray = new Term[0]; // just to have a type for toArray in the getTermsArray method private List<Term> terms; - + protected Boolean isGround = true; + + public Structure(String functor) { //this.functor = (functor == null ? null : functor.intern()); // it does not improve performance in test i did! super(functor); @@ -66,7 +68,7 @@ final int tss = l.getArity(); terms = new ArrayList<Term>(tss); for (int i = 0; i < tss; i++) - terms.add(l.getTerm(i).clone()); + addTerm(l.getTerm(i).clone()); } // used by capply @@ -75,8 +77,7 @@ final int tss = l.getArity(); terms = new ArrayList<Term>(tss); for (int i = 0; i < tss; i++) - terms.add(l.getTerm(i).capply(u)); - resetHashCodeCache(); + addTerm(l.getTerm(i).capply(u)); } /** @@ -112,7 +113,7 @@ result = 7 * result + getTerm(i).hashCode(); return result; } - + public boolean equals(Object t) { if (t == null) return false; if (t == this) return true; @@ -212,6 +213,8 @@ public void addTerm(Term t) { if (t == null) return; terms.add(t); + if (!t.isGround()) + isGround = false; predicateIndicatorCache = null; resetHashCodeCache(); } @@ -221,23 +224,20 @@ terms.remove(index); predicateIndicatorCache = null; resetHashCodeCache(); + isGround = null; } @Override public Literal addTerms(Term ... ts ) { for (Term t: ts) - terms.add(t); - predicateIndicatorCache = null; - resetHashCodeCache(); + addTerm(t); return this; } @Override public Literal addTerms(List<Term> l) { for (Term t: l) - terms.add(t); - predicateIndicatorCache = null; - resetHashCodeCache(); + addTerm(t); return this; } @@ -246,6 +246,7 @@ terms = l; predicateIndicatorCache = null; resetHashCodeCache(); + isGround = null; return this; } @@ -253,6 +254,8 @@ public void setTerm(int i, Term t) { terms.set(i,t); resetHashCodeCache(); + if (isGround() && !t.isGround()) + isGround = false; } public Term getTerm(int i) { @@ -294,13 +297,17 @@ @Override public boolean isGround() { - final int size = getArity(); - for (int i=0; i<size; i++) { - if (!getTerm(i).isGround()) { - return false; + if (isGround == null) { + isGround = true; + final int size = getArity(); + for (int i=0; i<size; i++) { + if (!getTerm(i).isGround()) { + isGround = false; + break; + } } } - return true; + return isGround; } public boolean isUnary() { Modified: trunk/src/jason/bb/DefaultBeliefBase.java =================================================================== --- trunk/src/jason/bb/DefaultBeliefBase.java 2013-11-23 14:28:34 UTC (rev 1761) +++ trunk/src/jason/bb/DefaultBeliefBase.java 2013-11-23 15:00:39 UTC (rev 1762) @@ -144,7 +144,8 @@ entry = new BelEntry(); belsMap.put(l.getPredicateIndicator(), entry); } - entry.add(l.copy(), addInEnd); // we need to clone for the consequent event to not have a ref to this bel (which can change before the event being processed); see bug from Viviana Marcardi + l = l.copy(); // we need to clone l for the consequent event to not have a ref to this bel (which may change before the event is processed); see bug from Viviana Marcardi + entry.add(l, addInEnd); // add it in the percepts list if (l.hasAnnot(TPercept)) { @@ -162,7 +163,7 @@ if (l.hasSubsetAnnot(bl)) { // e.g. removing b[a] or b[a,d] from BB b[a,b,c] // second case fails if (l.hasAnnot(TPercept)) { - percepts.remove(bl); + boolean b = percepts.remove(bl); } boolean result = bl.delAnnots(l.getAnnots()); // note that l annots can be empty, in this case, nothing is deleted! return removeFromEntry(bl) || result; Modified: trunk/src/test/TermTest.java =================================================================== --- trunk/src/test/TermTest.java 2013-11-23 14:28:34 UTC (rev 1761) +++ trunk/src/test/TermTest.java 2013-11-23 15:00:39 UTC (rev 1762) @@ -79,7 +79,9 @@ // tests with variables t1.addTerm(new Structure("c")); + assertTrue(t3.isGround()); t3.addTerm(new VarTerm("X")); + assertFalse(t3.isGround()); assertFalse(t1.equals(t3)); Literal l3 = new LiteralImpl(true, new Pred("pos")); @@ -342,6 +344,7 @@ // p[a,b,c,d] = p[a,c|R] - ok and R=[b,d] Term t1 = parseTerm("p[c,a,b,d,c]"); Term t2 = parseTerm("p[c,a,c|R]"); + assertFalse(t2.isGround()); Unifier u = new Unifier(); assertTrue(u.unifies(t1, t2)); assertEquals("[b,d]",u.get("R").toString()); @@ -371,7 +374,9 @@ assertEquals("p[b,c,d,z]",t1.toString()); t1 = parseTerm("p[a,b,c,X]"); + assertFalse(t1.isGround()); t1 = t1.capply(u); + assertTrue(t1.isGround()); assertEquals("p[a,b,c,z]",t1.toString()); } @@ -696,6 +701,7 @@ public void testMakeVarAnnon2() { Literal l1 = Literal.parseLiteral("calc(AgY,QuadY2,QuadY2)"); + assertFalse(l1.isGround()); Literal l2 = Literal.parseLiteral("calc(32,33,V)"); Unifier u = new Unifier(); assertTrue(u.unifies(l1, l2)); @@ -715,8 +721,8 @@ l2 = (Literal)l2.capply(u); assertEquals("calc(32,33,33)", l2.toString()); l1 = (Literal)l1.capply(u); + assertTrue(l1.isGround()); assertEquals("calc(32,33,33)", l1.toString()); - } public void testMakeVarAnnon3() { @@ -728,7 +734,9 @@ assertEquals("vl("+l1.getTerm(1)+")",l1.getAnnots("vl").get(0).toString()); l1 = Literal.parseLiteral("calc(a)[a,b|T]"); + assertFalse(l1.isGround()); l1.makeVarsAnnon(); + assertFalse(l1.isGround()); assertTrue(l1.toString().contains("_")); assertFalse("calc(a)[a,b|T]".equals(l1.toString())); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-11-23 14:28:37
|
Revision: 1761 http://sourceforge.net/p/jason/svn/1761 Author: jomifred Date: 2013-11-23 14:28:34 +0000 (Sat, 23 Nov 2013) Log Message: ----------- rename class Modified Paths: -------------- trunk/src/jason/asSyntax/ArithFunctionTerm.java trunk/src/jason/asSyntax/Atom.java trunk/src/jason/asSyntax/NumberTerm.java trunk/src/jason/asSyntax/VarTerm.java Added Paths: ----------- trunk/src/jason/NoValueException.java Removed Paths: ------------- trunk/src/jason/NoValueForVarException.java Copied: trunk/src/jason/NoValueException.java (from rev 1760, trunk/src/jason/NoValueForVarException.java) =================================================================== --- trunk/src/jason/NoValueException.java (rev 0) +++ trunk/src/jason/NoValueException.java 2013-11-23 14:28:34 UTC (rev 1761) @@ -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.inf.ufrgs.br/~bordini +// http://www.das.ufsc.br/~jomi +// +//---------------------------------------------------------------------------- + + +package jason; + + +public class NoValueException extends JasonException { + + private static final long serialVersionUID = 1L; + + public NoValueException() { + } + + public NoValueException(String msg) { + super(msg); + } + + public NoValueException(String msg, Exception cause) { + super(msg); + initCause(cause); + } + +} Deleted: trunk/src/jason/NoValueForVarException.java =================================================================== --- trunk/src/jason/NoValueForVarException.java 2013-11-22 17:16:43 UTC (rev 1760) +++ trunk/src/jason/NoValueForVarException.java 2013-11-23 14:28:34 UTC (rev 1761) @@ -1,44 +0,0 @@ -//---------------------------------------------------------------------------- -// 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.inf.ufrgs.br/~bordini -// http://www.das.ufsc.br/~jomi -// -//---------------------------------------------------------------------------- - - -package jason; - - -public class NoValueForVarException extends JasonException { - - private static final long serialVersionUID = 1L; - - public NoValueForVarException() { - } - - public NoValueForVarException(String msg) { - super(msg); - } - - public NoValueForVarException(String msg, Exception cause) { - super(msg); - initCause(cause); - } - -} Modified: trunk/src/jason/asSyntax/ArithFunctionTerm.java =================================================================== --- trunk/src/jason/asSyntax/ArithFunctionTerm.java 2013-11-22 17:16:43 UTC (rev 1760) +++ trunk/src/jason/asSyntax/ArithFunctionTerm.java 2013-11-23 14:28:34 UTC (rev 1761) @@ -1,6 +1,6 @@ package jason.asSyntax; -import jason.NoValueForVarException; +import jason.NoValueException; import jason.asSemantics.Agent; import jason.asSemantics.ArithFunction; import jason.asSemantics.Unifier; @@ -91,7 +91,7 @@ try { value = new NumberTermImpl(function.evaluate((agent == null ? null : agent.getTS()), ((Literal)v).getTermsArray())); return value; - } catch (NoValueForVarException e) { + } catch (NoValueException e) { // ignore and return this; } catch (Exception e) { logger.log(Level.SEVERE, getErrorMsg()+ " -- error in evaluate!", e); @@ -103,12 +103,11 @@ return clone(); } - @Override - public double solve() throws NoValueForVarException { + public double solve() throws NoValueException { if (value == null) // try to solve without unifier capply(null); if (value == null) - throw new NoValueForVarException(); + throw new NoValueException(); else return value.solve(); } Modified: trunk/src/jason/asSyntax/Atom.java =================================================================== --- trunk/src/jason/asSyntax/Atom.java 2013-11-22 17:16:43 UTC (rev 1760) +++ trunk/src/jason/asSyntax/Atom.java 2013-11-23 14:28:34 UTC (rev 1761) @@ -41,7 +41,7 @@ public Atom(String functor) { if (functor == null) - logger.log(Level.WARNING, "A structure functor should not be null!", new Exception()); + logger.log(Level.WARNING, "An atom functor should not be null!", new Exception()); this.functor = functor; } Modified: trunk/src/jason/asSyntax/NumberTerm.java =================================================================== --- trunk/src/jason/asSyntax/NumberTerm.java 2013-11-22 17:16:43 UTC (rev 1760) +++ trunk/src/jason/asSyntax/NumberTerm.java 2013-11-23 14:28:34 UTC (rev 1761) @@ -1,6 +1,6 @@ package jason.asSyntax; -import jason.NoValueForVarException; +import jason.NoValueException; /** The interface for numeric terms of AgentSpeak language @@ -10,5 +10,5 @@ public interface NumberTerm extends Term { /** returns the numeric value of the term */ - public double solve() throws NoValueForVarException; + public double solve() throws NoValueException; } Modified: trunk/src/jason/asSyntax/VarTerm.java =================================================================== --- trunk/src/jason/asSyntax/VarTerm.java 2013-11-22 17:16:43 UTC (rev 1760) +++ trunk/src/jason/asSyntax/VarTerm.java 2013-11-23 14:28:34 UTC (rev 1761) @@ -23,7 +23,7 @@ package jason.asSyntax; -import jason.NoValueForVarException; +import jason.NoValueException; import jason.asSemantics.Agent; import jason.asSemantics.Unifier; import jason.asSyntax.parser.as2j; @@ -757,9 +757,8 @@ // Interface NumberTerm // ---------- - @Override - public double solve() throws NoValueForVarException { - throw new NoValueForVarException(); + public double solve() throws NoValueException { + throw new NoValueException(); /* if (value != null && value.isNumeric()) return ((NumberTerm) value).solve(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-11-22 17:16:46
|
Revision: 1760 http://sourceforge.net/p/jason/svn/1760 Author: jomifred Date: 2013-11-22 17:16:43 +0000 (Fri, 22 Nov 2013) Log Message: ----------- fix bug reported by Viviana Marcardi Modified Paths: -------------- trunk/build.xml trunk/release-notes.txt trunk/src/jason/asSemantics/Agent.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/bb/DefaultBeliefBase.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2013-11-14 10:44:23 UTC (rev 1759) +++ trunk/build.xml 2013-11-22 17:16:43 UTC (rev 1760) @@ -12,7 +12,7 @@ <property name="dist.properties" value="${basedir}/bin/dist.properties" /> <property name="version" value="1" /> - <property name="release" value="3.10b" /> + <property name="release" value="4.0" /> <property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" /> <property name="distFile" value="${env.HOME}/Jason-${version}.${release}" /> Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-11-14 10:44:23 UTC (rev 1759) +++ trunk/release-notes.txt 2013-11-22 17:16:43 UTC (rev 1760) @@ -1,7 +1,7 @@ --------------------------- version 1.4.0 -revision XXX on SVN +revision 1759 on SVN --------------------------- New features Modified: trunk/src/jason/asSemantics/Agent.java =================================================================== --- trunk/src/jason/asSemantics/Agent.java 2013-11-14 10:44:23 UTC (rev 1759) +++ trunk/src/jason/asSemantics/Agent.java 2013-11-22 17:16:43 UTC (rev 1760) @@ -664,7 +664,7 @@ // stat int adds = 0; int dels = 0; - long startTime = System.nanoTime(); + long startTime = qProfiling == null ? 0 : System.nanoTime(); // deleting percepts in the BB that is not perceived anymore Iterator<Literal> perceptsInBB = getBB().getPercepts(); @@ -821,7 +821,7 @@ List<Literal>[] result = null; try { if (beliefToAdd != null) { - if (logger.isLoggable(Level.FINE)) logger.fine("Adding belief " + beliefToAdd); + if (logger.isLoggable(Level.FINE)) logger.fine("Doing (add) brf for " + beliefToAdd); if (getBB().add(position, beliefToAdd)) { result = new List[2]; @@ -838,7 +838,7 @@ u = new Unifier(); } - if (logger.isLoggable(Level.FINE)) logger.fine("Doing brf for " + beliefToDel + " in BB=" + believes(beliefToDel, u)); + if (logger.isLoggable(Level.FINE)) logger.fine("Doing (del) brf for " + beliefToDel + " in BB=" + believes(beliefToDel, u)); boolean removed = getBB().remove(beliefToDel); if (!removed && !beliefToDel.isGround()) { // then try to unify the parameter with a belief in BB Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-11-14 10:44:23 UTC (rev 1759) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-11-22 17:16:43 UTC (rev 1760) @@ -1045,7 +1045,7 @@ // b) create the failure event (it is done by SelRelPlan) if (e.isInternal() || C.hasListener() || ag.getPL().hasCandidatePlan(e.trigger)) { C.addEvent(e); - if (logger.isLoggable(Level.FINE)) logger.fine("Added event " + e); + if (logger.isLoggable(Level.FINE)) logger.fine("Added event " + e+ ", events = "+C.getEvents()); } } Modified: trunk/src/jason/bb/DefaultBeliefBase.java =================================================================== --- trunk/src/jason/bb/DefaultBeliefBase.java 2013-11-14 10:44:23 UTC (rev 1759) +++ trunk/src/jason/bb/DefaultBeliefBase.java 2013-11-22 17:16:43 UTC (rev 1760) @@ -144,7 +144,7 @@ entry = new BelEntry(); belsMap.put(l.getPredicateIndicator(), entry); } - entry.add(l, addInEnd); + entry.add(l.copy(), addInEnd); // we need to clone for the consequent event to not have a ref to this bel (which can change before the event being processed); see bug from Viviana Marcardi // add it in the percepts list if (l.hasAnnot(TPercept)) { @@ -227,8 +227,22 @@ } public boolean abolish(PredicateIndicator pi) { - // TODO: remove also in percepts list! - return belsMap.remove(pi) != null; + BelEntry entry = belsMap.remove(pi); + if (entry != null) { + size -= entry.size(); + + // remove also in percepts list! + Iterator<Literal> i = percepts.iterator(); + while (i.hasNext()) { + Literal l = i.next(); + if (l.getPredicateIndicator().equals(pi)) + i.remove(); + } + return true; + } else { + return false; + } + //return belsMap.remove(pi) != null; } public Literal contains(Literal l) { @@ -318,6 +332,10 @@ } } + public int size() { + return map.size(); + } + public boolean isEmpty() { return list.isEmpty(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-11-14 10:44:26
|
Revision: 1759 http://sourceforge.net/p/jason/svn/1759 Author: jomifred Date: 2013-11-14 10:44:23 +0000 (Thu, 14 Nov 2013) Log Message: ----------- add test, update moise Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/TestAll.java trunk/lib/moise.jar trunk/release-notes.txt Added Paths: ----------- trunk/applications/as-unit-test/src/jason/tests/BugList1.java Added: trunk/applications/as-unit-test/src/jason/tests/BugList1.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/BugList1.java (rev 0) +++ trunk/applications/as-unit-test/src/jason/tests/BugList1.java 2013-11-14 10:44:23 UTC (rev 1759) @@ -0,0 +1,31 @@ +package jason.tests; + +import jason.asunit.TestAgent; + +import org.junit.Before; +import org.junit.Test; + +public class BugList1 { + + TestAgent ag, oa, ob; + + // initialisation of the agent test + @Before + public void setupAg() { + ag = new TestAgent("a"); + + // defines the agent's AgentSpeak code + ag.parseAScode( + "+!start <- L=\"[a]\"; !g(L). "+ + "+!g([]) <- jason.asunit.print(no)."+ + "+!g(_) <- jason.asunit.print(yes)." + ); + } + + @Test(timeout=2000) + public void testProg() { + ag.addGoal("start"); + ag.assertPrint("yes", 10); + } + +} Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-11-07 14:08:03 UTC (rev 1758) +++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-11-14 10:44:23 UTC (rev 1759) @@ -14,6 +14,7 @@ BugIfGoalReturn.class, BugIfLength.class, BugUnamedVars.class, + BugList1.class, TestAddLogExprInBB.class, TestGoalSource.class, TestIA.class, Modified: trunk/lib/moise.jar =================================================================== (Binary files differ) Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-11-07 14:08:03 UTC (rev 1758) +++ trunk/release-notes.txt 2013-11-14 10:44:23 UTC (rev 1759) @@ -1,10 +1,31 @@ +--------------------------- +version 1.4.0 + +revision XXX on SVN +--------------------------- + New features -- implementation of tail recursion optimisation for sub-goals. +- implementation of tail recursion optimisation (TRO) for sub-goals. It can be turned off in agent options, e.g.: agents: bob [tro=false]; +Changes in the API + +- the method apply was removed and replaced by capply that + clones and applies an unifier. Usually a code like + Term t = .... + t = t.clone(); + t.apply(u); + + can be replaced by + Term t = ..... + t = t.capply(u); + +NB. the TRO and capply have improved the performance of some application by 30%. + + --------------------------- version 1.3.10b This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-11-07 14:08:07
|
Revision: 1758 http://sourceforge.net/p/jason/svn/1758 Author: jomifred Date: 2013-11-07 14:08:03 +0000 (Thu, 07 Nov 2013) Log Message: ----------- add new type of Exception Added Paths: ----------- trunk/src/jason/NoValueForVarException.java Added: trunk/src/jason/NoValueForVarException.java =================================================================== --- trunk/src/jason/NoValueForVarException.java (rev 0) +++ trunk/src/jason/NoValueForVarException.java 2013-11-07 14:08:03 UTC (rev 1758) @@ -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.inf.ufrgs.br/~bordini +// http://www.das.ufsc.br/~jomi +// +//---------------------------------------------------------------------------- + + +package jason; + + +public class NoValueForVarException extends JasonException { + + private static final long serialVersionUID = 1L; + + public NoValueForVarException() { + } + + public NoValueForVarException(String msg) { + super(msg); + } + + public NoValueForVarException(String msg, Exception cause) { + super(msg); + initCause(cause); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-11-07 14:02:16
|
Revision: 1757 http://sourceforge.net/p/jason/svn/1757 Author: jomifred Date: 2013-11-07 14:02:11 +0000 (Thu, 07 Nov 2013) Log Message: ----------- new method capply that clones and applies Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/TestKQML.java trunk/src/jason/architecture/MindInspectorAgArch.java trunk/src/jason/asSemantics/Agent.java trunk/src/jason/asSemantics/ConcurrentInternalAction.java trunk/src/jason/asSemantics/DefaultInternalAction.java trunk/src/jason/asSemantics/IntendedMeans.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSemantics/Unifier.java trunk/src/jason/asSyntax/ArithExpr.java trunk/src/jason/asSyntax/ArithFunctionTerm.java trunk/src/jason/asSyntax/Atom.java trunk/src/jason/asSyntax/BinaryStructure.java trunk/src/jason/asSyntax/BodyLiteral.java trunk/src/jason/asSyntax/CyclicTerm.java trunk/src/jason/asSyntax/DefaultTerm.java trunk/src/jason/asSyntax/InternalActionLiteral.java trunk/src/jason/asSyntax/ListTermImpl.java trunk/src/jason/asSyntax/Literal.java trunk/src/jason/asSyntax/LiteralImpl.java trunk/src/jason/asSyntax/LogExpr.java trunk/src/jason/asSyntax/NumberTerm.java trunk/src/jason/asSyntax/NumberTermImpl.java trunk/src/jason/asSyntax/ObjectTermImpl.java trunk/src/jason/asSyntax/Plan.java trunk/src/jason/asSyntax/PlanBodyImpl.java trunk/src/jason/asSyntax/Pred.java trunk/src/jason/asSyntax/RelExpr.java trunk/src/jason/asSyntax/Rule.java trunk/src/jason/asSyntax/Structure.java trunk/src/jason/asSyntax/Term.java trunk/src/jason/asSyntax/Trigger.java trunk/src/jason/asSyntax/UnnamedVar.java trunk/src/jason/asSyntax/VarTerm.java trunk/src/jason/bb/AgentJDBCPersistentBB.java trunk/src/jason/bb/JDBCPersistentBB.java trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc trunk/src/jason/mas2j/parser/mas2j.java trunk/src/jason/stdlib/add_plan.java trunk/src/jason/stdlib/desire.java trunk/src/jason/stdlib/drop_desire.java trunk/src/jason/stdlib/findall.java trunk/src/jason/stdlib/puts.java trunk/src/jason/stdlib/setof.java trunk/src/jason/stdlib/succeed_goal.java trunk/src/test/ASParserTest.java trunk/src/test/BeliefBaseTest.java trunk/src/test/ExprTermTest.java trunk/src/test/ListTermTest.java trunk/src/test/PlanTest.java trunk/src/test/RuleTest.java trunk/src/test/StdLibTest.java trunk/src/test/TermTest.java trunk/src/test/VarTermTest.java Modified: trunk/applications/as-unit-test/src/jason/tests/TestKQML.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestKQML.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/applications/as-unit-test/src/jason/tests/TestKQML.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -107,7 +107,7 @@ public void testTellHow() { bob.addGoal("send_tellHow"); bob.assertIdle(10); - maria.assertPrint("Hello bob", 10); + maria.assertPrint("Hello bob", 20); bob.addGoal("send_untellHow"); bob.assertIdle(10); Modified: trunk/src/jason/architecture/MindInspectorAgArch.java =================================================================== --- trunk/src/jason/architecture/MindInspectorAgArch.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/architecture/MindInspectorAgArch.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -22,6 +22,7 @@ package jason.architecture; +import jason.NoValueForVarException; import jason.asSyntax.ASSyntax; import jason.asSyntax.NumberTerm; import jason.asSyntax.Structure; @@ -117,7 +118,11 @@ hasMindInspectorByCycle = sConf.getTerm(0).toString().equals("cycle"); if (! hasMindInspectorByCycle) { - updateInterval = (int)((NumberTerm)sConf.getTerm(0)).solve(); + try { + updateInterval = (int)((NumberTerm)sConf.getTerm(0)).solve(); + } catch (NoValueForVarException e1) { + e1.printStackTrace(); + } new Thread("update agent mind inspector") { public void run() { try { Modified: trunk/src/jason/asSemantics/Agent.java =================================================================== --- trunk/src/jason/asSemantics/Agent.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSemantics/Agent.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -488,8 +488,8 @@ if (!b.isRule() && !b.isGround()) b = new Rule(b,Literal.LTrue); - b.apply(new Unifier()); // to solve arithmetic expressions - + b = (Literal)b.capply(null); // to solve arithmetic expressions + // does not do BRF for rules (and so do not produce events +bel for rules) if (b.isRule()) getBB().add(b); @@ -843,7 +843,7 @@ boolean removed = getBB().remove(beliefToDel); if (!removed && !beliefToDel.isGround()) { // then try to unify the parameter with a belief in BB if (believes(beliefToDel, u)) { - beliefToDel.apply(u); + beliefToDel = (Literal)beliefToDel.capply(u); removed = getBB().remove(beliefToDel); } } Modified: trunk/src/jason/asSemantics/ConcurrentInternalAction.java =================================================================== --- trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSemantics/ConcurrentInternalAction.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -68,8 +68,7 @@ public Term[] prepareArguments(Literal body, Unifier un) { Term[] terms = new Term[body.getArity()]; for (int i=0; i<terms.length; i++) { - terms[i] = body.getTerm(i).clone(); - terms[i].apply(un); + terms[i] = body.getTerm(i).capply(un); } return terms; } Modified: trunk/src/jason/asSemantics/DefaultInternalAction.java =================================================================== --- trunk/src/jason/asSemantics/DefaultInternalAction.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSemantics/DefaultInternalAction.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -32,8 +32,7 @@ public Term[] prepareArguments(Literal body, Unifier un) { Term[] terms = new Term[body.getArity()]; for (int i=0; i<terms.length; i++) { - terms[i] = body.getTerm(i).clone(); - terms[i].apply(un); + terms[i] = body.getTerm(i).capply(un); } return terms; } Modified: trunk/src/jason/asSemantics/IntendedMeans.java =================================================================== --- trunk/src/jason/asSemantics/IntendedMeans.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSemantics/IntendedMeans.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -53,11 +53,10 @@ unif = opt.getUnifier(); if (te == null) { - trigger = plan.getTrigger().clone(); + trigger = plan.getTrigger().capply(unif); } else { - trigger = te; + trigger = te.capply(unif); } - trigger.apply(unif); } // used by clone Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -24,6 +24,7 @@ package jason.asSemantics; import jason.JasonException; +import jason.NoValueForVarException; import jason.RevisionFailedException; import jason.architecture.AgArch; import jason.asSyntax.ASSyntax; @@ -279,8 +280,7 @@ // test the case of sync ask with many receivers Unifier un = intention.peek().getUnif(); - Term rec = send.getTerm(0).clone(); - rec.apply(un); + Term rec = send.getTerm(0).capply(un); if (rec.isList()) { // send to many receivers // put the answers in the unifier VarTerm answers = new VarTerm("AnsList___"+m.getInReplyTo()); @@ -497,33 +497,37 @@ // begin tail recursion optimisation (TRO) if (setts.isTROon()) { IntendedMeans top = confP.C.SE.intention.peek(); // top = the IM that will be removed from the intention due to TRO - if (top.getTrigger().isGoal() && im.getTrigger().isGoal() && // are both goal - top.getTrigger().getPredicateIndicator().equals( im.getTrigger().getPredicateIndicator()) && // are they equals - top.getCurrentStep().getBodyNext() == null) { // the plan below is finished + if (top != null && top.getTrigger().isGoal() && im.getTrigger().isGoal() && // are both goal + top.getCurrentStep().getBodyNext() == null && // the plan below is finished + top.getTrigger().getPredicateIndicator().equals( im.getTrigger().getPredicateIndicator()) // goals are equals + ) { confP.C.SE.intention.pop(); // remove the top IM IntendedMeans imBase = confP.C.SE.intention.peek(); // base = where the new IM will be place on top of - // move top relevant values into the base (relevant = renamed vars in base) - for (VarTerm v: imBase.renamedVars) { - VarTerm vvl = (VarTerm)imBase.renamedVars.function.get(v); - Term t = top.unif.get(vvl); - if (t != null) { // if v has got a value in top unif, put the value in the unifier - if (t instanceof Literal) { - Literal l= (Literal)t.clone(); - l.apply(top.unif); - l.makeVarsAnnon(top.renamedVars); - im.unif.function.put(vvl, l); + if (imBase != null) { + // move top relevant values into the base (relevant = renamed vars in base) + for (VarTerm v: imBase.renamedVars) { + VarTerm vvl = (VarTerm)imBase.renamedVars.function.get(v); + Term t = top.unif.get(vvl); + if (t != null) { // if v has got a value in top unif, put the value in the unifier + if (t instanceof Literal) { + //Literal l= (Literal)t.clone(); + //l.apply(top.unif); + Literal l= (Literal)t.capply(top.unif); + l.makeVarsAnnon(top.renamedVars); + im.unif.function.put(vvl, l); + } else { + im.unif.function.put(vvl, t); + } } else { - im.unif.function.put(vvl, t); + // the vvl was renamed again in top, just replace in base the new value + VarTerm v0 = (VarTerm)top.renamedVars.function.get(vvl); + if (v0 != null) { + imBase.renamedVars.function.put(v, v0); + } } - } else { - // the vvl was renamed again in top, just replace in base the new value - VarTerm v0 = (VarTerm)top.renamedVars.function.get(vvl); - if (v0 != null) { - imBase.renamedVars.function.put(v, v0); - } - } - } + } + } } // end of TRO } @@ -616,8 +620,7 @@ Term bTerm = h.getBodyTerm(); if (bTerm instanceof VarTerm) { // de-var bTerm - bTerm = bTerm.clone(); // clone before apply - bTerm.apply(u); + bTerm = bTerm.capply(u); if (bTerm.isVar()) { // 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_without_value", msg))) @@ -650,7 +653,7 @@ // Rule Action case action: - body = body.copy(); body.apply(u); + body = (Literal)body.capply(u); confP.C.A = new ActionExec(body, conf.C.SI); break; @@ -839,8 +842,7 @@ // add the self source in the body in case no other source was given private Literal prepareBodyForEvent(Literal body, Unifier u, IntendedMeans imRenamedVars) { - body = body.copy(); - body.apply(u); + body = (Literal)body.capply(u); Unifier renamedVars = new Unifier(); //System.out.println("antes "+body+" "+u+" "); body.makeVarsAnnon(renamedVars); // free variables in an event cannot conflict with those in the plan @@ -955,8 +957,7 @@ //System.out.println(ov+"="+vt+"="+vl); if (vl != null) { // vt has value in top //System.out.println(" and found "+vl); - vl = vl.clone(); - vl.apply(topIM.unif); + vl = vl.capply(topIM.unif); if (vl.isLiteral()) ((Literal)vl).makeVarsAnnon(); im.unif.bind(vt, vl); @@ -1069,8 +1070,7 @@ } else { failEvent = new Event(im.getTrigger().clone(), i); } - Term bodyPart = im.getCurrentStep().getBodyTerm().clone(); - bodyPart.apply(im.unif); + Term bodyPart = im.getCurrentStep().getBodyTerm().capply(im.unif); setDefaultFailureAnnots(failEvent, bodyPart, failAnnots); if (im.isGoalAdd()) { @@ -1213,7 +1213,12 @@ isize = 0; else isize = intention.size(); - int deadline = (int)((NumberTerm)hdl.getTerm(0)).solve(); + int deadline = 0; + try { + deadline = (int)((NumberTerm)hdl.getTerm(0)).solve(); + } catch (NoValueForVarException e1) { + e1.printStackTrace(); + } getAg().getScheduler().schedule(new Runnable() { public void run() { Modified: trunk/src/jason/asSemantics/Unifier.java =================================================================== --- trunk/src/jason/asSemantics/Unifier.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSemantics/Unifier.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -51,20 +51,6 @@ protected Map<VarTerm, Term> function = new HashMap<VarTerm, Term>(); - /** - * @deprecated use t.apply(un) instead. - */ - public void apply(Term t) { - t.apply(this); - } - - /** - * @deprecated use p.apply(un) instead. - */ - public void apply(Pred p) { - p.apply(this); - } - /** * gets the value for a Var, if it is unified with another var, gets this * other's value @@ -235,14 +221,10 @@ protected boolean unifyTerms(Term t1g, Term t2g) { // if args are expressions, apply them and use their values - if (t1g.isArithExpr()) { - t1g = t1g.clone(); - t1g.apply(this); - } - if (t2g.isArithExpr()) { - t2g = t2g.clone(); - t2g.apply(this); - } + if (t1g.isArithExpr()) + t1g = t1g.capply(this); + if (t2g.isArithExpr()) + t2g = t2g.capply(this); final boolean t1gisvar = t1g.isVar(); final boolean t2gisvar = t2g.isVar(); Modified: trunk/src/jason/asSyntax/ArithExpr.java =================================================================== --- trunk/src/jason/asSyntax/ArithExpr.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/ArithExpr.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -23,7 +23,9 @@ package jason.asSyntax; +import jason.NoValueForVarException; import jason.asSemantics.Agent; +import jason.asSemantics.Unifier; import jason.asSyntax.parser.as2j; import java.io.StringReader; @@ -38,7 +40,7 @@ @navassoc - op - ArithmeticOp */ -public class ArithExpr extends ArithFunctionTerm { +public class ArithExpr extends ArithFunctionTerm implements NumberTerm { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(ArithExpr.class.getName()); @@ -162,34 +164,34 @@ return null; } } - + @Override - public double solve() { - double l = ((NumberTerm)getTerm(0)).solve(); - if (isUnary()) { - if (op == ArithmeticOp.minus) { - return -l; + public Term capply(Unifier u) { + try { + double l = ((NumberTerm)getTerm(0).capply(u)).solve(); + if (isUnary()) { + if (op == ArithmeticOp.minus) { + value = new NumberTermImpl(-l); + } else { + value = new NumberTermImpl(l); + } } else { - return l; + double r = ((NumberTerm)getTerm(1).capply(u)).solve(); + value = new NumberTermImpl(op.eval(l, r)); } - } else { - double r = ((NumberTerm)getTerm(1)).solve(); - return op.eval(l, r); + return value; + } catch (NoValueForVarException e) { + return clone(); } } - - @Override + public boolean checkArity(int a) { return a == 1 || a == 2; } /** make a hard copy of the terms */ public NumberTerm clone() { - if (isEvaluated()) { - return getValue(); - } else { - return new ArithExpr(this); - } + return new ArithExpr(this); } /** gets the Operation of this Expression */ @@ -209,38 +211,30 @@ @Override public String toString() { - if (isEvaluated()) { - return getValue().toString(); + if (isUnary()) { + return "(" + op + getTerm(0) + ")"; } else { - if (isUnary()) { - return "(" + op + getTerm(0) + ")"; - } else { - return "(" + getTerm(0) + op + getTerm(1) + ")"; - } + return "(" + getTerm(0) + op + getTerm(1) + ")"; } } /** get as XML */ public Element getAsDOM(Document document) { - if (isEvaluated()) { - return getValue().getAsDOM(document); + Element u = (Element) document.createElement("expression"); + u.setAttribute("type", "arithmetic"); + u.setAttribute("operator", op.toString()); + if (isUnary()) { + Element r = (Element) document.createElement("right"); + r.appendChild(getTerm(0).getAsDOM(document)); // put the left argument indeed! + u.appendChild(r); } else { - Element u = (Element) document.createElement("expression"); - u.setAttribute("type", "arithmetic"); - u.setAttribute("operator", op.toString()); - if (isUnary()) { - Element r = (Element) document.createElement("right"); - r.appendChild(getTerm(0).getAsDOM(document)); // put the left argument indeed! - u.appendChild(r); - } else { - Element l = (Element) document.createElement("left"); - l.appendChild(getTerm(0).getAsDOM(document)); - u.appendChild(l); - Element r = (Element) document.createElement("right"); - r.appendChild(getTerm(1).getAsDOM(document)); - u.appendChild(r); - } - return u; + Element l = (Element) document.createElement("left"); + l.appendChild(getTerm(0).getAsDOM(document)); + u.appendChild(l); + Element r = (Element) document.createElement("right"); + r.appendChild(getTerm(1).getAsDOM(document)); + u.appendChild(r); } + return u; } } Modified: trunk/src/jason/asSyntax/ArithFunctionTerm.java =================================================================== --- trunk/src/jason/asSyntax/ArithFunctionTerm.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/ArithFunctionTerm.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -1,5 +1,6 @@ package jason.asSyntax; +import jason.NoValueForVarException; import jason.asSemantics.Agent; import jason.asSemantics.ArithFunction; import jason.asSemantics.Unifier; @@ -26,16 +27,12 @@ private static Logger logger = Logger.getLogger(ArithFunctionTerm.class.getName()); - private NumberTerm value = null; // value, when evaluated + protected NumberTerm value = null; // value, when evaluated private ArithFunction function = null; private Agent agent = null; // the agent where this function was used - - public ArithFunctionTerm(String functor, int termsSize) { - super(functor, termsSize); - } - + public ArithFunctionTerm(ArithFunction function) { super(function.getName(), 2); this.function = function; @@ -43,15 +40,14 @@ public ArithFunctionTerm(ArithFunctionTerm af) { super(af); // clone args from af - value = af.value; function = af.function; agent = af.agent; } - public NumberTerm getValue() { - return value; + public ArithFunctionTerm(String functor, int arity) { + super(functor,arity); } - + @Override public boolean isNumeric() { return true; @@ -68,62 +64,15 @@ } @Override - public Literal makeVarsAnnon(Unifier un) { - if (isEvaluated()) { - return null; - } else { - return super.makeVarsAnnon(un); - } - } - - @Override public boolean isLiteral() { return false; } @Override public boolean isArithExpr() { - return !isEvaluated(); + return true; } - - /** returns true if the function/expression was already evaluated */ - public boolean isEvaluated() { - return value != null; - } - @Override - public boolean isGround() { - return isEvaluated() || super.isGround(); - } - - public boolean isUnary() { - return getArity() == 1; - } - - /** - * Does a "normal" apply and then solve the expression and store the result, - * so future calls of solve do not need to compute the value again - */ - @Override - public boolean apply(Unifier u) { - if (isEvaluated()) - return false; - - super.apply(u); - if ((function != null && function.allowUngroundTerms()) || isGround()) { - try { - value = new NumberTermImpl(solve()); - return true; - } catch (Exception e) { - logger.log(Level.SEVERE, getErrorMsg()+ " -- "+ e); - } - //} else { - // logger.warning(getErrorMsg()+ " -- this function has unground arguments and can not be evaluated! Unifier is "+u); - } - - return false; - } - public void setAgent(Agent ag) { agent = ag; } @@ -132,20 +81,38 @@ } /** computes the value for this arithmetic function (as defined in the NumberTerm interface) */ - public double solve() { - if (isEvaluated()) - return value.solve(); - else if (function != null) - try { - return function.evaluate((agent == null ? null : agent.getTS()),getTermsArray()); - } catch (Exception e) { - logger.log(Level.SEVERE, getErrorMsg()+ " -- error in evaluate!", e); + @Override + public Term capply(Unifier u) { + if (function == null) { + logger.log(Level.SEVERE, getErrorMsg()+ " -- the function can not be evalutated, it has no function assigned to it!", new Exception()); + } else { + Term v = super.capply(u); + if (function.allowUngroundTerms() || v.isGround()) { + try { + value = new NumberTermImpl(function.evaluate((agent == null ? null : agent.getTS()), ((Literal)v).getTermsArray())); + return value; + } catch (NoValueForVarException e) { + // ignore and return this; + } catch (Exception e) { + logger.log(Level.SEVERE, getErrorMsg()+ " -- error in evaluate!", e); + } + //} else { + // logger.warning(getErrorMsg()+ " -- this function has unground arguments and can not be evaluated! Unifier is "+u); } - else - logger.log(Level.SEVERE, getErrorMsg()+ " -- the function can not be evalutated, it has no function assigned to it!", new Exception()); - return 0; + } + return clone(); } + @Override + public double solve() throws NoValueForVarException { + if (value == null) // try to solve without unifier + capply(null); + if (value == null) + throw new NoValueForVarException(); + else + return value.solve(); + } + public boolean checkArity(int a) { return function != null && function.checkArity(a); } @@ -159,46 +126,24 @@ @Override public boolean equals(Object t) { if (t == null) return false; - if (isEvaluated()) return value.equals(t); return super.equals(t); } @Override public int compareTo(Term o) { - /*if (o instanceof NumberTerm) { - NumberTerm st = (NumberTerm)o; - if (solve() > st.solve()) return 1; - if (solve() < st.solve()) return -1; - } - return 0; */ if (o instanceof VarTerm) { return o.compareTo(this) * -1; } - if (o instanceof NumberTerm) { + return super.compareTo(o); + /*if (o instanceof NumberTerm) { NumberTerm st = (NumberTerm)o; if (solve() > st.solve()) return 1; if (solve() < st.solve()) return -1; return 0; } - return -1; + return -1;*/ } - @Override - protected int calcHashCode() { - if (isEvaluated()) - return value.hashCode(); - else - return super.calcHashCode(); - } - - @Override - public String toString() { - if (isEvaluated()) - return value.toString(); - else - return super.toString(); - } - @Override public String getErrorMsg() { return "Error in '"+this+"' ("+ super.getErrorMsg() + ")"; @@ -206,22 +151,15 @@ @Override public NumberTerm clone() { - if (isEvaluated()) - return value; - else - return new ArithFunctionTerm(this); + return new ArithFunctionTerm(this); } public Element getAsDOM(Document document) { - if (isEvaluated()) { - return value.getAsDOM(document); - } else { - Element u = (Element) document.createElement("expression"); - u.setAttribute("type", "arithmetic"); - Element r = (Element) document.createElement("right"); - r.appendChild(super.getAsDOM(document)); // put the left argument indeed! - u.appendChild(r); - return u; - } + Element u = (Element) document.createElement("expression"); + u.setAttribute("type", "arithmetic"); + Element r = (Element) document.createElement("right"); + r.appendChild(super.getAsDOM(document)); // put the left argument indeed! + u.appendChild(r); + return u; } } Modified: trunk/src/jason/asSyntax/Atom.java =================================================================== --- trunk/src/jason/asSyntax/Atom.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Atom.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -59,7 +59,7 @@ public Term clone() { return this; // since this object is immutable } - + @Override public boolean isAtom() { return true; Modified: trunk/src/jason/asSyntax/BinaryStructure.java =================================================================== --- trunk/src/jason/asSyntax/BinaryStructure.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/BinaryStructure.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -56,10 +56,6 @@ srcInfo = arg.getSrcInfo(); } - public boolean isUnary() { - return getArity() == 1; - } - /** gets the LHS of this operation */ public Term getLHS() { return getTerm(0); Modified: trunk/src/jason/asSyntax/BodyLiteral.java =================================================================== --- trunk/src/jason/asSyntax/BodyLiteral.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/BodyLiteral.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -37,6 +37,7 @@ case delAddBel: return PlanBody.BodyType.delAddBel; case achieveNF: return PlanBody.BodyType.achieveNF; case constraint: return PlanBody.BodyType.constraint; + default: break; } return PlanBody.BodyType.none; } Modified: trunk/src/jason/asSyntax/CyclicTerm.java =================================================================== --- trunk/src/jason/asSyntax/CyclicTerm.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/CyclicTerm.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -45,6 +45,11 @@ cyclicVar = v; } + public CyclicTerm(Literal t, VarTerm v, Unifier u) { + super(t,u); + cyclicVar = v; + } + public VarTerm getCyclicVar() { return cyclicVar; } @@ -75,6 +80,8 @@ return this; } + + /* @Override public boolean apply(Unifier u) { Term v = u.remove(cyclicVar); @@ -83,9 +90,19 @@ u.bind(cyclicVar, v); return b; } + */ + @Override + public Term capply(Unifier u) { + Term v = u.remove(cyclicVar); + Term r = new CyclicTerm(this, (VarTerm)cyclicVar.clone(), u); + if (v != null) + u.bind(cyclicVar, v); + return r; + } + public Term clone() { - return new CyclicTerm(this, (VarTerm)cyclicVar.copy()); + return new CyclicTerm(this, (VarTerm)cyclicVar.clone()); } @Override Modified: trunk/src/jason/asSyntax/DefaultTerm.java =================================================================== --- trunk/src/jason/asSyntax/DefaultTerm.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/DefaultTerm.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -110,9 +110,8 @@ return true; } - - public boolean apply(Unifier u) { - return false; + public Term capply(Unifier u) { + return clone(); } public SourceInfo getSrcInfo() { Modified: trunk/src/jason/asSyntax/InternalActionLiteral.java =================================================================== --- trunk/src/jason/asSyntax/InternalActionLiteral.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/InternalActionLiteral.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -24,9 +24,7 @@ package jason.asSyntax; import jason.asSemantics.Agent; -import jason.asSemantics.QueryCacheKey; import jason.asSemantics.InternalAction; -import jason.asSemantics.QueryCacheAdv; import jason.asSemantics.Unifier; import java.util.ConcurrentModificationException; @@ -61,6 +59,12 @@ this.ia = l.ia; } + // used by capply + private InternalActionLiteral(InternalActionLiteral l, Unifier u) { + super((Structure) l, u); + this.ia = l.ia; + } + // used by the parser public InternalActionLiteral(Structure p, Agent ag) throws Exception { super(p); @@ -146,6 +150,11 @@ return "Error in internal action '"+this+"'"+ src; } + @Override + public Term capply(Unifier u) { + return new InternalActionLiteral(this, u); + } + public InternalActionLiteral clone() { return new InternalActionLiteral(this); } Modified: trunk/src/jason/asSyntax/ListTermImpl.java =================================================================== --- trunk/src/jason/asSyntax/ListTermImpl.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/ListTermImpl.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -96,7 +96,16 @@ public ListTerm cloneLT() { return clone(); } - + + /** make a hard copy of the terms */ + @Override + public ListTerm capply(Unifier u) { + ListTermImpl t = new ListTermImpl(); + if (term != null) t.term = this.term.capply(u); + if (next != null) t.next = this.next.capply(u); + return t; + } + /** make a shallow copy of the list (terms are not cloned, only the structure) */ public ListTerm cloneLTShallow() { ListTermImpl t = new ListTermImpl(); @@ -242,6 +251,7 @@ return false; } + /* @Override public boolean apply(Unifier u) { if (isEmpty()) { @@ -253,6 +263,7 @@ } return false; } + */ @Override public Iterator<Unifier> logicalConsequence(Agent ag, Unifier un) { @@ -625,7 +636,7 @@ s.append(l.getTerm()); if (l.isTail()) { s.append('|'); - s.append(l.getNext()); + s.append(l.getTail()); break; } l = l.getNext(); Modified: trunk/src/jason/asSyntax/Literal.java =================================================================== --- trunk/src/jason/asSyntax/Literal.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Literal.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -332,8 +332,7 @@ // try cache iterator if (cacheIt != null) { while (cacheIt.hasNext()) { - Literal ltmp = Literal.this.copy(); - ltmp.apply( cacheIt.next() ); + Literal ltmp = (Literal)Literal.this.capply( cacheIt.next() ); Unifier u = un.clone(); //System.out.println(" try "+ltmp); if (u.unifiesNoUndo(Literal.this, ltmp)) { @@ -365,8 +364,9 @@ while (ruleIt.hasNext()) { // unifies the rule head with the result of rule evaluation Unifier ruleUn = ruleIt.next(); // evaluation result - Literal rhead = rule.headClone(); - rhead.apply(ruleUn); + //Literal rhead = rule.headClone(); + //rhead = (Literal)rhead.capply(ruleUn); + Literal rhead = rule.headCApply(ruleUn); useDerefVars(rhead, ruleUn); // replace vars by the bottom in the var clusters (e.g. X=_2; Y=_2, a(X,Y) ===> A(_2,_2)) rhead.makeVarsAnnon(); // to remove vars in head with original names @@ -399,8 +399,7 @@ // it is used to define what will be the unifier used // inside the rule. if (cloneAnnon == null) { - cloneAnnon = Literal.this.copy(); - cloneAnnon.apply(un); + cloneAnnon = (Literal)Literal.this.capply(un); cloneAnnon.makeVarsAnnon(); } @@ -418,8 +417,7 @@ get(); return; }*/ - kForChache = Literal.this.copy(); - kForChache.apply(un); + kForChache = (Literal)Literal.this.capply(un); //System.out.println("try "+kForChache); cacheIt = qCache.getCache(kForChache); if (cacheIt != null) { Modified: trunk/src/jason/asSyntax/LiteralImpl.java =================================================================== --- trunk/src/jason/asSyntax/LiteralImpl.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/LiteralImpl.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -23,6 +23,8 @@ package jason.asSyntax; +import jason.asSemantics.Unifier; + import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -53,6 +55,13 @@ type = !l.negated(); } + // used by capply + protected LiteralImpl(Literal l, Unifier u) { + super(l,u); + type = !l.negated(); + } + + /** if pos == true, the literal is positive, otherwise it is negative */ public LiteralImpl(boolean pos, Literal l) { super(l); @@ -119,11 +128,17 @@ return super.compareTo(t); } + @Override public Term clone() { return new LiteralImpl(this); } @Override + public Term capply(Unifier u) { + return new LiteralImpl(this,u); + } + + @Override protected int calcHashCode() { int result = super.calcHashCode(); if (negated()) result += 3271; Modified: trunk/src/jason/asSyntax/LogExpr.java =================================================================== --- trunk/src/jason/asSyntax/LogExpr.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/LogExpr.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -104,6 +104,8 @@ switch (op) { + case none: break; + case not: if (!getLHS().logicalConsequence(ag,un).hasNext()) { return createUnifIterator(un); @@ -238,6 +240,15 @@ return null; } + @Override + public Term capply(Unifier u) { + // do not call constructor with term parameter! + if (isUnary()) + return new LogExpr(op, (LogicalFormula)getTerm(0).capply(u)); + else + return new LogExpr((LogicalFormula)getTerm(0).capply(u), op, (LogicalFormula)getTerm(1).capply(u)); + } + /** make a hard copy of the terms */ public LogicalFormula clone() { // do not call constructor with term parameter! Modified: trunk/src/jason/asSyntax/NumberTerm.java =================================================================== --- trunk/src/jason/asSyntax/NumberTerm.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/NumberTerm.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -1,6 +1,8 @@ package jason.asSyntax; +import jason.NoValueForVarException; + /** The interface for numeric terms of AgentSpeak language * * @opt nodefillcolor lightgoldenrodyellow @@ -8,5 +10,5 @@ public interface NumberTerm extends Term { /** returns the numeric value of the term */ - public double solve(); + public double solve() throws NoValueForVarException; } Modified: trunk/src/jason/asSyntax/NumberTermImpl.java =================================================================== --- trunk/src/jason/asSyntax/NumberTermImpl.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/NumberTermImpl.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -58,7 +58,7 @@ } public NumberTermImpl(NumberTermImpl t) { - value = t.solve(); + value = t.value; srcInfo = t.srcInfo; } @@ -90,7 +90,7 @@ @Override protected int calcHashCode() { - return 37 * (int)solve(); + return 37 * (int)value; } @Override @@ -98,10 +98,10 @@ if (o instanceof VarTerm) { return o.compareTo(this) * -1; } - if (o instanceof NumberTerm) { - NumberTerm st = (NumberTerm)o; - if (solve() > st.solve()) return 1; - if (solve() < st.solve()) return -1; + if (o instanceof NumberTermImpl) { + NumberTermImpl st = (NumberTermImpl)o; + if (value > st.value) return 1; + if (value < st.value) return -1; return 0; } return -1; Modified: trunk/src/jason/asSyntax/ObjectTermImpl.java =================================================================== --- trunk/src/jason/asSyntax/ObjectTermImpl.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/ObjectTermImpl.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -35,12 +35,12 @@ return this.o.equals(((ObjectTermImpl) o).o); } - if (o instanceof VarTerm) { + /*if (o instanceof VarTerm) { Term value = ((VarTerm) o).getValue(); if (value instanceof ObjectTermImpl) { return this.o.equals(((ObjectTermImpl) value).o); } - } + }*/ return false; } Modified: trunk/src/jason/asSyntax/Plan.java =================================================================== --- trunk/src/jason/asSyntax/Plan.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Plan.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -207,6 +207,25 @@ return false; } + public Plan capply(Unifier u) { + Plan p = new Plan(); + if (label != null) { + p.label = (Pred) label.capply(u); + p.isAtomic = isAtomic; + p.hasBreakpoint = hasBreakpoint; + p.isAllUnifs = isAllUnifs; + } + + p.tevent = tevent.capply(u); + if (context != null) + p.context = (LogicalFormula)context.capply(u); + p.body = (PlanBody)body.capply(u); + p.setSrcInfo(srcInfo); + p.isTerm = isTerm; + + return p; + } + public Term clone() { Plan p = new Plan(); if (label != null) { Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java =================================================================== --- trunk/src/jason/asSyntax/PlanBodyImpl.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -152,6 +152,7 @@ } } + /* private boolean applyHead(Unifier u) { if (term != null && term.apply(u)) { if (term.isPlanBody()) { // we cannot have "inner" body literals @@ -168,7 +169,9 @@ } return false; } + */ + /* @Override public boolean apply(Unifier u) { boolean ok = next != null && next.apply(u); @@ -181,6 +184,7 @@ return ok; } + */ @Override public Iterator<Unifier> logicalConsequence(Agent ag, Unifier un) { @@ -277,6 +281,29 @@ bl.setBodyTerm(l); } + @Override + public PlanBody capply(Unifier u) { + //System.out.println(this+" with "+u); + PlanBodyImpl c; + if (term == null) { // (NIDE) must copy c.isTerm even if cloning empty plan + c = new PlanBodyImpl(); + } else { + c = new PlanBodyImpl(formType, term.capply(u)); + if (c.term.isPlanBody()) { // we cannot have "inner" body literals + c.formType = ((PlanBody)c.term).getBodyType(); + c.next = ((PlanBody)c.term).getBodyNext(); + c.term = ((PlanBody)c.term).getBodyTerm(); + } + } + c.isTerm = isTerm; + + if (next != null) + c.add((PlanBody)next.capply(u)); + + //System.out.println(this+" = "+c+" using "+u+" term="+c.term+"/"+term.capply(u)); + return c; + } + public PlanBody clone() { PlanBodyImpl c; if (term == null) // (NIDE) must copy c.isTerm even if cloning empty plan Modified: trunk/src/jason/asSyntax/Pred.java =================================================================== --- trunk/src/jason/asSyntax/Pred.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Pred.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -27,7 +27,6 @@ import jason.asSyntax.parser.as2j; import java.io.StringReader; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -61,10 +60,20 @@ } } + // used by capply + protected Pred(Literal l, Unifier u) { + super(l,u); + if (l.hasAnnot()) { + setAnnots( (ListTerm)l.getAnnots().capply(u) ); + } else { + annots = null; + } + } + public Pred(String functor, int termsSize) { super(functor, termsSize); } - + public static Pred parsePred(String sPred) { as2j parser = new as2j(new StringReader(sPred)); try { @@ -94,19 +103,27 @@ } } + /* @Override public boolean apply(Unifier u) { - boolean r = super.apply(u); + boolean r1 = super.apply(u); + boolean r2 = applyAnnots(u); + return r1 || r2; + } + */ + /* + private final boolean applyAnnots(Unifier u) { + boolean r = false; if (annots != null) { // if some annotation has variables that become ground, they need to be replaced in the list to maintain the order - List<Term> toAdd = null; + List<Term> toAdd = null; Iterator<ListTerm> i = annots.listTermIterator(); while (i.hasNext()) { ListTerm lt = i.next(); if (lt.isTail() && lt.getTail().apply(u)) { // have to test tail before term, since term test may lead to i.remove that remove also the tail r = true; lt.getTerm().apply(u); // apply for the term - setAnnots(annots); // sort all annots given in from tail ground + setAnnots(annots); // sort all annots given from tail ground break; // the iterator is inconsistent } else if (lt.getTerm() != null && lt.getTerm().apply(u)) { r = true; @@ -120,8 +137,9 @@ for (Term t: toAdd) addAnnot(t); } - return r; + return r; } + */ @Override public Literal setAnnots(ListTerm l) { @@ -542,6 +560,11 @@ return 0; } + @Override + public Term capply(Unifier u) { + return new Pred(this,u); + } + public Term clone() { return new Pred(this); } Modified: trunk/src/jason/asSyntax/RelExpr.java =================================================================== --- trunk/src/jason/asSyntax/RelExpr.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/RelExpr.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -81,13 +81,13 @@ } public Iterator<Unifier> logicalConsequence(final Agent ag, Unifier un) { - Term xp = getTerm(0).clone(); - Term yp = getTerm(1).clone(); - xp.apply(un); - yp.apply(un); + Term xp = getTerm(0).capply(un); + Term yp = getTerm(1).capply(un); switch (op) { + case none: break; + case gt : if (xp.compareTo(yp) > 0) return LogExpr.createUnifIterator(un); break; case gte: if (xp.compareTo(yp) >= 0) return LogExpr.createUnifIterator(un); break; case lt : if (xp.compareTo(yp) < 0) return LogExpr.createUnifIterator(un); break; @@ -143,9 +143,14 @@ return null; } + @Override + public Term capply(Unifier u) { + return new RelExpr(getTerm(0).capply(u), op, getTerm(1).capply(u)); + } + /** make a hard copy of the terms */ public LogicalFormula clone() { - return new RelExpr(getTerm(0).clone(), op, getTerm(1).clone()); + return new RelExpr(getTerm(0).clone(), op, getTerm(1).clone()); } /** gets the Operation of this Expression */ Modified: trunk/src/jason/asSyntax/Rule.java =================================================================== --- trunk/src/jason/asSyntax/Rule.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Rule.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -56,6 +56,13 @@ this.body = body; } + public Rule(Rule r, Unifier u) { + super(r,u); + body = (LogicalFormula)r.body.capply(u); + predicateIndicatorCache = null; + } + + @Override public boolean isRule() { return true; @@ -71,8 +78,8 @@ } @Override - public int hashCode() { - return super.hashCode() + body.hashCode(); + protected int calcHashCode() { + return super.calcHashCode() + body.hashCode(); } public LogicalFormula getBody() { @@ -86,17 +93,26 @@ return super.makeVarsAnnon(un); } + @Override + public Term capply(Unifier u) { + return new Rule(this,u); + } + public Rule clone() { Rule r = new Rule((Literal)super.clone(), (LogicalFormula)body.clone()); r.predicateIndicatorCache = null; r.resetHashCodeCache(); return r; } - + public Literal headClone() { return (Literal)super.clone(); } + public Literal headCApply(Unifier u) { + return (Literal)super.capply(u); + } + public String toString() { return super.toString() + " :- " + body; } Modified: trunk/src/jason/asSyntax/Structure.java =================================================================== --- trunk/src/jason/asSyntax/Structure.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Structure.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -69,6 +69,16 @@ terms.add(l.getTerm(i).clone()); } + // used by capply + protected Structure(Literal l, Unifier u) { + super(l); + final int tss = l.getArity(); + terms = new ArrayList<Term>(tss); + for (int i = 0; i < tss; i++) + terms.add(l.getTerm(i).capply(u)); + resetHashCodeCache(); + } + /** * Create a structure with a defined number of terms. * @@ -172,6 +182,7 @@ } + /* @Override public boolean apply(Unifier u) { boolean r = false; @@ -185,7 +196,12 @@ resetHashCodeCache(); return r; } + */ + @Override + public Term capply(Unifier u) { + return new Structure(this,u); + } /** make a deep copy of the terms */ public Term clone() { @@ -287,6 +303,10 @@ return true; } + public boolean isUnary() { + return getArity() == 1; + } + @Override public Literal makeVarsAnnon() { return makeVarsAnnon(new Unifier()); Modified: trunk/src/jason/asSyntax/Term.java =================================================================== --- trunk/src/jason/asSyntax/Term.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Term.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -41,8 +41,11 @@ public boolean subsumes(Term l); /** replaces variables by their values in the unifier, returns true if some variable was applied */ - public boolean apply(Unifier u); + //public boolean apply(Unifier u); + /** clone and applies together (and faster than clone and then apply) */ + public Term capply(Unifier u); + /** Removes the value cached for hashCode */ //public void resetHashCodeCache(); Modified: trunk/src/jason/asSyntax/Trigger.java =================================================================== --- trunk/src/jason/asSyntax/Trigger.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/Trigger.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -167,6 +167,15 @@ c.isTerm = isTerm; return c; } + + @Override + public Trigger capply(Unifier u) { + Trigger c = new Trigger(operator, type, (Literal)literal.capply(u)); + c.predicateIndicatorCache = this.predicateIndicatorCache; + c.isTerm = isTerm; + return c; + } + /** return [+|-][!|?] super.getPredicateIndicator */ @Override @@ -177,9 +186,9 @@ return predicateIndicatorCache; } - public boolean apply(Unifier u) { + /*public boolean apply(Unifier u) { return literal.apply(u); - } + }*/ public Literal getLiteral() { return literal; @@ -211,7 +220,7 @@ if (t instanceof Trigger) { return (Trigger)t; } - if (t instanceof VarTerm) { + /*if (t instanceof VarTerm) { VarTerm v = (VarTerm)t; if (v.hasValue() && v.getValue() instanceof Trigger) { return (Trigger)v.getValue(); @@ -219,7 +228,7 @@ if (v.hasValue() && v.getValue() instanceof Plan) { return ((Plan)v.getValue()).getTrigger(); } - } + }*/ if (t.isString()) { return ASSyntax.parseTrigger(((StringTerm)t).getString()); } Modified: trunk/src/jason/asSyntax/UnnamedVar.java =================================================================== --- trunk/src/jason/asSyntax/UnnamedVar.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/UnnamedVar.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -66,22 +66,22 @@ */ public Term clone() { - if (hasValue()) { + /*if (hasValue()) { return getValue().clone(); - } else { + } else {*/ UnnamedVar newv = new UnnamedVar(getFunctor()); newv.myId = this.myId; //newv.fromRename = this.fromRename; if (hasAnnot()) newv.addAnnots(this.getAnnots().cloneLT()); return newv; - } + //} } public int compareTo(Term t) { - if (hasValue()) { + /*if (hasValue()) { return super.compareTo(t); - } else if (t instanceof UnnamedVar) { + } else */if (t instanceof UnnamedVar) { if (myId > ((UnnamedVar)t).myId) return 1; else if (myId < ((UnnamedVar)t).myId) @@ -97,6 +97,6 @@ @Override public boolean isUnnamedVar() { - return !hasValue(); + return true; //!hasValue(); } } Modified: trunk/src/jason/asSyntax/VarTerm.java =================================================================== --- trunk/src/jason/asSyntax/VarTerm.java 2013-11-04 11:27:47 UTC (rev 1756) +++ trunk/src/jason/asSyntax/VarTerm.java 2013-11-07 14:02:11 UTC (rev 1757) @@ -23,6 +23,7 @@ package jason.asSyntax; +import jason.NoValueForVarException; import jason.asSemantics.Agent; import jason.asSemantics.Unifier; import jason.asSyntax.parser.as2j; @@ -50,12 +51,12 @@ * * @author jomi */ -public class VarTerm extends LiteralImpl implements NumberTerm, ListTerm, StringTerm, ObjectTerm, PlanBody { +public class VarTerm extends LiteralImpl implements NumberTerm, ListTerm { //, StringTerm, ObjectTerm, PlanBody { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(VarTerm.class.getName()); - private Term value = null; + //private Term value = null; public VarTerm(String s) { super(s); @@ -79,33 +80,71 @@ return null; } } + + @Override + public Term capply(Unifier u) { + if (u != null) { + Term vl = u.get(this); + if (vl != null) { + if (!vl.isCyclicTerm() && vl.hasVar(this, u)) { + //logger.warning("The value of a variable contains itself, variable "+super.getFunctor()+" "+super.getSrcInfo()+", value="+vl+", unifier="+u); + + u.remove(this); // remove this var to avoid loops in the apply below + Term tempVl = vl.capply(u); + u.bind(this, vl); + + CyclicTerm ct = new CyclicTerm((Literal)tempVl, this); + Unifier renamedVars = new Unifier(); // remove "this" from the value to avoid loops in apply + ct.makeVarsAnnon(renamedVars); + renamedVars.remove(this); + u.compose(renamedVars); + vl = ct; + } + + vl = vl.capply(u); // should clone here, since there is no cloning in unify + // decide whether to use var annots in apply + // X = p[a] + // !X[b] + // what's the event: + // +!p[a] + // or + // +!p[a,b] + // Answer: use annots of var, useful for meta-programming like + // P[step(N)] + if (vl.isLiteral() && this.hasAnnot()) { // if this var has annots, add them in the value's annots (Experimental) + vl = ((Literal)vl).forceFullLiteralImpl().addAnnots((ListTerm)this.getAnnots().capply(u)); + } + return vl; + } + } + return clone(); + } public Term clone() { - if (value != null) { - return value.clone(); - } else { - // do not call constructor with term parameter! - VarTerm t = new VarTerm(super.getFunctor()); - t.setNegated(!negated()); - t.srcInfo = this.srcInfo; - if (hasAnnot()) - t.setAnnots(getAnnots().cloneLT()); - return t; - } + // do not call constructor with term parameter! + VarTerm t = new VarTerm(super.getFunctor()); + t.setNegated(!negated()); + t.srcInfo = this.srcInfo; + if (hasAnnot()) + t.setAnnots(getAnnots().cloneLT()); + return t; } - + + /* public PlanBody clonePB() { return (PlanBody)clone(); } + */ public ListTerm cloneLT() { return (ListTerm)clone(); } + @Override public boolean isVar() { - return value == null; + return true; } public boolean isUnnamedVar() { @@ -114,14 +153,14 @@ @Override public boolean isGround() { - return value != null && value.isGround(); + return false; } /** * grounds a variable, set a value for this var * (e.g. X = 10; Y = a(b,c); ...) */ - public boolean setValue(Term vl) { + /*public boolean setValue(Term vl) { if (vl.isVar()) { logger.log(Level.WARNING, "Attempted set a variable as a value for a variable, in " + this.getFunctor(), new Exception()); return false; @@ -144,13 +183,15 @@ value = vl; resetHashCodeCache(); return true; - } + }*/ /** returns true if this var has a value */ +/* public boolean hasValue() { return value != null; } - +*/ + /* public boolean apply(Unifier u) { if (value == null) { ... [truncated message content] |
From: <jom...@us...> - 2013-11-04 11:27:53
|
Revision: 1756 http://sourceforge.net/p/jason/svn/1756 Author: jomifred Date: 2013-11-04 11:27:47 +0000 (Mon, 04 Nov 2013) Log Message: ----------- initial implementation of tail recursion optimisation Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java trunk/applications/as-unit-test/src/jason/tests/TestAll.java trunk/release-notes.txt trunk/src/jason/asSemantics/Intention.java trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSemantics/Unifier.java trunk/src/jason/runtime/Settings.java Added Paths: ----------- trunk/applications/as-unit-test/src/jason/tests/TestTRO.java Modified: trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java 2013-10-31 20:20:03 UTC (rev 1755) +++ trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java 2013-11-04 11:27:47 UTC (rev 1756) @@ -28,8 +28,8 @@ "+!a(Y)[x(Z),kk] <- Y=3; Z=4. "+ "+!a(Y)[x(Z),source(self)] <- Y=1; Z=2. "+ - "+!test4 <- X = [a,b,c]; !deleteb(X,Y); jason.asunit.print(Y)."+ - "+!test5 <- X = [a,b,c]; !deleteb2(X,Y); jason.asunit.print(Y)."+ + "+!test4 <- X = [a,b,c,b,b,d]; !deleteb(X,Y); jason.asunit.print(Y)."+ + "+!test5 <- X = [a,b,c,b,b,d]; !deleteb2(X,Y); jason.asunit.print(Y)."+ "+!deleteb([], [])."+ "+!deleteb([b|L1], L2)"+ @@ -64,12 +64,12 @@ @Test(timeout=2000) public void testDelete1() { ag.addGoal("test4"); - ag.assertPrint("[a,c]", 10); + ag.assertPrint("[a,c,d]", 10); } @Test(timeout=2000) public void testDelete2() { ag.addGoal("test5"); - ag.assertPrint("[a,c]", 10); + ag.assertPrint("[a,c,d]", 20); } } Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-10-31 20:20:03 UTC (rev 1755) +++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-11-04 11:27:47 UTC (rev 1756) @@ -26,6 +26,7 @@ TestVarInContext.class, TestUnnamedVar.class, TestCopyTerm.class, - TestNegatedVar.class + TestNegatedVar.class, + TestTRO.class }) public class TestAll { } Added: trunk/applications/as-unit-test/src/jason/tests/TestTRO.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestTRO.java (rev 0) +++ trunk/applications/as-unit-test/src/jason/tests/TestTRO.java 2013-11-04 11:27:47 UTC (rev 1756) @@ -0,0 +1,31 @@ +package jason.tests; + +import jason.asunit.TestAgent; + +import org.junit.Before; +import org.junit.Test; + +// test Tail Recursion Optimization +public class TestTRO { + + TestAgent ag; + + // initialisation of the agent test + @Before + public void setupAg() { + ag = new TestAgent(); + + // defines the agent's AgentSpeak code + ag.parseAScode( + "+!run <- !fat(5,1,F); jason.asunit.print(F). "+ + "+!fat(1,V,V). "+ + "+!fat(N,A,X) <- !fat(N-1,N*A,X)." + ); + } + + @Test(timeout=2000) + public void testGoalSrouce() { + ag.addGoal("run"); + ag.assertPrint("120", 50); + } +} Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-10-31 20:20:03 UTC (rev 1755) +++ trunk/release-notes.txt 2013-11-04 11:27:47 UTC (rev 1756) @@ -1,3 +1,10 @@ +New features + +- implementation of tail recursion optimisation for sub-goals. + It can be turned off in agent options, e.g.: + agents: bob [tro=false]; + + --------------------------- version 1.3.10b @@ -218,7 +225,7 @@ these events can than be handled by plans such as ^!goto(X,Y)[state(S)] <- .print("goto state is ",S). for the state suspended, another annotation contains the - suspension reason (.wait, .suspend, É) + suspension reason (.wait, .suspend, ...) ^!goto(X,Y)[state(S)[reason(R)]] <- .print("goto state is ",S," due to ",R). Modified: trunk/src/jason/asSemantics/Intention.java =================================================================== --- trunk/src/jason/asSemantics/Intention.java 2013-10-31 20:20:03 UTC (rev 1755) +++ trunk/src/jason/asSemantics/Intention.java 2013-11-04 11:27:47 UTC (rev 1756) @@ -193,7 +193,7 @@ } public String toString() { - StringBuilder s = new StringBuilder("intention "+id+": "); + StringBuilder s = new StringBuilder("intention "+id+": \n"); for (IntendedMeans im: intendedMeans) s.append(" " + im + "\n"); if (isFinished()) Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-10-31 20:20:03 UTC (rev 1755) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-11-04 11:27:47 UTC (rev 1756) @@ -493,6 +493,41 @@ confP.C.addIntention(intention); } else { // Rule IntEv + + // begin tail recursion optimisation (TRO) + if (setts.isTROon()) { + IntendedMeans top = confP.C.SE.intention.peek(); // top = the IM that will be removed from the intention due to TRO + if (top.getTrigger().isGoal() && im.getTrigger().isGoal() && // are both goal + top.getTrigger().getPredicateIndicator().equals( im.getTrigger().getPredicateIndicator()) && // are they equals + top.getCurrentStep().getBodyNext() == null) { // the plan below is finished + confP.C.SE.intention.pop(); // remove the top IM + + IntendedMeans imBase = confP.C.SE.intention.peek(); // base = where the new IM will be place on top of + // move top relevant values into the base (relevant = renamed vars in base) + for (VarTerm v: imBase.renamedVars) { + VarTerm vvl = (VarTerm)imBase.renamedVars.function.get(v); + Term t = top.unif.get(vvl); + if (t != null) { // if v has got a value in top unif, put the value in the unifier + if (t instanceof Literal) { + Literal l= (Literal)t.clone(); + l.apply(top.unif); + l.makeVarsAnnon(top.renamedVars); + im.unif.function.put(vvl, l); + } else { + im.unif.function.put(vvl, t); + } + } else { + // the vvl was renamed again in top, just replace in base the new value + VarTerm v0 = (VarTerm)top.renamedVars.function.get(vvl); + if (v0 != null) { + imBase.renamedVars.function.put(v, v0); + } + } + } + } + // end of TRO + } + confP.C.SE.intention.push(im); confP.C.addIntention(confP.C.SE.intention); } @@ -807,10 +842,30 @@ body = body.copy(); body.apply(u); Unifier renamedVars = new Unifier(); - if (imRenamedVars != null) + //System.out.println("antes "+body+" "+u+" "); + body.makeVarsAnnon(renamedVars); // free variables in an event cannot conflict with those in the plan + if (imRenamedVars != null) { imRenamedVars.renamedVars = renamedVars; - body.makeVarsAnnon(renamedVars); // free variables in an event cannot conflict with those in the plan - //body.makeVarsAnnon(u); // free variables in an event cannot conflict with those in the plan + + // Code for TRO (Tail Recursion Opt) + if (setts.isTROon()) { + // renamed vars binded with another var in u need to be preserved (since u will be lost in TRO) + Map<VarTerm, Term> adds = null; + for (VarTerm v: renamedVars) { + Term t = u.function.get(v); + if (t != null) { + //System.out.println("adding "+t+"="+renamedVars.function.get(v)); + if (adds == null) + adds = new HashMap<VarTerm, Term>(); + adds.put((VarTerm)t,renamedVars.function.get(v)); + } + } + if (adds != null) + renamedVars.function.putAll(adds); + //System.out.println("depois "+body+" "+renamedVars+" u="+u); + // end code for TRO + } + } body = body.forceFullLiteralImpl(); if (!body.hasSource()) { // do not add source(self) in case the programmer set the source body.addAnnot(BeliefBase.TSelf); @@ -883,52 +938,23 @@ // old code: /*topLiteral.apply(topIM.unif); topLiteral.makeVarsAnnon(); - im.unif.unifies(im.removeCurrentStep(), topLiteral); + Literal cstep = (Literal)im.removeCurrentStep(); + boolean r = im.unif.unifies(cstep,topLiteral); */ // new code optimised: handle directly renamed vars for the call - //System.out.println("* "+topLiteral+topIM.unif+" "+im.unif+" "+im.renamedVars); - /*VarTerm[] lvt = null; - Term[] lvl = null; - int n = 0; - // get vars in the unifier that comes from makeVarAnnon - for (Term t: im.unif.function.values()) { - if (t instanceof UnnamedVar) { - UnnamedVar vt = (UnnamedVar)t; - if (vt.isFromMakeVarAnnon()) { - Term vl = topIM.unif.function.get(vt); - if (vl != null) { // vt has value in top - vl = vl.clone(); - vl.apply(topIM.unif); - if (vl.isLiteral()) - ((Literal)vl).makeVarsAnnon(); - if (lvt == null) { - int s = Math.max(im.unif.size(),topIM.unif.size()); - lvt = new VarTerm[s]; - lvl = new Term[s]; - } - lvt[n] = vt; - lvl[n] = vl; - n++; - } - } - } - } - for (int il=0; il<n; il++) { - im.unif.bind(lvt[il], lvl[il]); - } - */ - - // get vars in the unifier that comes from makeVarAnnon (stored in renamedVars) if (im.renamedVars != null) { for (VarTerm ov: im.renamedVars.function.keySet()) { + //System.out.println("looking for a value for "+ov+" in "+im.renamedVars+" and "+topIM.unif); UnnamedVar vt = (UnnamedVar)im.renamedVars.function.get(ov); + //System.out.println(" via "+vt); im.unif.unifiesNoUndo(ov, vt); // introduces the renaming in the current unif // if vt has got a value from the top (a "return" value), include this value in the current unif Term vl = topIM.unif.function.get(vt); //System.out.println(ov+"="+vt+"="+vl); if (vl != null) { // vt has value in top + //System.out.println(" and found "+vl); vl = vl.clone(); vl.apply(topIM.unif); if (vl.isLiteral()) @@ -937,8 +963,7 @@ } } } - //System.out.println("=> "+im.unif); - im.removeCurrentStep(); + im.removeCurrentStep(); } } } Modified: trunk/src/jason/asSemantics/Unifier.java =================================================================== --- trunk/src/jason/asSemantics/Unifier.java 2013-10-31 20:20:03 UTC (rev 1755) +++ trunk/src/jason/asSemantics/Unifier.java 2013-11-04 11:27:47 UTC (rev 1756) @@ -103,6 +103,16 @@ } return vl; } + + public VarTerm getVarFromValue(Term vl) { + for (VarTerm v: function.keySet()) { + Term vvl = function.get(v); + if (vvl.equals(vl)) { + return v; + } + } + return null; + } public boolean unifies(Trigger te1, Trigger te2) { return te1.sameType(te2) && unifies(te1.getLiteral(), te2.getLiteral()); Modified: trunk/src/jason/runtime/Settings.java =================================================================== --- trunk/src/jason/runtime/Settings.java 2013-10-31 20:20:03 UTC (rev 1755) +++ trunk/src/jason/runtime/Settings.java 2013-11-04 11:27:47 UTC (rev 1756) @@ -52,6 +52,7 @@ private boolean sync = ODefaultSync; private boolean qCache = false; // whether to use query cache private boolean qProfiling = false; // whether has query profiling + private boolean troON = true; // tail recursion optimisation is on by default private Map<String,Object> userParameters = new HashMap<String,Object>(); @@ -108,6 +109,8 @@ } else if (key.equals("synchronised")) { setSync("true".equals((String)options.get("synchronised"))); + } else if (key.equals("tro")) { + setTRO("true".equals((String)options.get("tro"))); } else if (key.equals("qcache")) { setQueryCache( "cycle".equals((String)options.get("qcache")) ); } else if (key.equals("qprofiling")) { @@ -200,6 +203,13 @@ sync = pSync; } + public boolean isTROon() { + return troON; + } + public void setTRO(boolean tro) { + troON = tro; + } + public boolean hasQueryCache() { return qCache; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-10-31 20:20:07
|
Revision: 1755 http://sourceforge.net/p/jason/svn/1755 Author: jomifred Date: 2013-10-31 20:20:03 +0000 (Thu, 31 Oct 2013) Log Message: ----------- fix bugs in PlanBodyImpl as reported by NIDE, Naoyuki Modified Paths: -------------- trunk/src/jason/asSemantics/IntendedMeans.java trunk/src/jason/asSyntax/PlanBodyImpl.java Modified: trunk/src/jason/asSemantics/IntendedMeans.java =================================================================== --- trunk/src/jason/asSemantics/IntendedMeans.java 2013-10-29 20:25:04 UTC (rev 1754) +++ trunk/src/jason/asSemantics/IntendedMeans.java 2013-10-31 20:20:03 UTC (rev 1755) @@ -132,9 +132,14 @@ } public Term getAsTerm() { - if (planBody instanceof PlanBodyImpl) { + if (planBody instanceof PlanBodyImpl || planBody == null) { // TODO: use same replacements (Var -> Unnamed var) for the plan and for the unifier - PlanBody bd = (PlanBody)((PlanBodyImpl)planBody.clone()).makeVarsAnnon(); + PlanBody bd; + if (planBody == null) { // (NIDE) in case we must convert empty plan to Term + bd = new PlanBodyImpl(); + } else { + bd = (PlanBody)((PlanBodyImpl)planBody.clone()).makeVarsAnnon(); + } bd.setAsBodyTerm(true); return ASSyntax.createStructure("im", ASSyntax.createString(plan.getLabel()), bd, unif.getAsTerm()); } else { Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java =================================================================== --- trunk/src/jason/asSyntax/PlanBodyImpl.java 2013-10-29 20:25:04 UTC (rev 1754) +++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2013-10-31 20:20:03 UTC (rev 1755) @@ -144,7 +144,12 @@ @Override public void setTerm(int i, Term t) { if (i == 0) term = t; - if (i == 1) System.out.println("Should not setTerm(1) of body literal!"); + if (i == 1) { // (NIDE) if next is the last VAR... + if (next != null && next.getBodyTerm().isVar() && next.getBodyNext() == null) + next.setBodyTerm(t); + else + System.out.println("Should not setTerm(1) of body literal!"); + } } private boolean applyHead(Unifier u) { @@ -202,6 +207,8 @@ /** clone the plan body and adds it in the end of this plan */ public boolean add(PlanBody bl) { + if (bl == null) // (NIDE) if bl is empty, do nothing + return true; if (term == null) { bl = bl.clonePB(); swap(bl); @@ -271,10 +278,11 @@ } public PlanBody clone() { - if (term == null) // empty - return new PlanBodyImpl(); - - PlanBodyImpl c = new PlanBodyImpl(formType, term.clone()); + PlanBodyImpl c; + if (term == null) // (NIDE) must copy c.isTerm even if cloning empty plan + c = new PlanBodyImpl(); + else + c = new PlanBodyImpl(formType, term.clone()); c.isTerm = isTerm; if (next != null) c.setBodyNext(getBodyNext().clonePB()); @@ -287,7 +295,7 @@ public String toString() { if (term == null) { - return ""; + return isTerm ? "{ }" : ""; // NIDE } else { StringBuilder out = new StringBuilder(); if (isTerm) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-10-29 20:25:06
|
Revision: 1754 http://sourceforge.net/p/jason/svn/1754 Author: jomifred Date: 2013-10-29 20:25:04 +0000 (Tue, 29 Oct 2013) Log Message: ----------- fix a bug in Message class as reported by Lucas Welter Hilgert Modified Paths: -------------- trunk/src/jason/asSemantics/Message.java trunk/src/jason/asSyntax/PredicateIndicator.java trunk/src/jason/stdlib/relevant_plans.java Modified: trunk/src/jason/asSemantics/Message.java =================================================================== --- trunk/src/jason/asSemantics/Message.java 2013-10-24 20:07:19 UTC (rev 1753) +++ trunk/src/jason/asSemantics/Message.java 2013-10-29 20:25:04 UTC (rev 1754) @@ -164,7 +164,7 @@ if (msg.startsWith("<")) { one = msg.indexOf(","); int arrowIndex = msg.indexOf("->"); - if (one < arrowIndex) { // If there is an arrow before the first comma + if (one > arrowIndex) { // If there is an arrow before the first comma newmsg.msgId = msg.substring(1, arrowIndex); newmsg.inReplyTo = msg.substring(arrowIndex + 2, one); } else { // If not (either there is no arrow, or there is one behind the first comma) Modified: trunk/src/jason/asSyntax/PredicateIndicator.java =================================================================== --- trunk/src/jason/asSyntax/PredicateIndicator.java 2013-10-24 20:07:19 UTC (rev 1753) +++ trunk/src/jason/asSyntax/PredicateIndicator.java 2013-10-29 20:25:04 UTC (rev 1754) @@ -1,11 +1,13 @@ package jason.asSyntax; +import java.io.Serializable; + /** * Represents the "type" of a predicate based on the functor and the arity, e.g.: ask/4 * * @author jomi */ -public final class PredicateIndicator { +public final class PredicateIndicator implements Serializable { private final String functor; private final int arity; Modified: trunk/src/jason/stdlib/relevant_plans.java =================================================================== --- trunk/src/jason/stdlib/relevant_plans.java 2013-10-24 20:07:19 UTC (rev 1753) +++ trunk/src/jason/stdlib/relevant_plans.java 2013-10-29 20:25:04 UTC (rev 1754) @@ -99,15 +99,13 @@ np.getLabel().delSources(); np.setAsPlanTerm(true); np.makeVarsAnnon(); - //StringTerm stplan = new StringTermImpl(np.toASString().replaceAll("\\\"", "\\\\\"")); - //last = last.append(stplan); last = last.append(np); if (args.length == 3) labels.add(np.getLabel()); } } - boolean ok = un.unifies(lt, args[1]); // second arg is a var; + boolean ok = un.unifies(lt, args[1]); // args[1] is a var; if (ok && args.length == 3) ok = un.unifies(labels, args[2]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-10-24 20:07:21
|
Revision: 1753 http://sourceforge.net/p/jason/svn/1753 Author: jomifred Date: 2013-10-24 20:07:19 +0000 (Thu, 24 Oct 2013) Log Message: ----------- generate failure event from send achieve without plan in the receiver Modified Paths: -------------- trunk/src/jason/asSemantics/TransitionSystem.java Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-10-21 13:52:25 UTC (rev 1752) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-10-24 20:07:19 UTC (rev 1753) @@ -311,7 +311,7 @@ if (!setts.isSync() && !ag.getPL().hasUserKqmlReceivedPlans() && content.isLiteral() && !content.isList()) { // optimisation to jump kqmlPlans if (m.getIlForce().equals("achieve") ) { content = add_nested_source.addAnnotToList(content, new Atom(sender)); - updateEvents(new Event(new Trigger(TEOperator.add, TEType.achieve, (Literal)content), Intention.EmptyInt)); + C.addEvent(new Event(new Trigger(TEOperator.add, TEType.achieve, (Literal)content), Intention.EmptyInt)); added = true; } else if (m.getIlForce().equals("tell") ) { content = add_nested_source.addAnnotToList(content, new Atom(sender)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-10-21 13:52:28
|
Revision: 1752 http://sourceforge.net/p/jason/svn/1752 Author: jomifred Date: 2013-10-21 13:52:25 +0000 (Mon, 21 Oct 2013) Log Message: ----------- fix minor bug in console Modified Paths: -------------- trunk/build.xml trunk/lib/UmlGraph.jar trunk/release-notes.txt trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/runtime/MASConsoleColorGUI.java trunk/src/jason/runtime/MASConsoleGUI.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2013-10-19 19:37:16 UTC (rev 1751) +++ trunk/build.xml 2013-10-21 13:52:25 UTC (rev 1752) @@ -12,7 +12,7 @@ <property name="dist.properties" value="${basedir}/bin/dist.properties" /> <property name="version" value="1" /> - <property name="release" value="3.10a" /> + <property name="release" value="3.10b" /> <property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" /> <property name="distFile" value="${env.HOME}/Jason-${version}.${release}" /> @@ -255,7 +255,7 @@ </not> </condition> - <target name="apidocsimple" unless="dot-ok" > <!-- stylesheetfile="doc/faq/faq.css" --> + <target name="apidocsimple" unless="dot-ok"> <!-- --> <javadoc destdir="${basedir}/doc/api" packagenames="jason.*" @@ -291,9 +291,9 @@ <param name="-qualify"/> <!--param name="-collapsible"/--> <param name="-postfixpackage"/> - <param name="-nodefontsize" value="14"/> - <param name="-nodefontpackagesize" value="8"/> - <param name="-edgefontsize" value="10"/> + <!--param name="-nodefontsize" value="14"/--> + <!--param name="-nodefontpackagesize" value="8"/--> + <!--param name="-edgefontsize" value="10"/--> <!--param name="-link" value="http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/spec"/> <param name="-link" value="http://java.sun.com/j2se/1.5/docs/api"/--> </doclet> Modified: trunk/lib/UmlGraph.jar =================================================================== (Binary files differ) Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-10-19 19:37:16 UTC (rev 1751) +++ trunk/release-notes.txt 2013-10-21 13:52:25 UTC (rev 1752) @@ -1,7 +1,7 @@ --------------------------- version 1.3.10b -revision 1748 on SVN +revision 1750 on SVN --------------------------- New features Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-10-19 19:37:16 UTC (rev 1751) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-10-21 13:52:25 UTC (rev 1752) @@ -579,28 +579,16 @@ PlanBody h = im.getCurrentStep(); Term bTerm = h.getBodyTerm(); - // de-var bTerm - //while (bTerm instanceof VarTerm) { - if (bTerm instanceof VarTerm) { - // check if bTerm is ground - /*if (((VarTerm)bTerm).hasValue()) { - bTerm = ((VarTerm)bTerm).getValue(); - continue; // restart the loop - }*/ - - // h should be 'groundable' (considering the current unifier) + + if (bTerm instanceof VarTerm) { // de-var bTerm bTerm = bTerm.clone(); // clone before apply bTerm.apply(u); - //Term bValue = u.get((VarTerm)bTerm); - //System.out.println("*** "+bTerm+"="+bValue+" "+bTerm.isGround()+" "+u); - //if (bValue == null) { // the case of !A with A not ground if (bTerm.isVar()) { // 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_without_value", msg))) logger.log(Level.SEVERE, msg); return; } - //if (bValue.isPlanBody()) { if (bTerm.isPlanBody()) { if (h.getBodyType() != BodyType.action) { // the case of ...; A = { !g }; +g; .... String msg = h.getSrcInfo()+": "+ "The operator '"+h.getBodyType()+"' is lost with the variable '"+bTerm+"' unified with a plan body. "; @@ -608,24 +596,16 @@ logger.log(Level.SEVERE, msg); return; } - //h = (PlanBody)bValue; h = (PlanBody)bTerm; if (h.getPlanSize() > 1) { // the case of A unified with {a;b;c} h.add(im.getCurrentStep().getBodyNext()); im.insertAsNextStep(h.getBodyNext()); } bTerm = h.getBodyTerm(); - } else { - ListTerm annots = ((VarTerm)bTerm).getAnnots(); - //bTerm = bValue; - if (bTerm.isLiteral() && annots != null) { - bTerm = ((Literal)bTerm).forceFullLiteralImpl(); - ((Literal)bTerm).addAnnots(annots); - } } } - Literal body = null; + Literal body = null; if (bTerm instanceof Literal) body = (Literal)bTerm; Modified: trunk/src/jason/runtime/MASConsoleColorGUI.java =================================================================== --- trunk/src/jason/runtime/MASConsoleColorGUI.java 2013-10-19 19:37:16 UTC (rev 1751) +++ trunk/src/jason/runtime/MASConsoleColorGUI.java 2013-10-21 13:52:25 UTC (rev 1752) @@ -94,7 +94,7 @@ int l = output.getDocument().getLength(); if (l > 60000) { cleanConsole(); - // l = output.getDocument().getLength(); + l = 0; } synchronized (this) { output.append(c, s); Modified: trunk/src/jason/runtime/MASConsoleGUI.java =================================================================== --- trunk/src/jason/runtime/MASConsoleGUI.java 2013-10-19 19:37:16 UTC (rev 1751) +++ trunk/src/jason/runtime/MASConsoleGUI.java 2013-10-21 13:52:25 UTC (rev 1752) @@ -206,7 +206,7 @@ int l = output.getDocument().getLength(); if (l > 60000) { cleanConsole(); - // l = output.getDocument().getLength(); + l = 0; } synchronized (this) { output.append(s); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-10-19 19:37:19
|
Revision: 1751 http://sourceforge.net/p/jason/svn/1751 Author: jomifred Date: 2013-10-19 19:37:16 +0000 (Sat, 19 Oct 2013) Log Message: ----------- allows unicode chars in JacaCC input files Modified Paths: -------------- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc trunk/src/jason/asSyntax/parser/as2j.java trunk/src/jason/asSyntax/parser/as2jTokenManager.java trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc trunk/src/jason/mas2j/parser/mas2jTokenManager.java trunk/src/jason/runtime/MASConsoleColorGUI.java trunk/src/jason/runtime/MASConsoleGUI.java Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc =================================================================== --- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2013-10-04 14:35:08 UTC (rev 1750) +++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2013-10-19 19:37:16 UTC (rev 1751) @@ -25,6 +25,7 @@ FORCE_LA_CHECK=true; STATIC=false; IGNORE_CASE=false; + UNICODE_INPUT=true; } PARSER_BEGIN(as2j) Modified: trunk/src/jason/asSyntax/parser/as2j.java =================================================================== --- trunk/src/jason/asSyntax/parser/as2j.java 2013-10-04 14:35:08 UTC (rev 1750) +++ trunk/src/jason/asSyntax/parser/as2j.java 2013-10-19 19:37:16 UTC (rev 1751) @@ -1524,11 +1524,6 @@ finally { jj_save(1, xla); } } - final private boolean jj_3R_54() { - if (jj_3R_61()) return true; - return false; - } - final private boolean jj_3R_67() { if (jj_3R_79()) return true; return false; @@ -2132,6 +2127,11 @@ return false; } + final private boolean jj_3R_54() { + if (jj_3R_61()) return true; + return false; + } + public as2jTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; Modified: trunk/src/jason/asSyntax/parser/as2jTokenManager.java =================================================================== --- trunk/src/jason/asSyntax/parser/as2jTokenManager.java 2013-10-04 14:35:08 UTC (rev 1750) +++ trunk/src/jason/asSyntax/parser/as2jTokenManager.java 2013-10-19 19:37:16 UTC (rev 1751) @@ -364,6 +364,9 @@ jjCheckNAdd(jjnextStates[start + 1]); } static final long[] jjbitVec0 = { + 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec2 = { 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL }; private final int jjMoveNfa_0(int startState, int curPos) @@ -729,6 +732,9 @@ } else { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); MatchLoop: do @@ -736,20 +742,20 @@ switch(jjstateSet[--i]) { case 1: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(10, 12); break; case 15: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(0, 2); break; case 20: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjCheckNAddTwoStates(20, 21); break; case 22: case 23: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjCheckNAddTwoStates(23, 21); break; default : break; @@ -773,6 +779,18 @@ 15, 16, 18, 36, 37, 38, 39, 40, 14, 19, 1, 2, 4, 1, 2, 6, 4, 21, 22, 24, 3, 5, 7, 30, 31, 41, 42, }; +private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec2[i2] & l2) != 0L); + default : + if ((jjbitVec0[i1] & l1) != 0L) + return true; + return false; + } +} public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, null, null, "\164\162\165\145", "\146\141\154\163\145", "\156\157\164", "\176", "\144\151\166", "\155\157\144", Modified: trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc =================================================================== --- trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2013-10-04 14:35:08 UTC (rev 1750) +++ trunk/src/jason/mas2j/parser/MAS2JavaParser.jcc 2013-10-19 19:37:16 UTC (rev 1751) @@ -24,6 +24,7 @@ options { STATIC=false; + UNICODE_INPUT=true; } PARSER_BEGIN(mas2j) Modified: trunk/src/jason/mas2j/parser/mas2jTokenManager.java =================================================================== --- trunk/src/jason/mas2j/parser/mas2jTokenManager.java 2013-10-04 14:35:08 UTC (rev 1750) +++ trunk/src/jason/mas2j/parser/mas2jTokenManager.java 2013-10-19 19:37:16 UTC (rev 1751) @@ -777,6 +777,9 @@ jjCheckNAdd(jjnextStates[start + 1]); } static final long[] jjbitVec0 = { + 0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +static final long[] jjbitVec2 = { 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL }; private final int jjMoveNfa_0(int startState, int curPos) @@ -1529,6 +1532,9 @@ } else { + int hiByte = (int)(curChar >> 8); + int i1 = hiByte >> 6; + long l1 = 1L << (hiByte & 077); int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); MatchLoop: do @@ -1536,20 +1542,20 @@ switch(jjstateSet[--i]) { case 37: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(7, 9); break; case 65: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjAddStates(14, 16); break; case 70: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjCheckNAddTwoStates(70, 71); break; case 72: case 73: - if ((jjbitVec0[i2] & l2) != 0L) + if (jjCanMove_0(hiByte, i1, i2, l1, l2)) jjCheckNAddTwoStates(73, 71); break; default : break; @@ -1573,6 +1579,18 @@ 82, 83, 31, 84, 85, 64, 69, 37, 38, 40, 37, 38, 42, 40, 65, 66, 68, 71, 72, 74, 78, 79, 80, 56, 62, 34, 35, 39, 41, 43, 86, 87, }; +private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2) +{ + switch(hiByte) + { + case 0: + return ((jjbitVec2[i2] & l2) != 0L); + default : + if ((jjbitVec0[i1] & l1) != 0L) + return true; + return false; + } +} public static final String[] jjstrLiteralImages = { "", null, null, null, null, null, null, "\115\101\123", "\141\147\145\156\164\163", "\145\156\166\151\162\157\156\155\145\156\164", Modified: trunk/src/jason/runtime/MASConsoleColorGUI.java =================================================================== --- trunk/src/jason/runtime/MASConsoleColorGUI.java 2013-10-04 14:35:08 UTC (rev 1750) +++ trunk/src/jason/runtime/MASConsoleColorGUI.java 2013-10-19 19:37:16 UTC (rev 1751) @@ -10,6 +10,7 @@ import javax.swing.JTextPane; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; +import javax.swing.text.DefaultCaret; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; @@ -45,6 +46,7 @@ protected void initOutput() { output = new MASColorTextPane(Color.black); output.setEditable(false); + ((DefaultCaret)output.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); if (isTabbed()) { tabPane.add("common", new JScrollPane(output)); } else { @@ -83,10 +85,8 @@ int l = ta.getDocument().getLength(); if (l > 100000) { ta.setText(""); - // l = output.getDocument().getLength(); } ta.append(s); - // output.setCaretPosition(l); } } @@ -98,6 +98,7 @@ } synchronized (this) { output.append(c, s); + output.setCaretPosition(l); } } catch (Exception e) { close(); Modified: trunk/src/jason/runtime/MASConsoleGUI.java =================================================================== --- trunk/src/jason/runtime/MASConsoleGUI.java 2013-10-04 14:35:08 UTC (rev 1750) +++ trunk/src/jason/runtime/MASConsoleGUI.java 2013-10-19 19:37:16 UTC (rev 1751) @@ -43,6 +43,7 @@ import javax.swing.JScrollPane; import javax.swing.JTabbedPane; import javax.swing.JTextArea; +import javax.swing.text.DefaultCaret; /** the GUI console to output log messages */ public class MASConsoleGUI { @@ -109,6 +110,7 @@ protected void initOutput() { output = new JTextArea(); output.setEditable(false); + ((DefaultCaret)output.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); if (isTabbed) { tabPane.add("common", new JScrollPane(output)); } else { @@ -195,10 +197,8 @@ int l = ta.getDocument().getLength(); if (l > 100000) { ta.setText(""); - // l = output.getDocument().getLength(); } ta.append(s); - // output.setCaretPosition(l); } } @@ -210,6 +210,7 @@ } synchronized (this) { output.append(s); + output.setCaretPosition(l); } } catch (Exception e) { close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-10-04 14:35:13
|
Revision: 1750 http://sourceforge.net/p/jason/svn/1750 Author: jomifred Date: 2013-10-04 14:35:08 +0000 (Fri, 04 Oct 2013) Log Message: ----------- fix a bug in meta-vars in plans (like !G[annot(A)]) Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/BugVarsAsGoal.java trunk/release-notes.txt trunk/src/jason/asSyntax/VarTerm.java Modified: trunk/applications/as-unit-test/src/jason/tests/BugVarsAsGoal.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/BugVarsAsGoal.java 2013-09-16 12:56:58 UTC (rev 1749) +++ trunk/applications/as-unit-test/src/jason/tests/BugVarsAsGoal.java 2013-10-04 14:35:08 UTC (rev 1750) @@ -19,7 +19,12 @@ ag.parseAScode( "+!g <- +p(ggg); !gg; Y={!ggg}; Y. " + "+!gg : p(X) <- +X; !!X. " + - "+!ggg[source(A)] <- jason.asunit.print(A). " + "+!ggg[source(A)] <- jason.asunit.print(A). "+ + "+!jig[scheme(S)] <- jason.asunit.print(S)." + + "+!jig <- jason.asunit.print(noscheme)." + + "+!test1(S) <- !run(jig,S)." + + "+!test2(G) <- !G." + + "+!run(G,S) <- !G[scheme(S)]." ); } @@ -29,4 +34,15 @@ ag.assertPrint("self", 10); ag.assertPrint("self", 10); } + + @Test(timeout=2000) + public void test1() { + ag.addGoal("test1(s1)"); + ag.assertPrint("s1", 10); + } + @Test(timeout=2000) + public void test2() { + ag.addGoal("test2(jig)"); + ag.assertPrint("noscheme", 10); + } } Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-09-16 12:56:58 UTC (rev 1749) +++ trunk/release-notes.txt 2013-10-04 14:35:08 UTC (rev 1750) @@ -1,5 +1,5 @@ --------------------------- -version 1.3.10a +version 1.3.10b revision 1748 on SVN --------------------------- Modified: trunk/src/jason/asSyntax/VarTerm.java =================================================================== --- trunk/src/jason/asSyntax/VarTerm.java 2013-09-16 12:56:58 UTC (rev 1749) +++ trunk/src/jason/asSyntax/VarTerm.java 2013-10-04 14:35:08 UTC (rev 1750) @@ -137,8 +137,9 @@ // +!p[a,b] // Answer: use annots of var, useful for meta-programming like // P[step(N)] - if (vl.isPred() && this.hasAnnot()) // if this var has annots, add them in the value's annots (Experimental) - ((Pred)vl).addAnnots(this.getAnnots()); + if (vl.isLiteral() && this.hasAnnot()) { // if this var has annots, add them in the value's annots (Experimental) + vl = ((Literal)vl).forceFullLiteralImpl().addAnnots(this.getAnnots()); + } value = vl; resetHashCodeCache(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-09-16 12:57:00
|
Revision: 1749 http://sourceforge.net/p/jason/svn/1749 Author: jomifred Date: 2013-09-16 12:56:58 +0000 (Mon, 16 Sep 2013) Log Message: ----------- include test for bug detected by Francisco Grimaldo (related to lists) Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java trunk/build.xml trunk/examples/st-claus/jason_stclaus.mas2j trunk/examples/st-claus/secretary.asl trunk/examples/st-claus/worker.asl trunk/release-notes.txt Modified: trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java 2013-09-09 00:53:39 UTC (rev 1748) +++ trunk/applications/as-unit-test/src/jason/tests/BugListReturnUnification.java 2013-09-16 12:56:58 UTC (rev 1749) @@ -26,7 +26,24 @@ "+!test3 <- !a(Y)[x(Z), y]; jason.asunit.print(Y, Z). "+ "+!a(Y)[x(Z),kk] <- Y=3; Z=4. "+ - "+!a(Y)[x(Z),source(self)] <- Y=1; Z=2. " + "+!a(Y)[x(Z),source(self)] <- Y=1; Z=2. "+ + + "+!test4 <- X = [a,b,c]; !deleteb(X,Y); jason.asunit.print(Y)."+ + "+!test5 <- X = [a,b,c]; !deleteb2(X,Y); jason.asunit.print(Y)."+ + + "+!deleteb([], [])."+ + "+!deleteb([b|L1], L2)"+ + " <- !deleteb(L1, L2)."+ + "+!deleteb([H|L1], [H|L2])"+ + " <- !deleteb(L1, L2)."+ + + "+!deleteb2([], [])."+ + "+!deleteb2([b|L1], L2)"+ + " <- !deleteb2(L1, L2)."+ + "+!deleteb2([H|L1], R)"+ + " <- !deleteb2(L1, L2);"+ + " R = [H|L2]." + ); } @@ -43,4 +60,16 @@ ag.addGoal("test3"); ag.assertPrint("12", 10); } + + @Test(timeout=2000) + public void testDelete1() { + ag.addGoal("test4"); + ag.assertPrint("[a,c]", 10); + } + @Test(timeout=2000) + public void testDelete2() { + ag.addGoal("test5"); + ag.assertPrint("[a,c]", 10); + } + } Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2013-09-09 00:53:39 UTC (rev 1748) +++ trunk/build.xml 2013-09-16 12:56:58 UTC (rev 1749) @@ -12,7 +12,7 @@ <property name="dist.properties" value="${basedir}/bin/dist.properties" /> <property name="version" value="1" /> - <property name="release" value="3.10" /> + <property name="release" value="3.10a" /> <property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" /> <property name="distFile" value="${env.HOME}/Jason-${version}.${release}" /> Modified: trunk/examples/st-claus/jason_stclaus.mas2j =================================================================== --- trunk/examples/st-claus/jason_stclaus.mas2j 2013-09-09 00:53:39 UTC (rev 1748) +++ trunk/examples/st-claus/jason_stclaus.mas2j 2013-09-16 12:56:58 UTC (rev 1749) @@ -28,13 +28,13 @@ MAS jason_stclaus { - infrastructure: Centralised + infrastructure: Centralised - agents: - santa; - edna secretary.asl [beliefs="group_size(3,elf)"]; + agents: + santa; + edna secretary.asl [beliefs="group_size(3,elf)"]; robin secretary.asl [beliefs="group_size(9,reindeer)"]; - elf worker.asl [beliefs="kind(elf), secretary(edna)"] #10; + elf worker.asl [beliefs="kind(elf), secretary(edna)"] #10; reindeer worker.asl [beliefs="kind(reindeer), secretary(robin)"] #9; -} \ No newline at end of file +} Modified: trunk/examples/st-claus/secretary.asl =================================================================== --- trunk/examples/st-claus/secretary.asl 2013-09-09 00:53:39 UTC (rev 1748) +++ trunk/examples/st-claus/secretary.asl 2013-09-16 12:56:58 UTC (rev 1749) @@ -9,4 +9,4 @@ @liam2[atomic] +!iamhere[source(A)] : group(Group) <- -+group([A|Group]). - \ No newline at end of file + Modified: trunk/examples/st-claus/worker.asl =================================================================== --- trunk/examples/st-claus/worker.asl 2013-09-09 00:53:39 UTC (rev 1748) +++ trunk/examples/st-claus/worker.asl 2013-09-16 12:56:58 UTC (rev 1749) @@ -9,4 +9,4 @@ <- .print(M); .send(A,tell,done); .wait( math.random(20)+10 ); - !!start. \ No newline at end of file + !!start. Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-09-09 00:53:39 UTC (rev 1748) +++ trunk/release-notes.txt 2013-09-16 12:56:58 UTC (rev 1749) @@ -1,7 +1,7 @@ --------------------------- -version 1.3.10 +version 1.3.10a -revision 1745 on SVN +revision 1748 on SVN --------------------------- New features @@ -14,6 +14,12 @@ The intention will be suspended until the agent believes b(X) with X > 10. Timeout and elapse time arguments can be used as previously. + +New example: +- Santa Claus: a classical benchmark for concurrent programming + http://www.cs.otago.ac.nz/staffpriv/ok/santa + + --------------------------- version 1.3.9 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-09-09 00:53:43
|
Revision: 1748 http://sourceforge.net/p/jason/svn/1748 Author: jomifred Date: 2013-09-09 00:53:39 +0000 (Mon, 09 Sep 2013) Log Message: ----------- unification changed to deal with negated variables Modified Paths: -------------- trunk/applications/as-unit-test/src/jason/tests/TestAll.java trunk/release-notes.txt trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSemantics/Unifier.java trunk/src/jason/asSyntax/VarTerm.java trunk/src/jason/stdlib/create_agent.java trunk/src/test/ASParserTest.java trunk/src/test/VarTermTest.java Added Paths: ----------- trunk/applications/as-unit-test/src/jason/tests/TestNegatedVar.java Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -25,6 +25,7 @@ TestPlanFailure.class, TestVarInContext.class, TestUnnamedVar.class, - TestCopyTerm.class + TestCopyTerm.class, + TestNegatedVar.class }) public class TestAll { } Added: trunk/applications/as-unit-test/src/jason/tests/TestNegatedVar.java =================================================================== --- trunk/applications/as-unit-test/src/jason/tests/TestNegatedVar.java (rev 0) +++ trunk/applications/as-unit-test/src/jason/tests/TestNegatedVar.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -0,0 +1,32 @@ +package jason.tests; + +import jason.asunit.TestAgent; + +import org.junit.Before; +import org.junit.Test; + +public class TestNegatedVar { + + TestAgent ag; + + // initialisation of the agent test + @Before + public void setupAg() { + ag = new TestAgent(); + ag.setDebugMode(true); + + // defines the agent's AgentSpeak code + ag.parseAScode( + "+!start <- +b. " + + "+B <- !~B. " + + "+!X <- jason.asunit.print(X)." + ); + } + + @Test(timeout=2000) + public void testContext() { + ag.addGoal("start"); + ag.assertPrint("~b[source(self)]", 5); + } + +} Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/release-notes.txt 2013-09-09 00:53:39 UTC (rev 1748) @@ -11,7 +11,7 @@ - the internal action .wait accepts a logical expression as argument, as in ...; .wait(b(X) & X > 10); .... - The intention will be suspended until the agent belief b(X) with X > 10. + The intention will be suspended until the agent believes b(X) with X > 10. Timeout and elapse time arguments can be used as previously. --------------------------- Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -580,31 +580,36 @@ Term bTerm = h.getBodyTerm(); // de-var bTerm - while (bTerm instanceof VarTerm) { + //while (bTerm instanceof VarTerm) { + if (bTerm instanceof VarTerm) { // check if bTerm is ground - //if (bTerm.isGround()) { - if (((VarTerm)bTerm).hasValue()) { + /*if (((VarTerm)bTerm).hasValue()) { bTerm = ((VarTerm)bTerm).getValue(); continue; // restart the loop - } + }*/ // h should be 'groundable' (considering the current unifier) - Term bValue = u.get((VarTerm)bTerm); + bTerm = bTerm.clone(); // clone before apply + bTerm.apply(u); + //Term bValue = u.get((VarTerm)bTerm); //System.out.println("*** "+bTerm+"="+bValue+" "+bTerm.isGround()+" "+u); - if (bValue == null) { // the case of !A with A not ground + //if (bValue == null) { // the case of !A with A not ground + if (bTerm.isVar()) { // 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_without_value", msg))) logger.log(Level.SEVERE, msg); return; } - if (bValue.isPlanBody()) { + //if (bValue.isPlanBody()) { + if (bTerm.isPlanBody()) { if (h.getBodyType() != BodyType.action) { // the case of ...; A = { !g }; +g; .... - String msg = h.getSrcInfo()+": "+ "The operator '"+h.getBodyType()+"' is lost with the variable '"+bTerm+"' unified with a plan body '"+bValue+"'. "; + String msg = h.getSrcInfo()+": "+ "The operator '"+h.getBodyType()+"' is lost with the variable '"+bTerm+"' unified with a plan body. "; if (!generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("body_var_with_op", msg))) logger.log(Level.SEVERE, msg); return; } - h = (PlanBody)bValue; + //h = (PlanBody)bValue; + h = (PlanBody)bTerm; if (h.getPlanSize() > 1) { // the case of A unified with {a;b;c} h.add(im.getCurrentStep().getBodyNext()); im.insertAsNextStep(h.getBodyNext()); @@ -612,7 +617,7 @@ bTerm = h.getBodyTerm(); } else { ListTerm annots = ((VarTerm)bTerm).getAnnots(); - bTerm = bValue; + //bTerm = bValue; if (bTerm.isLiteral() && annots != null) { bTerm = ((Literal)bTerm).forceFullLiteralImpl(); ((Literal)bTerm).addAnnots(annots); Modified: trunk/src/jason/asSemantics/Unifier.java =================================================================== --- trunk/src/jason/asSemantics/Unifier.java 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/src/jason/asSemantics/Unifier.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -89,6 +89,18 @@ if (vl != null && vl.isVar()) { // optimised deref return get((VarTerm)vl); } + if (vl == null) { // try negated value of the var + //System.out.println("for "+vtp+" try "+new VarTerm(vtp.negated(), vtp.getFunctor())+" in "+this); + vl = function.get( new VarTerm(vtp.negated(), vtp.getFunctor()) ); + //System.out.println(" and found "+vl); + if (vl != null && vl.isVar()) { + vl = get((VarTerm)vl); + } + if (vl != null && vl.isLiteral()) { + vl = vl.clone(); + ((Literal)vl).setNegated(((Literal)vl).negated()); + } + } return vl; } @@ -233,21 +245,20 @@ final VarTerm t2gv = t2gisvar ? deref((VarTerm)t2g) : null; // get their values - final Term t1vl = t1gisvar ? function.get(t1gv) : t1g; - final Term t2vl = t2gisvar ? function.get(t2gv) : t2g; + //final Term t1vl = t1gisvar ? function.get(t1gv) : t1g; + //final Term t2vl = t2gisvar ? function.get(t2gv) : t2g; + final Term t1vl = t1gisvar ? get(t1gv) : t1g; + final Term t2vl = t2gisvar ? get(t2gv) : t2g; - if (t1vl != null && t2vl != null) { - // unifies the two values of the vars + if (t1vl != null && t2vl != null) { // unifies the two values of the vars return unifiesNoUndo(t1vl, t2vl); - } else if (t1vl != null) { - bind(t2gv, t1vl); + } else if (t1vl != null) { // unifies var with value + return bind(t2gv, t1vl); } else if (t2vl != null) { - bind(t1gv, t2vl); - } else { //if (t1gv != null && t2gv != null) { - // unify two vars - bind(t1gv, t2gv); + return bind(t1gv, t2vl); + } else { // unify two vars + return bind(t1gv, t2gv); } - return true; } // both terms are not vars @@ -307,23 +318,43 @@ return v; } - - - public void bind(VarTerm vt1, VarTerm vt2) { + public boolean bind(VarTerm vt1, VarTerm vt2) { + if (vt1.negated() && vt2.negated()) { // in the case of ~A = ~B, put A=B in the unifier + vt1 = new VarTerm(vt1.getFunctor()); + vt2 = new VarTerm(vt2.getFunctor()); + } + final int comp = vt1.compareTo(vt2); if (comp < 0) { - function.put((VarTerm)vt1.clone(), vt2); + function.put((VarTerm)vt1.clone(), vt2.clone()); } else if (comp > 0){ - function.put((VarTerm)vt2.clone(), vt1); + function.put((VarTerm)vt2.clone(), vt1.clone()); } // if they are the same (comp == 0), do not bind + return true; } - public void bind(VarTerm vt, Term vl) { + public boolean bind(VarTerm vt, Term vl) { + if (vt.negated()) { // negated vars unifies only with negated literals + if (vl.isLiteral()) { + if (!((Literal)vl).negated()) { + return false; + } else { + // put also the positive case in the unifier + Literal vlp = (Literal)vl.clone(); + vlp.setNegated(Literal.LPos); + unifies(new VarTerm(vt.getFunctor()), vlp); + } + } else { + return false; + } + } + if (!vl.isCyclicTerm() && vl.hasVar(vt, this)) { vl = new CyclicTerm((Literal)vl, (VarTerm)vt.clone()); - //System.out.println("changing "+vt+" <- "+vl+" in "+this); } + function.put((VarTerm) vt.clone(), vl); + return true; } public void clear() { Modified: trunk/src/jason/asSyntax/VarTerm.java =================================================================== --- trunk/src/jason/asSyntax/VarTerm.java 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/src/jason/asSyntax/VarTerm.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -65,6 +65,9 @@ e.printStackTrace(); } } + public VarTerm(boolean negated, String s) { + super(negated, s); + } /** @deprecated prefer ASSyntax.parseVar(...) */ public static VarTerm parseVar(String sVar) { @@ -83,6 +86,7 @@ } else { // do not call constructor with term parameter! VarTerm t = new VarTerm(super.getFunctor()); + t.setNegated(!negated()); t.srcInfo = this.srcInfo; if (hasAnnot()) t.setAnnots(getAnnots().cloneLT()); @@ -135,7 +139,7 @@ // P[step(N)] if (vl.isPred() && this.hasAnnot()) // if this var has annots, add them in the value's annots (Experimental) ((Pred)vl).addAnnots(this.getAnnots()); - + value = vl; resetHashCodeCache(); return true; @@ -148,8 +152,7 @@ public boolean apply(Unifier u) { if (value == null) { - Term vl = u.get(this); - //System.out.println("applying "+this+"="+vl+" un="+u); + Term vl = u.get(this); if (vl != null) { if (!vl.isCyclicTerm() && vl.hasVar(this, u)) { //logger.warning("The value of a variable contains itself, variable "+super.getFunctor()+" "+super.getSrcInfo()+", value="+vl+", unifier="+u); @@ -200,7 +203,7 @@ if (t instanceof VarTerm) { final VarTerm tAsVT = (VarTerm) t; if (tAsVT.getValue() == null) { - return getFunctor().equals(((VarTerm)t).getFunctor()); + return negated() == ((VarTerm)t).negated() && getFunctor().equals(((VarTerm)t).getFunctor()); } } } @@ -212,10 +215,14 @@ return value.compareTo(t); else if (t == null || t.isUnnamedVar()) return -1; - else if (t.isVar()) - return getFunctor().compareTo(((VarTerm)t).getFunctor()); - else - return 1; + else if (t.isVar()) { + if (!negated() && ((VarTerm)t).negated()) + return -1; + else + return getFunctor().compareTo(((VarTerm)t).getFunctor()); + } else { + return 1; + } } @Override @@ -476,9 +483,10 @@ public String toString() { if (value == null) { String s = getFunctor(); - if (hasAnnot()) { + if (hasAnnot()) s += getAnnots(); - } + if (negated()) + s = "~" + s; return s; } else { return value.toString(); @@ -668,7 +676,10 @@ @Override public boolean negated() { - return value != null && getValue().isLiteral() && ((Literal) getValue()).negated(); + if (value == null) + return super.negated(); + else + return getValue().isLiteral() && ((Literal) getValue()).negated(); } @Override Modified: trunk/src/jason/stdlib/create_agent.java =================================================================== --- trunk/src/jason/stdlib/create_agent.java 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/src/jason/stdlib/create_agent.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -28,23 +28,17 @@ import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; import jason.asSyntax.ListTerm; -import jason.asSyntax.SourceInfo; import jason.asSyntax.StringTerm; import jason.asSyntax.StringTermImpl; import jason.asSyntax.Structure; import jason.asSyntax.Term; -import jason.asSyntax.VarTerm; import jason.mas2j.ClassParameters; import jason.runtime.RuntimeServicesInfraTier; import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - /** <p>Internal action: <b><code>.create_agent</code></b>. Modified: trunk/src/test/ASParserTest.java =================================================================== --- trunk/src/test/ASParserTest.java 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/src/test/ASParserTest.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -40,6 +40,18 @@ super.setUp(); } + public void testNegVar() throws ParseException { + Literal l = ASSyntax.parseLiteral("~B"); + assertTrue(l.isVar()); + assertTrue(l.negated()); + l = (Literal)l.clone(); + assertTrue(l.isVar()); + assertTrue(l.negated()); + Literal l1 = ASSyntax.parseLiteral("~B"); + Literal l2 = ASSyntax.parseLiteral("B"); + assertFalse(l1.equals(l2)); + } + public void testKQML() { Agent ag = new Agent(); ag.initAg(); Modified: trunk/src/test/VarTermTest.java =================================================================== --- trunk/src/test/VarTermTest.java 2013-09-09 00:51:53 UTC (rev 1747) +++ trunk/src/test/VarTermTest.java 2013-09-09 00:53:39 UTC (rev 1748) @@ -5,6 +5,7 @@ import jason.asSemantics.Unifier; import jason.asSyntax.ASSyntax; import jason.asSyntax.ArithExpr; +import jason.asSyntax.ArithExpr.ArithmeticOp; import jason.asSyntax.Atom; import jason.asSyntax.ListTerm; import jason.asSyntax.ListTermImpl; @@ -18,7 +19,6 @@ import jason.asSyntax.Term; import jason.asSyntax.UnnamedVar; import jason.asSyntax.VarTerm; -import jason.asSyntax.ArithExpr.ArithmeticOp; import jason.asSyntax.parser.ParseException; import jason.asSyntax.parser.SimpleCharStream; import jason.asSyntax.parser.Token; @@ -561,4 +561,107 @@ assertTrue(X.compareTo(new NumberTermImpl(1)) > 0); assertTrue(new NumberTermImpl(1).compareTo(X) < 0); } + + public void testUnifyNegVar() throws ParseException { + Literal l1 = ASSyntax.parseLiteral("~B"); + Literal l2 = ASSyntax.parseLiteral("~p(1)"); + Unifier u = new Unifier(); + assertTrue(u.unifies(l1, l2)); // ~B = ~p(1) + assertEquals(u.get((VarTerm)l1).toString(),"~p(1)"); + l1.apply(u); // apply in ~B should result in ~p(1) + assertEquals(l1.toString(),"~p(1)"); + + VarTerm b = new VarTerm("B"); + b.apply(u); + assertEquals(b.toString(),"p(1)"); + + l1 = ASSyntax.parseLiteral("~B"); + l2 = ASSyntax.parseLiteral("p(1)"); + u = new Unifier(); + assertFalse(u.unifies(l1, l2)); + + assertFalse(u.unifies(l1, ASSyntax.parseTerm("10"))); + + l1 = ASSyntax.parseLiteral("B"); + l2 = ASSyntax.parseLiteral("~p(1)"); + u = new Unifier(); + assertTrue(u.unifies(l1, l2)); + assertEquals(u.get("B").toString(),"~p(1)"); + l1.apply(u); + assertEquals(l1.toString(),"~p(1)"); + + l1 = ASSyntax.parseLiteral("~B"); + l2 = ASSyntax.parseLiteral("~A"); + u = new Unifier(); + assertTrue(u.unifies(l1, l2)); + // if A = p(10), apply in ~B should be ~p(10). + VarTerm va = new VarTerm("A"); + u.unifies(va,ASSyntax.parseLiteral("p(10)")); + va.apply(u); + assertEquals(va.toString(),"p(10)"); + l1.apply(u); + assertEquals(l1.toString(),"~p(10)"); + l2.apply(u); + assertEquals(l2.toString(),"~p(10)"); + + l1 = ASSyntax.parseLiteral("~B"); + l2 = ASSyntax.parseLiteral("~A"); + u = new Unifier(); + assertTrue(u.unifies(l1, l2)); // A = B + // if ~A = ~p(10), apply in B should be p(10). + assertTrue(u.unifies(l2, ASSyntax.parseLiteral("~p(10)"))); + l2.apply(u); + assertEquals(l2.toString(),"~p(10)"); + l1.apply(u); + assertEquals(l1.toString(),"~p(10)"); // ~B is ~p(10) + VarTerm vb = new VarTerm("B"); + vb.apply(u); + assertEquals(vb.toString(),"p(10)"); // B is p(10) + + u = new Unifier(); + u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("p(10)")); + u.unifies(new VarTerm("B"),ASSyntax.parseLiteral("~p(10)")); + assertFalse(u.unifies(new VarTerm("A"), new VarTerm("B"))); + l1 = ASSyntax.parseLiteral("~B"); + l2 = ASSyntax.parseLiteral("~A"); + assertFalse(u.unifies(l1, l2)); + + u = new Unifier(); + u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("p(10)")); + assertFalse(u.unifies(new VarTerm(Literal.LNeg,"B"),new VarTerm("A"))); + + u = new Unifier(); + u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("~p(10)")); + vb = new VarTerm(Literal.LNeg,"B"); + assertTrue(u.unifies(vb,new VarTerm("A"))); + vb.apply(u); + assertEquals(vb.toString(),"~p(10)"); + + u = new Unifier(); + u.unifies(new VarTerm("A"),ASSyntax.parseLiteral("~p(10)")); + vb = new VarTerm(Literal.LNeg,"B"); + assertTrue(u.unifies(vb,new VarTerm("A"))); + vb = new VarTerm("B"); + vb.apply(u); + assertEquals(vb.toString(),"p(10)"); + + // B = ~A + // A = p(10) + // => apply B is ~p(10) + // apply A is p(10) + // apply ~A is ~p(10) + l1 = ASSyntax.parseLiteral("B"); + l2 = ASSyntax.parseLiteral("~A"); + u = new Unifier(); + assertTrue(u.unifies(l1, l2)); + va = new VarTerm("A"); + u.unifies(va,ASSyntax.parseLiteral("p(10)")); + va.apply(u); + assertEquals(va.toString(),"p(10)"); + l1.apply(u); + assertEquals(l1.toString(),"~p(10)"); + l2.apply(u); + assertEquals(l2.toString(),"~p(10)"); + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-09-09 00:51:55
|
Revision: 1747 http://sourceforge.net/p/jason/svn/1747 Author: jomifred Date: 2013-09-09 00:51:53 +0000 (Mon, 09 Sep 2013) Log Message: ----------- parser changed to accept ~VAR Modified Paths: -------------- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc trunk/src/jason/asSyntax/parser/as2j.java Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc =================================================================== --- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2013-09-02 18:57:16 UTC (rev 1746) +++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2013-09-09 00:51:53 UTC (rev 1747) @@ -275,7 +275,10 @@ /* Beliefs & Rules */ Literal belief() : { Literal h; Object t; } { - h=literal() + h=literal() { if (h.isVar()) { + throw new ParseException(getSourceRef(h)+" variables cannot be beliefs!"); + } + } [ ":-" t = log_expr() { h = new Rule(h,(LogicalFormula)t); // warning only not parsed files @@ -294,7 +297,11 @@ /* Initial goals */ Literal initial_goal() : { Literal g; } { - "!" g=literal() "." { return g; } + "!" g=literal() "." { if (g.isVar()) { + throw new ParseException(getSourceRef(g)+". a variable cannot be a goal!"); + } + return g; + } } @@ -342,9 +349,7 @@ ) ] - ( F=literal() - | F=var() - ) { return new Trigger(teOp,teType,F); } + F=literal() { return new Trigger(teOp,teType,F); } } @@ -539,7 +544,7 @@ { ( ( [ <TK_NEG> { type = Literal.LNeg; } ] - F=pred() { + (F=pred() { if (F.getFunctor().indexOf(".") >= 0) { if (F.hasAnnot()) throw new ParseException(getSourceRef(F)+" Internal actions cannot have annotations."); @@ -554,6 +559,12 @@ } return new LiteralImpl(type,F); } + | F = var() { + VarTerm vt = (VarTerm)F; + vt.setNegated(type); + return vt; + } + ) ) | k=<TK_TRUE> { return Literal.LTrue; } | k=<TK_FALSE> { return Literal.LFalse; } @@ -781,7 +792,6 @@ return new ArithExpr(ArithmeticOp.plus, (NumberTerm)t); } | "(" t = log_expr() ")" { return t; } - | v = var() { return v; } | t = function() { return t; } ) } Modified: trunk/src/jason/asSyntax/parser/as2j.java =================================================================== --- trunk/src/jason/asSyntax/parser/as2j.java 2013-09-02 18:57:16 UTC (rev 1746) +++ trunk/src/jason/asSyntax/parser/as2j.java 2013-09-09 00:51:53 UTC (rev 1747) @@ -114,12 +114,14 @@ label_2: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case VAR: case TK_TRUE: case TK_FALSE: case TK_NEG: case TK_BEGIN: case TK_END: case ATOM: + case UNNAMEDVAR: ; break; default: @@ -195,12 +197,14 @@ label_7: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case VAR: case TK_TRUE: case TK_FALSE: case TK_NEG: case TK_BEGIN: case TK_END: case ATOM: + case UNNAMEDVAR: ; break; default: @@ -289,6 +293,9 @@ final public Literal belief() throws ParseException { Literal h; Object t; h = literal(); + if (h.isVar()) { + {if (true) throw new ParseException(getSourceRef(h)+" variables cannot be beliefs!");} + } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 32: jj_consume_token(32); @@ -317,6 +324,9 @@ jj_consume_token(34); g = literal(); jj_consume_token(33); + if (g.isVar()) { + {if (true) throw new ParseException(getSourceRef(g)+". a variable cannot be a goal!");} + } {if (true) return g;} throw new Error("Missing return statement in function"); } @@ -420,24 +430,7 @@ jj_la1[15] = jj_gen; ; } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case TK_TRUE: - case TK_FALSE: - case TK_NEG: - case TK_BEGIN: - case TK_END: - case ATOM: - F = literal(); - break; - case VAR: - case UNNAMEDVAR: - F = var(); - break; - default: - jj_la1[16] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } + F = literal(); {if (true) return new Trigger(teOp,teType,F);} throw new Error("Missing return statement in function"); } @@ -476,7 +469,7 @@ isControl = false; if (!(F instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!");} break; default: - jj_la1[17] = jj_gen; + jj_la1[16] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -486,7 +479,7 @@ hasPV = true; break; default: - jj_la1[18] = jj_gen; + jj_la1[17] = jj_gen; ; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -513,7 +506,7 @@ R = plan_body(); break; default: - jj_la1[19] = jj_gen; + jj_la1[18] = jj_gen; ; } if (R != null) { @@ -543,13 +536,13 @@ useElse = true; break; default: - jj_la1[20] = jj_gen; + jj_la1[19] = jj_gen; ; } T2 = plan_term(); break; default: - jj_la1[21] = jj_gen; + jj_la1[20] = jj_gen; ; } try { @@ -646,13 +639,13 @@ formType = BodyType.addBelEnd; break; default: - jj_la1[22] = jj_gen; + jj_la1[21] = jj_gen; jj_consume_token(-1); throw new ParseException(); } break; default: - jj_la1[23] = jj_gen; + jj_la1[22] = jj_gen; ; } break; @@ -665,18 +658,18 @@ formType = BodyType.delAddBel; break; default: - jj_la1[24] = jj_gen; + jj_la1[23] = jj_gen; ; } break; default: - jj_la1[25] = jj_gen; + jj_la1[24] = jj_gen; jj_consume_token(-1); throw new ParseException(); } break; default: - jj_la1[26] = jj_gen; + jj_la1[25] = jj_gen; ; } B = log_expr(); @@ -710,7 +703,7 @@ pb = false; break; default: - jj_la1[27] = jj_gen; + jj_la1[26] = jj_gen; ; } T = trigger(); @@ -722,7 +715,7 @@ pb = false; break; default: - jj_la1[28] = jj_gen; + jj_la1[27] = jj_gen; ; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -738,13 +731,13 @@ if (!pb) {if (true) throw new ParseException(getSourceRef(T)+" Wrong place for ';'");} break; default: - jj_la1[29] = jj_gen; + jj_la1[28] = jj_gen; jj_consume_token(-1); throw new ParseException(); } break; default: - jj_la1[30] = jj_gen; + jj_la1[29] = jj_gen; ; } } else { @@ -774,7 +767,7 @@ B = plan_body(); break; default: - jj_la1[31] = jj_gen; + jj_la1[30] = jj_gen; ; } jj_consume_token(31); @@ -817,20 +810,26 @@ final public Literal literal() throws ParseException { Pred F; Token k; boolean type = Literal.LPos; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case VAR: case TK_NEG: case TK_BEGIN: case TK_END: case ATOM: + case UNNAMEDVAR: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case TK_NEG: jj_consume_token(TK_NEG); type = Literal.LNeg; break; default: - jj_la1[32] = jj_gen; + jj_la1[31] = jj_gen; ; } - F = pred(); + switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case TK_BEGIN: + case TK_END: + case ATOM: + F = pred(); if (F.getFunctor().indexOf(".") >= 0) { if (F.hasAnnot()) {if (true) throw new ParseException(getSourceRef(F)+" Internal actions cannot have annotations.");} @@ -844,6 +843,19 @@ } } {if (true) return new LiteralImpl(type,F);} + break; + case VAR: + case UNNAMEDVAR: + F = var(); + VarTerm vt = (VarTerm)F; + vt.setNegated(type); + {if (true) return vt;} + break; + default: + jj_la1[32] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } break; case TK_TRUE: k = jj_consume_token(TK_TRUE); @@ -1426,16 +1438,13 @@ {if (true) return t;} break; case VAR: - case UNNAMEDVAR: - v = var(); - {if (true) return v;} - break; case TK_TRUE: case TK_FALSE: case TK_NEG: case TK_BEGIN: case TK_END: case ATOM: + case UNNAMEDVAR: t = function(); {if (true) return t;} break; @@ -1515,125 +1524,93 @@ finally { jj_save(1, xla); } } - final private boolean jj_3R_14() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(23)) { - jj_scanpos = xsp; - if (jj_scan_token(14)) { - jj_scanpos = xsp; - if (jj_scan_token(15)) return true; - } - } - xsp = jj_scanpos; - if (jj_3R_20()) jj_scanpos = xsp; - while (true) { - xsp = jj_scanpos; - if (jj_3R_21()) { jj_scanpos = xsp; break; } - } - xsp = jj_scanpos; - if (jj_3R_22()) jj_scanpos = xsp; + final private boolean jj_3R_54() { + if (jj_3R_61()) return true; return false; } - final private boolean jj_3R_91() { - if (jj_3R_92()) return true; + final private boolean jj_3R_67() { + if (jj_3R_79()) return true; return false; } - final private boolean jj_3R_54() { - if (jj_scan_token(TK_FALSE)) return true; + final private boolean jj_3R_85() { + if (jj_3R_91()) return true; return false; } - final private boolean jj_3R_53() { - if (jj_scan_token(TK_TRUE)) return true; + final private boolean jj_3R_66() { + if (jj_3R_78()) return true; return false; } - final private boolean jj_3R_70() { - if (jj_3R_79()) return true; + final private boolean jj_3R_53() { + if (jj_3R_14()) return true; return false; } - final private boolean jj_3R_69() { - if (jj_3R_78()) return true; - return false; - } - - final private boolean jj_3R_68() { + final private boolean jj_3R_65() { if (jj_3R_77()) return true; return false; } - final private boolean jj_3R_64() { + final private boolean jj_3R_52() { if (jj_scan_token(TK_NEG)) return true; return false; } - final private boolean jj_3R_67() { + final private boolean jj_3R_64() { if (jj_3R_76()) return true; return false; } - final private boolean jj_3R_62() { + final private boolean jj_3R_59() { Token xsp; xsp = jj_scanpos; - if (jj_3R_67()) { + if (jj_3R_64()) { jj_scanpos = xsp; - if (jj_3R_68()) { + if (jj_3R_65()) { jj_scanpos = xsp; - if (jj_3R_69()) { + if (jj_3R_66()) { jj_scanpos = xsp; - if (jj_3R_70()) return true; + if (jj_3R_67()) return true; } } } return false; } - final private boolean jj_3R_52() { + final private boolean jj_3R_44() { Token xsp; xsp = jj_scanpos; - if (jj_3R_64()) jj_scanpos = xsp; - if (jj_3R_14()) return true; + if (jj_3R_52()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_53()) { + jj_scanpos = xsp; + if (jj_3R_54()) return true; + } return false; } - final private boolean jj_3R_85() { - if (jj_3R_91()) return true; - return false; - } - - final private boolean jj_3R_45() { + final private boolean jj_3R_31() { Token xsp; xsp = jj_scanpos; - if (jj_3R_52()) { + if (jj_3R_44()) { jj_scanpos = xsp; - if (jj_3R_53()) { + if (jj_3R_45()) { jj_scanpos = xsp; - if (jj_3R_54()) return true; + if (jj_3R_46()) return true; } } return false; } - final private boolean jj_3R_32() { - if (jj_3R_46()) return true; - return false; - } - - final private boolean jj_3R_31() { - if (jj_3R_45()) return true; - return false; - } - - final private boolean jj_3R_44() { + final private boolean jj_3R_43() { if (jj_scan_token(40)) return true; return false; } - final private boolean jj_3R_43() { + final private boolean jj_3R_42() { if (jj_scan_token(34)) return true; return false; } @@ -1641,9 +1618,9 @@ final private boolean jj_3R_30() { Token xsp; xsp = jj_scanpos; - if (jj_3R_43()) { + if (jj_3R_42()) { jj_scanpos = xsp; - if (jj_3R_44()) return true; + if (jj_3R_43()) return true; } return false; } @@ -1663,6 +1640,11 @@ return false; } + final private boolean jj_3R_80() { + if (jj_3R_85()) return true; + return false; + } + final private boolean jj_3R_17() { Token xsp; xsp = jj_scanpos; @@ -1675,25 +1657,16 @@ } xsp = jj_scanpos; if (jj_3R_30()) jj_scanpos = xsp; - xsp = jj_scanpos; - if (jj_3R_31()) { - jj_scanpos = xsp; - if (jj_3R_32()) return true; - } + if (jj_3R_31()) return true; return false; } - final private boolean jj_3R_80() { - if (jj_3R_85()) return true; - return false; - } - final private boolean jj_3R_51() { if (jj_scan_token(TK_LABEL_AT)) return true; return false; } - final private boolean jj_3R_42() { + final private boolean jj_3R_41() { Token xsp; xsp = jj_scanpos; if (jj_3R_51()) jj_scanpos = xsp; @@ -1701,47 +1674,57 @@ return false; } + final private boolean jj_3R_83() { + if (jj_3R_81()) return true; + return false; + } + + final private boolean jj_3R_82() { + if (jj_3R_80()) return true; + return false; + } + final private boolean jj_3R_49() { - if (jj_3R_62()) return true; + if (jj_3R_59()) return true; return false; } - final private boolean jj_3R_35() { + final private boolean jj_3R_34() { if (jj_scan_token(41)) return true; return false; } - final private boolean jj_3R_34() { + final private boolean jj_3R_33() { if (jj_scan_token(36)) return true; return false; } - final private boolean jj_3R_83() { - if (jj_3R_81()) return true; + final private boolean jj_3R_75() { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_82()) { + jj_scanpos = xsp; + if (jj_3R_83()) return true; + } return false; } final private boolean jj_3R_19() { Token xsp; xsp = jj_scanpos; - if (jj_3R_34()) { + if (jj_3R_33()) { jj_scanpos = xsp; - if (jj_3R_35()) return true; + if (jj_3R_34()) return true; } return false; } final private boolean jj_3R_18() { if (jj_scan_token(35)) return true; - if (jj_3R_33()) return true; + if (jj_3R_32()) return true; return false; } - final private boolean jj_3R_82() { - if (jj_3R_80()) return true; - return false; - } - final private boolean jj_3R_16() { if (jj_scan_token(TK_LABEL_AT)) return true; if (jj_3R_14()) return true; @@ -1760,22 +1743,7 @@ return false; } - final private boolean jj_3R_75() { - Token xsp; - xsp = jj_scanpos; - if (jj_3R_82()) { - jj_scanpos = xsp; - if (jj_3R_83()) return true; - } - return false; - } - - final private boolean jj_3R_41() { - if (jj_scan_token(34)) return true; - return false; - } - - final private boolean jj_3R_37() { + final private boolean jj_3R_36() { if (jj_scan_token(30)) return true; Token xsp; xsp = jj_scanpos; @@ -1787,37 +1755,47 @@ } final private boolean jj_3R_40() { - if (jj_3R_45()) return true; + if (jj_scan_token(34)) return true; return false; } - final private boolean jj_3R_66() { + final private boolean jj_3R_63() { if (jj_3R_75()) return true; return false; } - final private boolean jj_3R_65() { + final private boolean jj_3R_62() { if (jj_scan_token(TK_NOT)) return true; return false; } - final private boolean jj_3R_58() { + final private boolean jj_3R_55() { Token xsp; xsp = jj_scanpos; - if (jj_3R_65()) { + if (jj_3R_62()) { jj_scanpos = xsp; - if (jj_3R_66()) return true; + if (jj_3R_63()) return true; } return false; } + final private boolean jj_3R_47() { + if (jj_3R_55()) return true; + return false; + } + + final private boolean jj_3R_39() { + if (jj_3R_31()) return true; + return false; + } + final private boolean jj_3R_90() { if (jj_scan_token(38)) return true; return false; } - final private boolean jj_3R_47() { - if (jj_3R_58()) return true; + final private boolean jj_3R_32() { + if (jj_3R_47()) return true; return false; } @@ -1836,11 +1814,6 @@ return false; } - final private boolean jj_3R_33() { - if (jj_3R_47()) return true; - return false; - } - final private boolean jj_3R_86() { if (jj_scan_token(34)) return true; return false; @@ -1865,106 +1838,106 @@ return false; } + final private boolean jj_3R_71() { + if (jj_3R_36()) return true; + return false; + } + final private boolean jj_3R_79() { Token xsp; xsp = jj_scanpos; if (jj_3R_84()) jj_scanpos = xsp; - if (jj_3R_33()) return true; + if (jj_3R_32()) return true; return false; } - final private boolean jj_3R_74() { - if (jj_3R_37()) return true; - return false; - } - - final private boolean jj_3R_73() { + final private boolean jj_3R_70() { if (jj_3R_81()) return true; return false; } - final private boolean jj_3R_72() { + final private boolean jj_3R_69() { if (jj_3R_80()) return true; return false; } - final private boolean jj_3_1() { - if (jj_scan_token(TK_BEGIN)) return true; - if (jj_3R_14()) return true; - if (jj_scan_token(31)) return true; - if (jj_3R_15()) return true; + final private boolean jj_3R_68() { + if (jj_3R_37()) return true; return false; } - final private boolean jj_3R_71() { - if (jj_3R_38()) return true; - return false; - } - - final private boolean jj_3R_63() { + final private boolean jj_3R_60() { Token xsp; xsp = jj_scanpos; - if (jj_3R_71()) { + if (jj_3R_68()) { jj_scanpos = xsp; - if (jj_3R_72()) { + if (jj_3R_69()) { jj_scanpos = xsp; - if (jj_3R_73()) { + if (jj_3R_70()) { jj_scanpos = xsp; - if (jj_3R_74()) return true; + if (jj_3R_71()) return true; } } } return false; } - final private boolean jj_3R_39() { - if (jj_scan_token(30)) return true; + final private boolean jj_3R_81() { + if (jj_scan_token(STRING)) return true; return false; } - final private boolean jj_3R_81() { - if (jj_scan_token(STRING)) return true; + final private boolean jj_3_1() { + if (jj_scan_token(TK_BEGIN)) return true; + if (jj_3R_14()) return true; + if (jj_scan_token(31)) return true; + if (jj_3R_15()) return true; return false; } - final private boolean jj_3R_57() { - if (jj_3R_38()) return true; + final private boolean jj_3R_74() { + if (jj_3R_37()) return true; return false; } - final private boolean jj_3R_78() { - if (jj_scan_token(TK_WHILE)) return true; + final private boolean jj_3R_38() { + if (jj_scan_token(30)) return true; return false; } - final private boolean jj_3R_56() { + final private boolean jj_3R_73() { if (jj_scan_token(UNNAMEDVAR)) return true; return false; } - final private boolean jj_3R_55() { + final private boolean jj_3R_72() { if (jj_scan_token(VAR)) return true; return false; } - final private boolean jj_3R_46() { + final private boolean jj_3R_78() { + if (jj_scan_token(TK_WHILE)) return true; + return false; + } + + final private boolean jj_3R_50() { + if (jj_3R_60()) return true; + return false; + } + + final private boolean jj_3R_61() { Token xsp; xsp = jj_scanpos; - if (jj_3R_55()) { + if (jj_3R_72()) { jj_scanpos = xsp; - if (jj_3R_56()) return true; + if (jj_3R_73()) return true; } xsp = jj_scanpos; - if (jj_3R_57()) jj_scanpos = xsp; + if (jj_3R_74()) jj_scanpos = xsp; return false; } - final private boolean jj_3R_50() { - if (jj_3R_63()) return true; - return false; - } - - final private boolean jj_3R_38() { + final private boolean jj_3R_37() { if (jj_scan_token(48)) return true; Token xsp; xsp = jj_scanpos; @@ -1973,51 +1946,46 @@ return false; } - final private boolean jj_3R_61() { - if (jj_3R_33()) return true; + final private boolean jj_3R_58() { + if (jj_3R_32()) return true; return false; } - final private boolean jj_3R_60() { - if (jj_3R_37()) return true; + final private boolean jj_3R_57() { + if (jj_3R_36()) return true; return false; } - final private boolean jj_3R_59() { - if (jj_3R_38()) return true; + final private boolean jj_3R_56() { + if (jj_3R_37()) return true; return false; } - final private boolean jj_3R_77() { - if (jj_scan_token(TK_FOR)) return true; - return false; - } - final private boolean jj_3R_48() { Token xsp; xsp = jj_scanpos; - if (jj_3R_59()) { + if (jj_3R_56()) { jj_scanpos = xsp; - if (jj_3R_60()) { + if (jj_3R_57()) { jj_scanpos = xsp; - if (jj_3R_61()) return true; + if (jj_3R_58()) return true; } } return false; } - final private boolean jj_3R_99() { - if (jj_3R_45()) return true; + final private boolean jj_3R_98() { + if (jj_3R_31()) return true; return false; } - final private boolean jj_3R_98() { - if (jj_3R_99()) return true; + final private boolean jj_3R_77() { + if (jj_scan_token(TK_FOR)) return true; return false; } final private boolean jj_3R_97() { - if (jj_3R_46()) return true; + if (jj_3R_98()) return true; return false; } @@ -2026,7 +1994,7 @@ return false; } - final private boolean jj_3R_36() { + final private boolean jj_3R_35() { if (jj_3R_48()) return true; return false; } @@ -2036,13 +2004,8 @@ return false; } - final private boolean jj_3R_26() { - if (jj_3R_42()) return true; - return false; - } - final private boolean jj_3R_22() { - if (jj_3R_38()) return true; + if (jj_3R_37()) return true; return false; } @@ -2052,15 +2015,10 @@ } final private boolean jj_3R_21() { - if (jj_3R_37()) return true; + if (jj_3R_36()) return true; return false; } - final private boolean jj_3R_25() { - if (jj_3R_41()) return true; - return false; - } - final private boolean jj_3R_93() { if (jj_scan_token(NUMBER)) return true; return false; @@ -2068,7 +2026,7 @@ final private boolean jj_3R_20() { if (jj_scan_token(42)) return true; - if (jj_3R_36()) return true; + if (jj_3R_35()) return true; return false; } @@ -2083,18 +2041,20 @@ jj_scanpos = xsp; if (jj_3R_96()) { jj_scanpos = xsp; - if (jj_3R_97()) { - jj_scanpos = xsp; - if (jj_3R_98()) return true; + if (jj_3R_97()) return true; } } } } - } return false; } - final private boolean jj_3R_24() { + final private boolean jj_3R_26() { + if (jj_3R_41()) return true; + return false; + } + + final private boolean jj_3R_25() { if (jj_3R_40()) return true; return false; } @@ -2104,11 +2064,47 @@ return false; } - final private boolean jj_3R_23() { + final private boolean jj_3R_14() { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(23)) { + jj_scanpos = xsp; + if (jj_scan_token(14)) { + jj_scanpos = xsp; + if (jj_scan_token(15)) return true; + } + } + xsp = jj_scanpos; + if (jj_3R_20()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_21()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_22()) jj_scanpos = xsp; + return false; + } + + final private boolean jj_3R_24() { if (jj_3R_39()) return true; return false; } + final private boolean jj_3R_23() { + if (jj_3R_38()) return true; + return false; + } + + final private boolean jj_3R_91() { + if (jj_3R_92()) return true; + return false; + } + + final private boolean jj_3R_46() { + if (jj_scan_token(TK_FALSE)) return true; + return false; + } + final private boolean jj_3R_15() { Token xsp; while (true) { @@ -2131,6 +2127,11 @@ return false; } + final private boolean jj_3R_45() { + if (jj_scan_token(TK_TRUE)) return true; + return false; + } + public as2jTokenManager token_source; SimpleCharStream jj_input_stream; public Token token, jj_nt; @@ -2148,10 +2149,10 @@ jj_la1_1(); } private static void jj_la1_0() { - jj_la1_0 = new int[] {0x40000000,0x80cb00,0x40000000,0x0,0x40000000,0x10000,0x80cb00,0x40000000,0x80c000,0x0,0x10000,0x0,0x0,0x0,0x0,0x0,0x180cb80,0x1facf80,0x0,0x1facf80,0x40000,0x40040000,0x0,0x0,0x0,0x0,0x0,0x10000,0x0,0x0,0x0,0x1facf80,0x800,0x80cb00,0x80c000,0x0,0x40000000,0x0,0x0,0x41e0cf80,0x0,0x1000080,0x0,0x41e0cb80,0x41e0cb80,0x0,0x0,0x1e0cf80,0x1e0cb80,0x0,0x41e0cb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x1a0cb80,0x1000080,0x0,}; + jj_la1_0 = new int[] {0x40000000,0x180cb80,0x40000000,0x0,0x40000000,0x10000,0x180cb80,0x40000000,0x80c000,0x0,0x10000,0x0,0x0,0x0,0x0,0x0,0x1facf80,0x0,0x1facf80,0x40000,0x40040000,0x0,0x0,0x0,0x0,0x0,0x10000,0x0,0x0,0x0,0x1facf80,0x800,0x180c080,0x180cb80,0x80c000,0x0,0x40000000,0x0,0x0,0x41e0cf80,0x0,0x1000080,0x0,0x41e0cb80,0x41e0cb80,0x0,0x0,0x1e0cf80,0x1e0cb80,0x0,0x41e0cb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x1a0cb80,0x1000080,0x0,}; } private static void jj_la1_1() { - jj_la1_1 = new int[] {0x0,0x0,0x0,0x4,0x0,0xe0,0x0,0x0,0x0,0x1,0x0,0x8,0x10,0xe0,0x104,0x104,0x0,0x1564,0x200,0x1564,0x0,0x0,0x6020,0x6020,0x20,0x1164,0x1164,0x0,0x8,0x210,0x210,0x1564,0x0,0x0,0x0,0x400,0x0,0x10000,0x8000,0x10460,0x8000,0x10000,0x20000,0x10460,0x10460,0x20000,0x80000,0x460,0x460,0x3f06000,0x10460,0x3f06000,0x60,0x60,0xc000000,0xc000000,0x10000000,0x460,0x0,0x10000,}; + jj_la1_1 = new int[] {0x0,0x0,0x0,0x4,0x0,0xe0,0x0,0x0,0x0,0x1,0x0,0x8,0x10,0xe0,0x104,0x104,0x1564,0x200,0x1564,0x0,0x0,0x6020,0x6020,0x20,0x1164,0x1164,0x0,0x8,0x210,0x210,0x1564,0x0,0x0,0x0,0x0,0x400,0x0,0x10000,0x8000,0x10460,0x8000,0x10000,0x20000,0x10460,0x10460,0x20000,0x80000,0x460,0x460,0x3f06000,0x10460,0x3f06000,0x60,0x60,0xc000000,0xc000000,0x10000000,0x460,0x0,0x10000,}; } final private JJCalls[] jj_2_rtns = new JJCalls[2]; private boolean jj_rescan = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-09-02 18:57:22
|
Revision: 1746 http://sourceforge.net/p/jason/svn/1746 Author: jomifred Date: 2013-09-02 18:57:16 +0000 (Mon, 02 Sep 2013) Log Message: ----------- add st claus example Modified Paths: -------------- trunk/pom.xml trunk/release-notes.txt Added Paths: ----------- trunk/examples/st-claus/ trunk/examples/st-claus/jason_stclaus.mas2j trunk/examples/st-claus/santa.asl trunk/examples/st-claus/secretary.asl trunk/examples/st-claus/worker.asl Added: trunk/examples/st-claus/jason_stclaus.mas2j =================================================================== --- trunk/examples/st-claus/jason_stclaus.mas2j (rev 0) +++ trunk/examples/st-claus/jason_stclaus.mas2j 2013-09-02 18:57:16 UTC (rev 1746) @@ -0,0 +1,40 @@ +/* + + See description at http://www.cs.otago.ac.nz/staffpriv/ok/santa/ + + This is a Jason solution to "The Santa Claus problem", + as discussed by Simon Peyton Jones (with a Haskell solution using + Software Transactional Memory) in "Beautiful code". + He quotes J.A.Trono "A new exercise in concurrency", SIGCSE 26:8-10, 1994. + + Santa repeatedly sleeps until wakened by either all of his + nine reindeer, back from their holidays, or by a group of three + of his ten elves. If awakened by the reindeer, he harnesses + each of them to his sleight, delivers toys with them, and finally + unharnesses them (allowing them to go off on holiday). If + awakened by a group of elves, he shows each of the group into + his study, consults with them on toy R&D, and finally shows them + each out (allowing them to go back to work). Santa should give + priority to the reindeer in the case that there is both a group + of elves and a group of reindeer waiting. + + Inspired by an old example of Dijkstra's, Richard solve this problem by + introducing two secretaries: Robin and Edna. The reindeer ask Robin + for appointments. As soon as she has nine waiting reindeer she sends + them as a group to Santa. The elves as Edna for appointments. As + soon as she has three waiting elves she sends them as a group to Santa. +*/ + + +MAS jason_stclaus { + + infrastructure: Centralised + + agents: + santa; + edna secretary.asl [beliefs="group_size(3,elf)"]; + robin secretary.asl [beliefs="group_size(9,reindeer)"]; + elf worker.asl [beliefs="kind(elf), secretary(edna)"] #10; + reindeer worker.asl [beliefs="kind(reindeer), secretary(robin)"] #9; + +} \ No newline at end of file Added: trunk/examples/st-claus/santa.asl =================================================================== --- trunk/examples/st-claus/santa.asl (rev 0) +++ trunk/examples/st-claus/santa.asl 2013-09-02 18:57:16 UTC (rev 1746) @@ -0,0 +1,26 @@ +round(0). + +// some group has been formed (message from a secretary) ++!group(Kind,G) : .desire(work(_,_)) // but I am already busy + <- .print("waiting to proceed with ",G); + .suspend; // this goal will be resumed after !work (see_waiting_groups) + !!group(Kind,G). // try again + +@lg[atomic] // N.B. must be atomic, otherwise st claus may handle another event +!group (from resume) before executing !!work ++!group(Kind,G) // I am not working, so start working with this group G + <- !!work(Kind,G). + +// I have to work with group G ++!work(Kind,G) : round(N) & N < 20 // just a stop condition + <- .print("Working with ",Kind,"s: ",G," (",N,")"); + -+round(N+1); + .abolish(done); + .send(G,achieve,proceed); + .wait(.count(done[source(_)],.length(G))); // suspends this intention until |G| dones are received + .print("Group ",G," of ",Kind,"s has finished"); + !!see_waiting_groups. // and resume them (the resume needs to be in another intention, otherwise st claus will be working while checking new groups) ++!work(_,_) <- .print("It is better to stop for now..."). + ++!see_waiting_groups <- + .resume(group(reindeer,_)); // resume reindeers first (they have priority) + .resume(group(_,_)). Added: trunk/examples/st-claus/secretary.asl =================================================================== --- trunk/examples/st-claus/secretary.asl (rev 0) +++ trunk/examples/st-claus/secretary.asl 2013-09-02 18:57:16 UTC (rev 1746) @@ -0,0 +1,12 @@ +group([]). + +// handle messages from workers and form groups +@liam1[atomic] ++!iamhere[source(A)] : group_size(S,Kind) & group(Group) & .length(Group,S-1) + <- -+group([]); + .send(santa,achieve,group(Kind,[A|Group])). + +@liam2[atomic] ++!iamhere[source(A)] : group(Group) + <- -+group([A|Group]). + \ No newline at end of file Added: trunk/examples/st-claus/worker.asl =================================================================== --- trunk/examples/st-claus/worker.asl (rev 0) +++ trunk/examples/st-claus/worker.asl 2013-09-02 18:57:16 UTC (rev 1746) @@ -0,0 +1,12 @@ +msg("Ho, ho, ho! Let's meet in the study!") :- kind(elf). +msg("Ho, ho, ho! Let's deliver toys!") :- kind(reindeer). + +!start. // initial goal, notify my secretary that I am ready ++!start : secretary(S) <- .send(S,achieve,iamhere). + +// do the job asked by St Claus ++!proceed[source(A)] : msg(M) + <- .print(M); + .send(A,tell,done); + .wait( math.random(20)+10 ); + !!start. \ No newline at end of file Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-08-30 11:43:23 UTC (rev 1745) +++ trunk/pom.xml 2013-09-02 18:57:16 UTC (rev 1746) @@ -4,7 +4,7 @@ <artifactId>jason</artifactId> <packaging>jar</packaging> <name>Jason</name> - <version>1.3.9</version> + <version>1.3.10</version> <description>Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language, and is implemented in Java. Using JADE a multi-agent system can be distributed over a network effortlessly.</description> <url>http://jason.sf.net</url> <licenses> Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-08-30 11:43:23 UTC (rev 1745) +++ trunk/release-notes.txt 2013-09-02 18:57:16 UTC (rev 1746) @@ -1,7 +1,7 @@ --------------------------- version 1.3.10 -revision XXX on SVN +revision 1745 on SVN --------------------------- New features This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-08-30 11:43:25
|
Revision: 1745 http://sourceforge.net/p/jason/svn/1745 Author: jomifred Date: 2013-08-30 11:43:23 +0000 (Fri, 30 Aug 2013) Log Message: ----------- minor change in FAQ title Modified Paths: -------------- trunk/build.xml trunk/doc/faq/faq.tex Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2013-08-30 11:32:02 UTC (rev 1744) +++ trunk/build.xml 2013-08-30 11:43:23 UTC (rev 1745) @@ -12,7 +12,7 @@ <property name="dist.properties" value="${basedir}/bin/dist.properties" /> <property name="version" value="1" /> - <property name="release" value="3.9" /> + <property name="release" value="3.10" /> <property name="distDir" value="${env.HOME}/tmp/x/Jason-${version}.${release}" /> <property name="distFile" value="${env.HOME}/Jason-${version}.${release}" /> Modified: trunk/doc/faq/faq.tex =================================================================== --- trunk/doc/faq/faq.tex 2013-08-30 11:32:02 UTC (rev 1744) +++ trunk/doc/faq/faq.tex 2013-08-30 11:43:23 UTC (rev 1745) @@ -16,7 +16,7 @@ \html{\begin{rawhtml}<h0><b><i>Jason</i></b> FAQ - <br><font size="-1">(for version 1.3.7)</font></h0> + <br><font size="-1">(for version > 1.3.7)</font></h0> \end{rawhtml}} \latex{\begin{center}{\Huge\jason FAQ}\end{center}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-08-30 11:32:05
|
Revision: 1744 http://sourceforge.net/p/jason/svn/1744 Author: jomifred Date: 2013-08-30 11:32:02 +0000 (Fri, 30 Aug 2013) Log Message: ----------- fix bugs related to JAG events and a bug related to wait inside atomic intentions Modified Paths: -------------- trunk/demos/persistent-belief-base/VoidBB.java trunk/lib/moise.jar trunk/release-notes.txt trunk/src/jason/asSemantics/TransitionSystem.java trunk/src/jason/asSyntax/PlanLibrary.java trunk/src/jason/stdlib/wait.java Modified: trunk/demos/persistent-belief-base/VoidBB.java =================================================================== --- trunk/demos/persistent-belief-base/VoidBB.java 2013-08-24 16:23:00 UTC (rev 1743) +++ trunk/demos/persistent-belief-base/VoidBB.java 2013-08-30 11:32:02 UTC (rev 1744) @@ -20,6 +20,8 @@ } public void stop() { } + public void clear() { + } public int size() { return 0; } Modified: trunk/lib/moise.jar =================================================================== (Binary files differ) Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2013-08-24 16:23:00 UTC (rev 1743) +++ trunk/release-notes.txt 2013-08-30 11:32:02 UTC (rev 1744) @@ -9,6 +9,10 @@ ...; !g(4)[hard_deadline(3000)]; ... if g(4) is not finished in 3 seconds, a failure event is produced. +- the internal action .wait accepts a logical expression as argument, as in + ...; .wait(b(X) & X > 10); .... + The intention will be suspended until the agent belief b(X) with X > 10. + Timeout and elapse time arguments can be used as previously. --------------------------- version 1.3.9 Modified: trunk/src/jason/asSemantics/TransitionSystem.java =================================================================== --- trunk/src/jason/asSemantics/TransitionSystem.java 2013-08-24 16:23:00 UTC (rev 1743) +++ trunk/src/jason/asSemantics/TransitionSystem.java 2013-08-30 11:32:02 UTC (rev 1744) @@ -1156,7 +1156,7 @@ if (failAnnots == null) failAnnots = JasonException.createBasicErrorAnnots( JasonException.UNKNOW_ERROR, ""); - Literal eventLiteral = failEvent.getTrigger().getLiteral(); + Literal eventLiteral = failEvent.getTrigger().getLiteral().forceFullLiteralImpl(); eventLiteral.addAnnots(failAnnots); // add failure annots in the event related to the code source Modified: trunk/src/jason/asSyntax/PlanLibrary.java =================================================================== --- trunk/src/jason/asSyntax/PlanLibrary.java 2013-08-24 16:23:00 UTC (rev 1743) +++ trunk/src/jason/asSyntax/PlanLibrary.java 2013-08-30 11:32:02 UTC (rev 1744) @@ -342,7 +342,7 @@ public List<Plan> getCandidatePlans(Trigger te) { List<Plan> l = relPlans.get(te.getPredicateIndicator()); - if ((l == null || l.isEmpty()) && !varPlans.isEmpty()) { // no rel plan, try varPlan + if ((l == null || l.isEmpty()) && !varPlans.isEmpty() && te != TE_JAG_SLEEPING && te != TE_JAG_AWAKING) { // no rel plan, try varPlan for (Plan p: varPlans) if (p.getTrigger().sameType(te)) { if (l == null) Modified: trunk/src/jason/stdlib/wait.java =================================================================== --- trunk/src/jason/stdlib/wait.java 2013-08-24 16:23:00 UTC (rev 1743) +++ trunk/src/jason/stdlib/wait.java 2013-08-30 11:32:02 UTC (rev 1744) @@ -89,8 +89,8 @@ public static final String waitAtom = ".wait"; - @Override public boolean canBeUsedInContext() { return false; } - @Override public boolean suspendIntention() { return true; } + @Override public boolean canBeUsedInContext() { return false; } + @Override public boolean suspendIntention() { return true; } @Override public int getMinArgs() { return 1; } @Override public int getMaxArgs() { return 3; } @@ -175,8 +175,8 @@ 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.removePendingIntention(sEvt) == si && !c.hasIntention(si) && !dropped) { + // add SI again in C.I if (1) it was not removed (2) is is not running (by some other reason) -- but this test does not apply to atomic intentions --, and (3) this wait was not dropped + if (c.removePendingIntention(sEvt) == si && (si.isAtomic() || !c.hasIntention(si)) && !dropped) { if (stopByTimeout && te != null && elapsedTimeTerm == null) { // fail the .wait by timeout if (si.isSuspended()) { // if the intention was suspended by .suspend This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-08-24 16:23:03
|
Revision: 1743 http://sourceforge.net/p/jason/svn/1743 Author: jomifred Date: 2013-08-24 16:23:00 +0000 (Sat, 24 Aug 2013) Log Message: ----------- the internal action create_agent accepts a variable for the first argument, this variable will be then unified with the unique name given to the agent. Modified Paths: -------------- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java trunk/src/jason/stdlib/create_agent.java Modified: trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2013-08-15 14:15:34 UTC (rev 1742) +++ trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2013-08-24 16:23:00 UTC (rev 1743) @@ -40,9 +40,12 @@ if (stts == null) stts = new Settings(); - while (masRunner.getAg(agName) != null) - agName += "_a"; - + String nb = ""; + int n = 1; + while (masRunner.getAg(agName+nb) != null) + nb = "_" + (n++); + agName = agName + nb; + CentralisedAgArch agArch = newAgInstance(); agArch.setAgName(agName); agArch.createArchs(ap.getAgArchClasses(), ap.agClass.getClassName(), ap.getBBClass(), agSource, stts, masRunner); Modified: trunk/src/jason/stdlib/create_agent.java =================================================================== --- trunk/src/jason/stdlib/create_agent.java 2013-08-15 14:15:34 UTC (rev 1742) +++ trunk/src/jason/stdlib/create_agent.java 2013-08-24 16:23:00 UTC (rev 1743) @@ -28,16 +28,23 @@ import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; import jason.asSyntax.ListTerm; +import jason.asSyntax.SourceInfo; import jason.asSyntax.StringTerm; +import jason.asSyntax.StringTermImpl; import jason.asSyntax.Structure; import jason.asSyntax.Term; +import jason.asSyntax.VarTerm; import jason.mas2j.ClassParameters; import jason.runtime.RuntimeServicesInfraTier; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + /** <p>Internal action: <b><code>.create_agent</code></b>. @@ -46,7 +53,9 @@ <p>Parameters:<ul> - <li>+ name (atom or string): the name for the new agent.<br/> + <li>+ name (atom, string, or variable): the name for the new agent. + If this parameter is a variable, it will be unified with the name given to the agent. + The agent's name will be the name of the variable and some number that makes it unique.<br/> <li>+ source (string): path to the file where the AgentSpeak code for the new agent can be found.<br/> @@ -61,6 +70,9 @@ <li> <code>.create_agent(bob,"/tmp/x.asl")</code>: creates an agent named "bob" from the source file in "/tmp/x.asl".</li> + <li> <code>.create_agent(Bob,"/tmp/x.asl")</code>: creates an agent named "bob" (or "bob_1", "bob_2", ...) + and unifies variable Bob with the given name.</li> + <li> <code>.create_agent(bob,"x.asl", [agentClass("myp.MyAgent")])</code>: creates the agent with customised agent class @@ -108,6 +120,9 @@ else name = args[0].toString(); + if (args[0].isVar()) + name = name.substring(0,1).toLowerCase() + name.substring(1); + StringTerm source = (StringTerm)args[1]; File fSource = new File(source.getString()); @@ -138,7 +153,11 @@ RuntimeServicesInfraTier rs = ts.getUserAgArch().getRuntimeServices(); name = rs.createAgent(name, fSource.getAbsolutePath(), agClass, agArchClasses, bbPars, ts.getSettings()); rs.startAgent(name); - return true; + + if (args[0].isVar()) + return un.unifies(new StringTermImpl(name), args[0]); + else + return true; } private Structure testString(Term t) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-08-15 14:15:37
|
Revision: 1742 http://sourceforge.net/p/jason/svn/1742 Author: jomifred Date: 2013-08-15 14:15:34 +0000 (Thu, 15 Aug 2013) Log Message: ----------- include a "clear" method in BB implements "remove()" for BB iterator Modified Paths: -------------- trunk/src/jason/bb/BeliefBase.java trunk/src/jason/bb/ChainBBAdapter.java trunk/src/jason/bb/DefaultBeliefBase.java trunk/src/jason/bb/JDBCPersistentBB.java trunk/src/test/BeliefBaseTest.java Modified: trunk/src/jason/bb/BeliefBase.java =================================================================== --- trunk/src/jason/bb/BeliefBase.java 2013-07-18 16:54:23 UTC (rev 1741) +++ trunk/src/jason/bb/BeliefBase.java 2013-08-15 14:15:34 UTC (rev 1742) @@ -64,6 +64,9 @@ /** Called just before the end of MAS execution */ public void stop(); + /** removes all beliefs from BB */ + public void clear(); + /** Adds a belief in the end of the BB, returns true if succeed. * The annots of l may be changed to reflect what was changed in the BB, * for example, if l is p[a,b] in a BB with p[a], l will be changed to Modified: trunk/src/jason/bb/ChainBBAdapter.java =================================================================== --- trunk/src/jason/bb/ChainBBAdapter.java 2013-07-18 16:54:23 UTC (rev 1741) +++ trunk/src/jason/bb/ChainBBAdapter.java 2013-08-15 14:15:34 UTC (rev 1742) @@ -89,6 +89,9 @@ nextBB.stop(); } + public void clear() { + nextBB.clear(); + } public boolean add(Literal l) { return nextBB.add(l); Modified: trunk/src/jason/bb/DefaultBeliefBase.java =================================================================== --- trunk/src/jason/bb/DefaultBeliefBase.java 2013-07-18 16:54:23 UTC (rev 1741) +++ trunk/src/jason/bb/DefaultBeliefBase.java 2013-08-15 14:15:34 UTC (rev 1742) @@ -74,6 +74,12 @@ public int size() { return size; } + + public void clear() { + size = 0; + percepts.clear(); + belsMap.clear(); + } public Iterator<Literal> getPercepts() { final Iterator<Literal> i = percepts.iterator(); @@ -188,13 +194,14 @@ return new Iterator<Literal>() { Iterator<Literal> il = ibe.next().list.iterator(); - + Literal l; + public boolean hasNext() { return il.hasNext(); } public Literal next() { - Literal l = il.next(); + l = il.next(); if (!il.hasNext() && ibe.hasNext()) { il = ibe.next().list.iterator(); } @@ -202,7 +209,11 @@ } public void remove() { - logger.warning("remove is not implemented for BB.iterator()."); + il.remove(); + if (l.hasAnnot(TPercept)) { + percepts.remove(l); + } + size--; } }; } else { @@ -213,10 +224,10 @@ /** @deprecated use iterator() instead of getAll */ public Iterator<Literal> getAll() { return iterator(); - } - + } public boolean abolish(PredicateIndicator pi) { + // TODO: remove also in percepts list! return belsMap.remove(pi) != null; } Modified: trunk/src/jason/bb/JDBCPersistentBB.java =================================================================== --- trunk/src/jason/bb/JDBCPersistentBB.java 2013-07-18 16:54:23 UTC (rev 1741) +++ trunk/src/jason/bb/JDBCPersistentBB.java 2013-08-15 14:15:34 UTC (rev 1742) @@ -180,6 +180,10 @@ } nextBB.stop(); } + + public void clear() { + logger.warning("clear is still not implemented for JDBC BB!"); + } /** returns true if the literal is stored in a DB */ protected boolean isDB(Literal l) { Modified: trunk/src/test/BeliefBaseTest.java =================================================================== --- trunk/src/test/BeliefBaseTest.java 2013-07-18 16:54:23 UTC (rev 1741) +++ trunk/src/test/BeliefBaseTest.java 2013-08-15 14:15:34 UTC (rev 1742) @@ -172,6 +172,19 @@ assertEquals(iteratorSize(bb.getPercepts()), 0); assertEquals(bb.size(), 1); + l2 = new LiteralImpl(true, new Pred("testRemIt")); + l2.addAnnot(new Structure("a")); + l2.addAnnot(BeliefBase.TPercept); + bb.add(l2); + Iterator<Literal> itl = bb.iterator(); + while (itl.hasNext()) { + Literal l = itl.next(); + if (l.getFunctor().startsWith("testRemIt")) { + itl.remove(); + } + } + assertEquals(iteratorSize(bb.getPercepts()), 0); + l3 = Literal.parseLiteral("pos[source(ag1)]"); assertFalse(l2.isAtom()); assertTrue(bb.remove(l3)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jom...@us...> - 2013-07-18 16:54:26
|
Revision: 1741 http://sourceforge.net/p/jason/svn/1741 Author: jomifred Date: 2013-07-18 16:54:23 +0000 (Thu, 18 Jul 2013) Log Message: ----------- initial implementation of .wait(logical formula) Modified Paths: -------------- trunk/examples/auction/auctioneer.asl trunk/src/jason/stdlib/wait.java Modified: trunk/examples/auction/auctioneer.asl =================================================================== --- trunk/examples/auction/auctioneer.asl 2013-07-18 00:44:04 UTC (rev 1740) +++ trunk/examples/auction/auctioneer.asl 2013-07-18 16:54:23 UTC (rev 1741) @@ -13,4 +13,3 @@ show_winner(N,W); // show it in the GUI .broadcast(tell, winner(W)); .abolish(place_bid(N,_)). - Modified: trunk/src/jason/stdlib/wait.java =================================================================== --- trunk/src/jason/stdlib/wait.java 2013-07-18 00:44:04 UTC (rev 1740) +++ trunk/src/jason/stdlib/wait.java 2013-07-18 16:54:23 UTC (rev 1741) @@ -32,6 +32,7 @@ import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; import jason.asSyntax.InternalActionLiteral; +import jason.asSyntax.LogicalFormula; import jason.asSyntax.NumberTerm; import jason.asSyntax.NumberTermImpl; import jason.asSyntax.PlanBody; @@ -52,8 +53,10 @@ <code>{+!go(X,Y)}</code>. <p>Parameters:<ul> - <li><i>+ event</i> (trigger term): the event to wait for.<br/> - <li>+ timeout (number).<br/> + <li><i>+ event</i> (trigger term [optional]): the event to wait for.<br/> + <li><i>+ logical expression</i> ([optional]): the expression (as used on plans context) to wait to holds.<br/> + <li>+ timeout (number [optional]): how many miliseconds should be waited.<br/> + <li>- elapse time (var [optional]): the amount of time the intention was suspended waiting.<br/> </ul> @@ -63,6 +66,9 @@ <li> <code>.wait({+b(1)})</code>: suspend the intention until the belief <code>b(1)</code> is added in the belief base. + <li> <code>.wait(b(X) & X > 10)</code>: suspend the intention until the agent believes + <code>b(X)</code> with X greater than 10. + <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 @@ -95,29 +101,31 @@ long timeout = -1; Trigger te = null; + LogicalFormula f = null; Term elapsedTime = null; if (args[0].isNumeric()) { // time in milliseconds NumberTerm time = (NumberTerm)args[0]; timeout = (long) time.solve(); - } else { // if (args[0].isString()) - // wait for event - te = Trigger.tryToGetTrigger(args[0]); //ASSyntax.parseTrigger( ((StringTerm) args[0]).getString()); - //te.getLiteral().apply(un); - + } else { + te = Trigger.tryToGetTrigger(args[0]); // wait for event + if (te == null && args[0] instanceof LogicalFormula) { // wait for an expression to become true + f = (LogicalFormula)args[0]; + } if (args.length >= 2) timeout = (long) ((NumberTerm) args[1]).solve(); if (args.length == 3) elapsedTime = args[2]; } - new WaitEvent(te, un, ts, timeout, elapsedTime); + new WaitEvent(te, f, un, ts, timeout, elapsedTime); return true; } class WaitEvent implements CircumstanceListener { private Trigger te; - private String sTE; // a string version of TE + private LogicalFormula formula; + private String sEvt; // a string version of what is being waited private Unifier un; private Intention si; private TransitionSystem ts; @@ -126,8 +134,9 @@ private Term elapsedTimeTerm; private long startTime; - WaitEvent(Trigger te, Unifier un, TransitionSystem ts, long timeout, Term elapsedTimeTerm) { + WaitEvent(Trigger te, LogicalFormula f, Unifier un, TransitionSystem ts, long timeout, Term elapsedTimeTerm) { this.te = te; + this.formula = f; this.un = un; this.ts = ts; c = ts.getC(); @@ -138,12 +147,14 @@ c.addEventListener(this); if (te != null) { - sTE = te.toString(); + sEvt = te.toString(); + } else if (formula != null) { + sEvt = formula.toString(); } else { - sTE = "time"+(timeout); + sEvt = "time"+(timeout); } - sTE = si.getId()+"/"+sTE; - c.addPendingIntention(sTE, si); + sEvt = si.getId()+"/"+sEvt; + c.addPendingIntention(sEvt, si); startTime = System.currentTimeMillis(); @@ -165,7 +176,7 @@ public void run() { try { // add SI again in C.I if it was not removed and this wait was not dropped - if (c.removePendingIntention(sTE) == si && !c.hasIntention(si) && !dropped) { + if (c.removePendingIntention(sEvt) == si && !c.hasIntention(si) && !dropped) { if (stopByTimeout && te != null && elapsedTimeTerm == null) { // fail the .wait by timeout if (si.isSuspended()) { // if the intention was suspended by .suspend @@ -198,8 +209,12 @@ } public void eventAdded(Event e) { - if (te != null && !dropped && un.unifies(te, e.getTrigger())) { + if (dropped) + return; + if (te != null && un.unifies(te, e.getTrigger())) { resume(false); + } else if (formula != null && ts.getAg().believes(formula, un)) { // each new event, just test the formula being waited + resume(false); } } @@ -214,7 +229,7 @@ public void intentionResumed(Intention i) { } public void intentionSuspended(Intention i, String reason) { } public String toString() { - return sTE; + return sEvt; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |