Skip to content

Commit

Permalink
fix test of pattern queue plans
Browse files Browse the repository at this point in the history
  • Loading branch information
jomifred committed Sep 24, 2020
1 parent 4e0d57e commit 7223a8e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions doc/tech/concurrency.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The plan

creates a new intention for `gb` and then executes the action `a1`. `a1` is executed after the creation of the intention for `gb` and not after the achievement of `gb` (as it would be the case if `!` was used instead of `!!`). The intention for `gb` is a new intention and not the same as the intention for `ga`.

=== Concurrent plans
=== Concurrent Operators

Besides the usual sequence operator `;`, plan bodies can also use fork and join operators for concurrent execution of plan bodies: `|&|` and `|||`. The first is called __fork-join-and__ and the second __fork-join-xor__.

Expand Down Expand Up @@ -113,13 +113,13 @@ When a *.succeed_goal(gb)* is executed:
If some intention cannot interleave its execution with another, the *atomic* annotation can be used in the label of plans:

----
@alabel[atomic] // no other intention will run if an intention based on this plan starts running
@alabel[atomic] // no other intention will run if an intention selects this plan
+!update(X)
<- -vl(T); // gets the current value of belief vl
+vl(T+X). // updates its value
----

If an atomic plan runs, all its subgoals will be also atomic.
If an atomic plan runs, all its subgoals will be also atomic. More documentation regarding this matter can be found https://github.com/jason-lang/jason/blob/develop/doc/tech/patterns.adoc[here].

// add new support with conflict

Expand Down
15 changes: 7 additions & 8 deletions doc/tech/patterns.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The following code avoids two or more concurrent executions of plan `g`:

If the agent has two events `+!g`, when the first is handled, the agent does not intend `g` and the first plan is selected and thus the agent now intends `g` avoiding this plan to be selected again.

NOTE: This pattern considers `g` as achieved if someother intention is trying it (cf. the second plan for `g`).
NOTE: This pattern considers `g` as achieved if some other intention is trying it (cf. the second plan for `g`).

Example:
----
Expand Down Expand Up @@ -120,8 +120,7 @@ The section 8.3 of the http://jason.sf.net/jBook[Jason Book] presents some usefu

=== Single-Minded Commitment

In this pattern we want an agent that keeps trying to achieve goal `g` until it believes `g` is achieved (as a declarative goal) or that `g` is impossible. See paper "Cohen & Levesque. Intention is choice with commitment. Artificial
Intelligence 42(3), 213–261, 1990."
In this pattern we want an agent that keeps trying to achieve goal `g` until it believes `g` is achieved (as a declarative goal) or that `g` is impossible. See paper "Cohen & Levesque. Intention is choice with commitment. Artificial Intelligence 42(3), 213–261, 1990."

Supposing that to believe in `f` implies that `g` is impossible, the pattern can be written as:

Expand All @@ -136,15 +135,15 @@ Supposing that to believe in `f` implies that `g` is impossible, the pattern can
<- dosomething2;
?g.
+!g : !g. // no applicable plan, keep trying
-!g <- !g. // if the above plans have failed, keep trying hopping for better conditions
+g <- .succeed_goal(g). // stop trying g if g
+f <- .fail_goal(g). // stop trying g if f
+!g : !g. // no applicable plan, keeps trying
-!g <- !g. // if the above plans have failed, keeps trying hopping for better conditions
+g <- .succeed_goal(g). // stops trying g if g
+f <- .fail_goal(g). // stops trying g if f
----

NOTE: The plans to achieve `g` end with `?g`, so they only succeed if after doing something to acheive `g` the agent believes `g` (for instance, it perceives `g`).

In Jason, a directive is available to simplify the use this pattern:
In Jason, a directive is available to simplify the use of this pattern:
----
{ begin smc(g,f) }
+!g : somecontext1 <- dosomething1.
Expand Down
7 changes: 3 additions & 4 deletions src/test/jason/asl/patterns/queueplan.asl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
@[test]
+!test_pattern_queue
<- !e;
//.wait(500);
//!assert_equals( 6, .count(run(_)))
.wait(500);
!assert_equals( 6, .count(run(_)))
.

// the pattern

!e.
+!e
<- for ( .range(I,0,5)) {
.print(I);
//.print(I);
!!g(I);
}.

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/test/ASParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void testDirectives() throws Exception {
a.initAg();
a.setASLSrc("test1");
parser.agent(a);
assertEquals(9, a.getPL().getPlans().size());
assertEquals(10, a.getPL().getPlans().size());
assertEquals("@l1[source(self)] +!at(X,left(H)) : not (b(X)) <- go(3,Y); ?at(X,left(H)).", a.getPL().get("l1").toString());

source = " { begin mg(at(10,10)) } \n";
Expand All @@ -210,7 +210,7 @@ public void testDirectives() throws Exception {
//for (Plan p: a.getPL().getPlans()) {
// System.out.println(p);
//}
assertTrue(a.getPL().getPlans().size() == 7);
assertTrue(a.getPL().getPlans().size() == 8);
assertTrue(a.getInitialBels().size() == 1);

source = " { begin sga(\"+go(X,Y)\", \"(at(home) & not c)\", at(X,Y)) } \n";
Expand Down

0 comments on commit 7223a8e

Please sign in to comment.