|
From: <jom...@us...> - 2008-05-03 14:16:18
|
Revision: 1285
http://jason.svn.sourceforge.net/jason/?rev=1285&view=rev
Author: jomifred
Date: 2008-05-03 07:16:12 -0700 (Sat, 03 May 2008)
Log Message:
-----------
jason team: improvements
.suspend without arg
.delete in list uses unification
Modified Paths:
--------------
trunk/applications/jason-moise/lib/moise.jar
trunk/applications/jason-moise/src/jmoise/OrgManager.java
trunk/applications/jason-moise/src/jmoise/broadcast.java
trunk/applications/jason-team/gauchos.xml
trunk/applications/jason-team/src/asl/exploration.asl
trunk/applications/jason-team/src/asl/gaucho.asl
trunk/applications/jason-team/src/asl/goto.asl
trunk/applications/jason-team/src/asl/herding.asl
trunk/applications/jason-team/src/java/agent/OrgMaintenanceGoal.java
trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
trunk/applications/jason-team/src/java/test/MindView.java
trunk/applications/jason-team/src/team-os.xml
trunk/src/jason/asSemantics/IntendedMeans.java
trunk/src/jason/asSyntax/InternalActionLiteral.java
trunk/src/jason/asSyntax/ListTermImpl.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/asSyntax/patterns/goal/EBDG.java
trunk/src/jason/stdlib/delete.java
trunk/src/jason/stdlib/drop_desire.java
trunk/src/jason/stdlib/package.html
trunk/src/jason/stdlib/resume.java
trunk/src/jason/stdlib/suspend.java
trunk/src/xml/agInspection.xsl
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/TestIAdelete.java
Added: trunk/applications/as-unit-test/src/jason/tests/TestIAdelete.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestIAdelete.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/TestIAdelete.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -0,0 +1,54 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestIAdelete {
+
+ TestAgent ag;
+
+ // initialisation of the agent test
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "pos(3). pos(4). pos(1). pos(10). "+
+ "+!test1 <- .findall(pos(X),pos(X),L); !find_closest(5,L,Alloc,Rest); jason.asunit.print(\"*\",Alloc); jason.asunit.print(Rest)."+
+
+ "+!test2 <- .findall(pos(X),pos(X),L); !alloc([1,2,3,4],L)."+
+
+ "+!alloc([],_). "+
+ "+!alloc([A|T],Options) <- !find_closest(A,Options,Loc,Rest); jason.asunit.print(A,\" to \",Loc); !alloc(T,Rest). " +
+
+ "+!find_closest(Ag,Options, MinDist, Rest) <- "+
+ " ?calc_distances(Options,Distances,Ag); jason.asunit.print(Distances); "+
+ " .min(Distances,d(_,MinDist)); "+
+ " .delete(pos(MinDist),Options,Rest). "+
+
+ "calc_distances([],[],_) :- true. "+
+ "calc_distances([pos(F)|TP], [d(D,F)|TD], Ref) "+
+ ":- D = math.abs(Ref - F) & calc_distances(TP, TD, Ref). "
+ );
+ }
+
+ @Test
+ public void testDelete() {
+ ag.addGoal("test1");
+ ag.assertPrint("[d(2,3),d(1,4),d(4,1),d(5,10)]", 5);
+ ag.assertPrint("*4", 5);
+ ag.assertPrint("[pos(3),pos(1),pos(10)]", 3);
+ }
+
+ @Test
+ public void testAlloc() {
+ ag.addGoal("test2");
+ ag.assertPrint("1 to 1", 10);
+ ag.assertPrint("2 to 3", 10);
+ ag.assertPrint("3 to 4", 10);
+ ag.assertPrint("4 to 10", 10);
+ }
+}
Modified: trunk/applications/jason-moise/lib/moise.jar
===================================================================
(Binary files differ)
Modified: trunk/applications/jason-moise/src/jmoise/OrgManager.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -156,10 +156,10 @@
OrgManagerCommand cmd = commands.get(content.getFunctor());
if (cmd != null) {
cmd.process(currentOE, content, agSender, m.getMsgId());
+ updateGUI();
} else {
logger.info("Received an unknown message: " + m + "!");
}
- updateGUI();
} catch (MoiseException e) {
logger.log(Level.SEVERE, "Error processing '" + m + "' for " + agSender + ". "+e);
sendReply(agSender, m.getMsgId(), "error(\"" + e + "\")");
@@ -215,11 +215,22 @@
public void process(OE currentOE, Pred command, OEAgent sender, String mId) throws MoiseException {
String roleId = command.getTerm(0).toString();
String grId = command.getTerm(1).toString();
+
sender.removeRole(roleId, grId);
GroupInstance gr = currentOE.findGroup(grId);
// notify other players
updateMembersOE(gr.getAgents(true), "play(" + sender + "," + roleId + "," + grId + ")", false, false);
+
+ // and the sender
+ updateMembersOE(sender, "play(" + sender + "," + roleId + "," + grId + ")", true, false);
+
+ // if the agent is not member of the group anymore, remove other informations of the group
+ if (!gr.getAgents(false).contains(sender)) {
+ for (RolePlayer rp : gr.getPlayers()) {
+ updateMembersOE(sender, "play(" + rp.getPlayer().getId() + "," + rp.getRole().getId() + "," + gr.getId() + ")", false, false);
+ }
+ }
}
}
Modified: trunk/applications/jason-moise/src/jmoise/broadcast.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/broadcast.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-moise/src/jmoise/broadcast.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -59,7 +59,7 @@
GroupInstance gi = oag.getOE().findGroup(target.toString());
if (gi != null) {
for (OEAgent ag: gi.getAgents(true)) {
- if (!ag.getId().equals(oag.getAgName())) {
+ if (!ag.getId().equals(oag.getAgName()) && !oag.getAgName().startsWith("someone")) {
oag.sendMsg(new Message(ilf.toString(), null, ag.getId(), pcnt));
}
}
@@ -68,7 +68,7 @@
SchemeInstance sch = oag.getOE().findScheme(target.toString());
if (sch != null) {
for (OEAgent ag: sch.getAgents()) {
- if (!ag.getId().equals(oag.getAgName())) {
+ if (!ag.getId().equals(oag.getAgName()) && !oag.getAgName().startsWith("someone")) {
oag.sendMsg(new Message(ilf.toString(), null, ag.getId(), pcnt));
}
}
Modified: trunk/applications/jason-team/gauchos.xml
===================================================================
--- trunk/applications/jason-team/gauchos.xml 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/gauchos.xml 2008-05-03 14:16:12 UTC (rev 1285)
@@ -32,9 +32,9 @@
<copy file="../jason-moise/lib/moise.jar" todir="lib" />
<mkdir dir="tmp-ag-mind" />
- <!--delete failonerror="no" includeEmptyDirs="true" verbose="false">
- <fileset dir="tmp-ag-mind" includes="*.xml"/>
- </delete-->
+ <delete failonerror="no" includeEmptyDirs="true" verbose="false">
+ <fileset dir="massim-server/backup" includes="*"/>
+ </delete>
</target>
<target name="user-end">
</target>
@@ -93,7 +93,11 @@
<target name="run" depends="compile" >
- <echo message="Running project ${ant.project.name}" />
+ <delete failonerror="no" includeEmptyDirs="true" verbose="false">
+ <fileset dir="tmp-ag-mind" includes="*.xml"/>
+ </delete>
+
+ <echo message="Running project ${ant.project.name}" />
<java classname="jason.infra.centralised.RunCentralisedMAS"
failonerror="true" fork="yes" dir="${basedir}" >
<classpath refid="project.classpath"/>
Modified: trunk/applications/jason-team/src/asl/exploration.asl
===================================================================
--- trunk/applications/jason-team/src/asl/exploration.asl 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/asl/exploration.asl 2008-05-03 14:16:12 UTC (rev 1285)
@@ -5,6 +5,8 @@
/* -- initial goals -- */
+!create_team_group.
+
/*
-- plans for new match
-- create the initial exploration groups and areas
@@ -14,10 +16,12 @@
/* plans for the team's groups creation */
+!create_team_group
+ : .my_name(gaucho1)
<- .print("oooo creating new team group ------------------------------------------------- ");
!remove_org;
jmoise.create_group(team).
-
++!create_team_group.
+
+group(team,GId) // agent 1 is responsible for the creation of exploration groups
: .my_name(gaucho1)
<- jmoise.create_group(exploration_grp,GId);
@@ -45,9 +49,9 @@
: .my_name(Me) &
agent_id(Me,AgId) &
AgId mod 2 == 1 // I have an odd Id
- <- .if( .my_name(gaucho1) ) {
- !create_team_group
- };
+ <- //.if( .my_name(gaucho1) ) {
+ // !create_team_group
+ //};
.print("ooo Recruiting scouters for my explorer group....");
@@ -79,7 +83,7 @@
+!find_scouter([ag_d(_,AgName)|_],GId)
<- .print("ooo Ask ",AgName," to play scouter");
.send(AgName, achieve, play_role(scouter,GId));
- .wait("+play(Ag,scouter,GId)",2000).
+ .wait("+play(AgName,scouter,GId)",2000).
-!find_scouter([_|LSOdd],GId) // in case the wait fails, try next agent
<- .print("ooo find_scouter failure, try another agent.");
!find_scouter(LSOdd,GId).
@@ -93,8 +97,6 @@
/* -- plans for the goals of role explorer -- */
-// TODO: make a pattern for organisational maintainance goal
-
{ begin maintenance_goal("+pos(_,_,_)") }
+!goto_near_unvisited[scheme(Sch),mission(Mission)]
@@ -121,11 +123,13 @@
!!goto_near_unvisited[scheme(Sch),mission(Mission)].
*/
+
+
/* -- plans for the goals of role scouter -- */
{ begin maintenance_goal("+pos(_,_,_)") }
-+!follow_leader[scheme(Sch),group(Gr)]
++!follow_leader[scheme(Sch),mission(Mission),group(Gr)]
: play(Leader, explorer, Gr)
<- .print("ooo I should follow the leader ",Leader);
?pos(MyX,MyY,_);
@@ -139,9 +143,10 @@
-+target(LX,LY)
}{
.print("ooo being in formation with leader.");
- .send(Leader,askOne,target(X,Y),target(TX,TY));
+ .send(Leader,askOne,target(_,_),target(TX,TY));
jia.scouter_pos(LX, LY, TX, TY, SX, SY);
-+target(SX,SY)
- }
+ }.
{ end }
+
Modified: trunk/applications/jason-team/src/asl/gaucho.asl
===================================================================
--- trunk/applications/jason-team/src/asl/gaucho.asl 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/asl/gaucho.asl 2008-05-03 14:16:12 UTC (rev 1285)
@@ -41,6 +41,8 @@
+?pos(X, Y, S) <- .wait("+pos(X,Y,S)").
+?group_area(Id,G,A) <- .wait("+group_area(Id,G,A)").
++?gsize(W,H) <- .wait("+gsize(W,H)").
++?ally_pos(Name,X,Y) : .my_name(Name) <- ?pos(X,Y,_).
+end_of_simulation(_Result)
<- .abolish(group_area(_,_,_));
@@ -57,39 +59,18 @@
/* -- plans for the goals of all roles -- */
-/*
-TODO: use a list given by BUF
++!share_seen_cows <- .print("ooo start sharing cows."); .suspend.
-+!share_seen_cows[scheme(Sch)]
- <- .print("ooo I should share cows!");
- ?cows_to_inform(C);
- jmoise.broadcast(Sch, tell, C);
- // TODO: limpar -+cows_to_inform([])
- .wait("+pos(_,_,_)"); // wait next cycle
- !!share_seen_cows[scheme(Sch)].
-
-+?cows_to_inform([]).
-
-+cell(X,Y,cow(Id))
- <- +cow(Id,X,Y); //Jomi, tu nao vai gostar disso :D
- ?cows_to_inform(C);
- -+cows_to_inform([cow(Id,X,Y)|C]).
-
-*/
-
-+!share_seen_cows.
-
// simple implementation of share_cows (see TODO above)
+cow(Id,X,Y)[source(percept)]
- : .my_name(Me) & play(Me,_,Gr)
+ : .desire(share_seen_cows) & .my_name(Me) & play(Me,_,Gr)
<- jmoise.broadcast(Gr, tell, cow(Id,X,Y)).
-cow(Id,X,Y)[source(percept)]
- : .my_name(Me) & play(Me,_,Gr)
+ : .desire(share_seen_cows) & .my_name(Me) & play(Me,_,Gr)
<- jmoise.broadcast(Gr, untell, cow(Id,X,Y)).
-
/* -- general organisational plans -- */
// remove all groups and schemes (only agent1 does that)
@@ -114,7 +95,7 @@
// get the list G of participants of the group where I play R
+?my_group_players(G,R)
<- .my_name(Me);
- play(Me,R,Gid);
+ ?play(Me,R,Gid);
.findall(P, play(P,_,Gid), G).
+!play_role(Role,Group)[source(Ag)]
@@ -134,8 +115,9 @@
<- jmoise.remove_mission(Mission,Sch).
// when I am not committed to a mission anymore, remove all goals based on that mission
--commitment(Ag,Mission,Sch)
- <- .drop_desire(_[scheme(Id),mission(Mission)]).
+-commitment(Me,Mission,Sch)
+ : .my_name(Me)
+ <- .drop_desire(_[scheme(Sch),mission(Mission)]).
// if some scheme is finished, drop all intentions related to it.
-scheme(_Spec,Id)
Modified: trunk/applications/jason-team/src/asl/goto.asl
===================================================================
--- trunk/applications/jason-team/src/asl/goto.asl 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/asl/goto.asl 2008-05-03 14:16:12 UTC (rev 1285)
@@ -21,6 +21,7 @@
+target(NX,NY)
<- .drop_desire(move);
jia.set_target(NX,NY);
+ -at_target;
!!move.
// I still do not know my location
Modified: trunk/applications/jason-team/src/asl/herding.asl
===================================================================
--- trunk/applications/jason-team/src/asl/herding.asl 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/asl/herding.asl 2008-05-03 14:16:12 UTC (rev 1285)
@@ -2,55 +2,127 @@
/* -- initial beliefs -- */
+/* -- plans for herding groups creation -- */
+// if see cow and is not herding, create the herding group and change roles
+@lcs[atomic]
++cow(_,_,_)
+ : .my_name(Me) &
+ play(Me,explorer,_) &
+ not .desire(create_herding_gr) // to avoid crating several groups
+ <- !create_herding_gr.
+
++!create_herding_gr
+ <- .print("ooo Creating herding group.");
+ .my_name(Me);
+
+ // create the new group
+ ?group(team,TeamId);
+ jmoise.create_group(herding_grp, TeamId);
+ .wait("+group(herding_grp, HG)[owner(Me)]", 4000);
+
+ // store the list of scouter in my group
+ ?play(Me,explorer,EG);
+ .findall(Scouter,play(Scouter,scouter,EG),LScouters);
+
+ !change_role(herder,HG);
+
+ // ask scouters to change role
+ .print("ooo Asking ",LScouters," to adopt the herdboy role");
+ .send(LScouters,achieve,change_role(herdboy,HG)).
+
+
++!change_role(herder,HG)
+ <- .my_name(Me);
+ .if (commitment(Me,explore,Sch)) {
+ jmoise.remove_mission(explore,Sch)
+ };
+ .if (play(Me,explorer,EG)) {
+ jmoise.remove_role(explorer,EG)
+ };
+ jmoise.adopt_role(herder,HG).
+
++!change_role(herdboy,HG)
+ <- .my_name(Me);
+ .if (commitment(Me,scout,Sch)) {
+ jmoise.remove_mission(scout,Sch)
+ };
+ .if (play(Me,scouter,EG)) {
+ jmoise.remove_role(scouter,EG)
+ };
+ jmoise.adopt_role(herdboy,HG).
+
+
+// If if start playing explorer in a group that has no scheme, create the scheme
++play(Ag,herder,G)
+ : .my_name(Ag) &
+ not scheme_group(_,G)
+ <- jmoise.create_scheme(herd_sch, [G]).
+
+
/* -- plans for the goals of role herder -- */
{ begin maintenance_goal("+pos(_,_,_)") }
-+!recruit[scheme(Sch)]
++!recruit[scheme(Sch),mission(Mission)]
<- .print("ooo I should revise the size of the cluster and recruit!").
{ end }
+
{ begin maintenance_goal("+pos(_,_,_)") }
-+!define_formation[scheme(Sch)]
++!define_formation[scheme(Sch),mission(Mission)]
<- .print("ooo I should define the formation of my group!");
?my_group_players(G, herder);
jia.herd_position(.length(G),L);
- .print("ooo formation is ",L);
+ .print("ooo Formation is ",L, " for agents ",G);
!alloc_all(G,L).
{ end }
-+!alloc_all([],LA).
++!alloc_all([],_).
+!alloc_all([HA|TA],LA)
<- !find_closest(HA,LA,pos(X,Y),NLA);
+ .print("ooo Alocating position ",pos(X,Y)," to agent ",HA);
.send(HA,tell,target(X,Y));
- -+alloc_target(HA,Alloc);
+ //-+alloc_target(HA,Alloc);
!alloc_all(TA,NLA).
-+!find_closest(Ag, List, Alloc, Rest) // rule
- <- ?ally_pos(Ag,XY);
- !closest(List,[],Sorted,pos(X,Y),9999);
- Sorted = [Alloc|Rest];
- .print("FIND CLOSEST: ",Sorted).
-// TODO: use min
-+!closest([],S,S,P,D).
++!find_closest(Ag, ListPos, MinDist, Rest) // find the location in ListPos nearest to agent Ag
+ <- ?ally_pos(Ag,X,Y);
+ ?calc_distances(ListPos,Distances,pos(X,Y));
+ .print("Distances for ",ag_pos(Ag,X,Y)," are ",Distances);
+ .min(Distances,d(_,MinDist));
+ .delete(d(_,MinDist),Distances,Rest);
+ .print("rest is ",Rest).
+ //!closest(ListPos,[],Sorted,pos(X,Y),9999);
+ //Sorted = [Alloc|Rest];
+ //.print("FIND CLOSEST: ",Sorted).
+
+calc_distances([],[],_) :- true.
+calc_distances([pos(Fx,Fy)|TP], [d(D,pos(Fx,Fy))|TD], pos(AgX,AgY))
+ :- jia.path_length(Fx,Fy,AgX,AgY,D) & calc_distances(TP, TD, pos(AgX,AgY)).
+
+/*
++!closest([],S,S,_,_).
+!closest([pos(XH,YH)|T],Aux,S,pos(XP,YP),LD)
- : jia.path_length(XH,YH,XP,YP,D) & D < LD // usar A*
+ : jia.path_length(XH,YH,XP,YP,D) & D < LD
<- !closest(T,[pos(XH,YH)|Aux],S,pos(XP,YP),D).
+!closest([pos(XH,YH)|T],Aux,S,pos(XP,YP),LD)
<- .concat(Aux,[pos(XH,YH)],Aux2);
!closest(T,Aux2,S,pos(XP,YP),LD).
+*/
-
/* -- plans for the goals of all roles (herder and herdboy) -- */
-{ begin maintenance_goal("+pos(_,_,_)") }
-+!be_in_formation[scheme(Sch)]
- <- .print("ooo I should be in formation!").
- // TODO
+//{ begin maintenance_goal("+pos(_,_,_)") }
+
+// This goal behaviour is set by the message "tell target" of the leader of the group
++!be_in_formation[scheme(Sch),mission(Mission)]
+ <- .print("ooo I should be in formation!");
+ .suspend.
-{ end }
+// { end }
+
Modified: trunk/applications/jason-team/src/java/agent/OrgMaintenanceGoal.java
===================================================================
--- trunk/applications/jason-team/src/java/agent/OrgMaintenanceGoal.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/java/agent/OrgMaintenanceGoal.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -23,6 +23,8 @@
PlanBody endofplan = null;
Literal goal = null;
+ //ListTerm annots = ListTermImpl.parseList("[scheme(SchId),mission(MissionId),group(GroupId)]");
+
// change all inner plans
for (Plan p: innerContent.getPL()) {
// create end of plan: .wait
@@ -31,13 +33,13 @@
endofplan = new PlanBodyImpl(PlanBody.BodyType.internalAction, wait);
// create end of plan: !!goal[.....]
+ //p.getTrigger().getLiteral().addAnnots( (ListTerm)annots.clone());
goal = p.getTrigger().getLiteral().copy();
endofplan.add(new PlanBodyImpl(PlanBody.BodyType.achieveNF, goal));
// add in the end of plan
p.getBody().add(endofplan);
-
- logger.info("*** changed plan = "+p);
+ newAg.getPL().add(p);
}
// add failure plan:
@@ -47,10 +49,8 @@
// .wait("+pos(_,_,_)"); // wait next cycle
// !!goto_near_unvisited[scheme(Sch),mission(Mission)].
String sp = "-!"+goal+" <- .current_intention(I); " +
- ".print(\"ooo Failure in organisational goal "+goal+", I\"); "+
+ ".print(\"ooo Failure in organisational goal "+goal+"\", I); "+
endofplan + ".";
-
- logger.info("*** new plan s = "+sp);
Plan p = Plan.parse(sp);
newAg.getPL().add(p);
Modified: trunk/applications/jason-team/src/java/arch/WriteStatusThread.java
===================================================================
--- trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/java/arch/WriteStatusThread.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -70,7 +70,10 @@
out = new PrintWriter(fileName);
while (true) {
try {
+ long timebefore = System.currentTimeMillis();
waitNextCycle();
+ long cycletime = System.currentTimeMillis() - timebefore;
+
//out.println("\n\n** Agent "+getAgName()+" in cycle "+cycle+"\n");
//for (int i=0; i<model.getNbOfAgs(); i++) {
// out.println("miner"+(i+1)+" is carrying "+model.getGoldsWithAg(i)+" gold(s), at "+model.getAgPos(i));
@@ -97,17 +100,20 @@
}
}
+ s.append( String.format("%7d ms", cycletime));
+ logger.info(s.toString());
+ out.println(s.toString());
+ out.flush();
+
+
// store the agent'd mind
if (dirmind != null) {
- String agmind = new asl2xml().transform(owner.getTS().getAg().getAgState());
- FileWriter outmind = new FileWriter(new File(dirmind.getName()+"/"+owner.getCycle()+".xml"));
- outmind.write(agmind);
- outmind.close();
+ String agmind = new asl2xml().transform(owner.getTS().getAg().getAgState());
+ FileWriter outmind = new FileWriter(new File(dirmind.getName()+"/"+owner.getCycle()+".xml"));
+ outmind.write(agmind);
+ outmind.close();
}
- logger.info(s.toString());
- out.println(s.toString());
- out.flush();
} catch (InterruptedException e) { // no problem, quit the thread
return;
} catch (Exception e) {
Modified: trunk/applications/jason-team/src/java/test/MindView.java
===================================================================
--- trunk/applications/jason-team/src/java/test/MindView.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/java/test/MindView.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -161,28 +161,23 @@
@SuppressWarnings("unchecked")
private void setupSlider() {
+ int first = -1;
int size = 0;
for (String f: new File("tmp-ag-mind").list()) {
if (f.endsWith(".xml")) {
f = f.substring(0, f.length()-4);
try {
int n = Integer.parseInt(f);
+ if (first < 0)
+ first = n;
if (n > size)
size = n;
} catch (Exception e) { }
}
}
- /*File f = new File("tmp-ag-mind/"+size+".xml");
- while (f.exists()) {
- size++;
- f = new File("tmp-ag-mind/"+size+".xml");
- }
- */
- //Hashtable<Integer,Component> labelTable = new Hashtable<Integer,Component>();
- //labelTable.put( 0, new JLabel("Cycle 0") );
- //labelTable.put( size, new JLabel("Cycle "+size) );
- //jHistory.setLabelTable( labelTable );
+ step = first;
+ jHistory.setMinimum(first);
jHistory.setMaximum(size);
- jHistory.setValue(0);
+ jHistory.setValue(step);
}
}
Modified: trunk/applications/jason-team/src/team-os.xml
===================================================================
--- trunk/applications/jason-team/src/team-os.xml 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/applications/jason-team/src/team-os.xml 2008-05-03 14:16:12 UTC (rev 1285)
@@ -55,9 +55,12 @@
</sub-groups>
<formation-constraints>
- <!--compatibility from="cowboy" to="cowboy" type="compatibility"
+ <compatibility from="explorer" to="herder" type="compatibility"
scope="intra-group" extends-sub-groups="true"
- bi-dir="true"/ -->
+ bi-dir="true"/>
+ <compatibility from="scouter" to="herder" type="herdboy"
+ scope="intra-group" extends-sub-groups="true"
+ bi-dir="true"/>
</formation-constraints>
</group-specification>
</structural-specification>
Modified: trunk/src/jason/asSemantics/IntendedMeans.java
===================================================================
--- trunk/src/jason/asSemantics/IntendedMeans.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/asSemantics/IntendedMeans.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -154,6 +154,7 @@
/** get as XML */
public Element getAsDOM(Document document) {
Element eim = (Element) document.createElement("intended-means");
+ eim.setAttribute("trigger", trigger.toString());
if (plan != null) {
eim.appendChild(plan.getAsDOM(document));
}
Modified: trunk/src/jason/asSyntax/InternalActionLiteral.java
===================================================================
--- trunk/src/jason/asSyntax/InternalActionLiteral.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/asSyntax/InternalActionLiteral.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -30,6 +30,7 @@
import jason.stdlib.loop;
import java.util.Iterator;
+import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -87,6 +88,21 @@
return super.apply(u);
}
+ @Override
+ public void countVars(Map<VarTerm, Integer> c) {
+ super.countVars(c);
+ if (this.ia != null && this.ia instanceof jason.stdlib.wait) {
+ // count the vars of first arg
+ if (getTerm(0).isString()) {
+ try {
+ Trigger te = Trigger.parseTrigger( ((StringTerm)getTerm(0)).getString() );
+ te.getLiteral().countVars(c);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
@SuppressWarnings("unchecked")
public Iterator<Unifier> logicalConsequence(Agent ag, Unifier un) {
Modified: trunk/src/jason/asSyntax/ListTermImpl.java
===================================================================
--- trunk/src/jason/asSyntax/ListTermImpl.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/asSyntax/ListTermImpl.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -87,6 +87,10 @@
return t;
}
+ public ListTermImpl copy() {
+ return (ListTermImpl)clone();
+ }
+
@Override
public boolean equals(Object t) {
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-05-03 14:16:12 UTC (rev 1285)
@@ -202,8 +202,8 @@
( b = belief() { if (a != null) {
if (b.isRule()) {
a.addInitialBel(b);
- if (!parsedFiles.contains(asSource))
- logger.warning(getSourceRef(b)+" warning: avoid to mix rules and plans ('"+b+"').");
+ //if (!parsedFiles.contains(asSource))
+ // logger.warning(getSourceRef(b)+" warning: avoid to mix rules and plans ('"+b+"').");
} else {
throw new ParseException(getSourceRef(b)+" The belief '"+b+"' is not in the begin of the source code!");
}
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -203,8 +203,8 @@
if (a != null) {
if (b.isRule()) {
a.addInitialBel(b);
- if (!parsedFiles.contains(asSource))
- logger.warning(getSourceRef(b)+" warning: avoid to mix rules and plans ('"+b+"').");
+ //if (!parsedFiles.contains(asSource))
+ // logger.warning(getSourceRef(b)+" warning: avoid to mix rules and plans ('"+b+"').");
} else {
{if (true) throw new ParseException(getSourceRef(b)+" The belief '"+b+"' is not in the begin of the source code!");}
}
Modified: trunk/src/jason/asSyntax/patterns/goal/EBDG.java
===================================================================
--- trunk/src/jason/asSyntax/patterns/goal/EBDG.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/asSyntax/patterns/goal/EBDG.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -73,7 +73,7 @@
return newAg;
} catch (Exception e) {
- logger.log(Level.SEVERE,"Directive DG error.", e);
+ logger.log(Level.SEVERE,"Directive EBDG error.", e);
}
return null;
}
Modified: trunk/src/jason/stdlib/delete.java
===================================================================
--- trunk/src/jason/stdlib/delete.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/stdlib/delete.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -41,7 +41,7 @@
<p>Description: delete elements of strings or lists.
<p>Parameters:<ul>
- <li>+ arg[0] (term, string, or number): if term, this arg is the element to be removed in the list (all ocurrences of the element will be removed);
+ <li>+ arg[0] (term, string, or number): if term, this arg is the element to be removed in the list (all occurrences of the element will be removed);
if string, this arg is the substring to be removed (the second arg should be a string);
if number, this arg is the position in the list/string of the element/character to be removed.<br/>
<li>+ arg[1] (list or string): the list/string where to delete.
@@ -94,7 +94,7 @@
// first element as term
if (args[1].isList()) {
- return un.unifies(args[2], deleteFromList(args[0],(ListTerm)args[1]));
+ return un.unifies(args[2], deleteFromList(args[0],(ListTerm)args[1], un.copy()));
}
throw new JasonException("Incorrect use of the internal action '.delete' (see documentation).");
} catch (ArrayIndexOutOfBoundsException e) {
@@ -104,11 +104,15 @@
}
}
- ListTerm deleteFromList(Term element, ListTerm l) {
+ ListTerm deleteFromList(Term element, ListTerm l, Unifier un) {
+ Unifier bak = un;
ListTerm r = new ListTermImpl();
ListTerm last = r;
for (Term t: l) {
- if (!t.equals(element))
+ boolean u = un.unifies(element, t);
+ if (u)
+ un = bak.copy();
+ else
last = last.append(t);
}
return r;
Modified: trunk/src/jason/stdlib/drop_desire.java
===================================================================
--- trunk/src/jason/stdlib/drop_desire.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/stdlib/drop_desire.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -88,7 +88,7 @@
Trigger te = new Trigger(TEOperator.add, TEType.achieve, l);
Iterator<Event> ie = C.getEvents().iterator();
while (ie.hasNext()) {
- Event ei = ie.next();
+ Event ei = ie.next();
Trigger t = ei.getTrigger();
if (ei.getIntention() != Intention.EmptyInt) {
t = (Trigger) t.clone();
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/stdlib/package.html 2008-05-03 14:16:12 UTC (rev 1285)
@@ -23,6 +23,8 @@
<li>{@link jason.stdlib.succeed_goal}: abort some goal with success.</li>
<li>{@link jason.stdlib.fail_goal}: abort some goal with failure.</li>
+ <li>{@link jason.stdlib.suspend}: suspend intentions.</li>
+ <li>{@link jason.stdlib.resume}: resume suspended intentions.</li>
</ul>
<h2>Belief base</h2>
@@ -57,6 +59,7 @@
<li>{@link jason.stdlib.length}: size of lists. </li>
<li>{@link jason.stdlib.concat}: concat lists. </li>
+ <li>{@link jason.stdlib.delete}: delete members of a lists. </li>
<li>{@link jason.stdlib.difference}: difference of sets. </li>
<li>{@link jason.stdlib.intersection}: intersection of sets. </li>
@@ -75,6 +78,7 @@
<ul>
<li>{@link jason.stdlib.length}: size of strings. </li>
<li>{@link jason.stdlib.concat}: append strings. </li>
+ <li>{@link jason.stdlib.delete}: delete characters of a string. </li>
<li>{@link jason.stdlib.reverse}: reverse strings. </li>
<li>{@link jason.stdlib.substring}: test substrings of strings. </li>
<li>{@link jason.stdlib.string}: check whether an argument is a string.</li>
Modified: trunk/src/jason/stdlib/resume.java
===================================================================
--- trunk/src/jason/stdlib/resume.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/stdlib/resume.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -78,6 +78,11 @@
if (i.hasTrigger(g, un)) {
i.setSuspended(false);
ik.remove();
+
+ // remove the IA .suspend in case of self-suspend
+ if (k.equals(suspend.SELF_SUSPENDED_INT)) {
+ i.peek().removeCurrentStep();
+ }
// add it back in I if not in PA
if (! C.getPendingActions().containsKey(i.getId())) {
Modified: trunk/src/jason/stdlib/suspend.java
===================================================================
--- trunk/src/jason/stdlib/suspend.java 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/jason/stdlib/suspend.java 2008-05-03 14:16:12 UTC (rev 1285)
@@ -47,9 +47,10 @@
is a goal if there is a triggering event <code>+!G</code> in any plan within
any intention in I, E, PI, or PA.
- <p>Example:<ul>
+ <p>Examples:<ul>
<li> <code>.suspend(go(1,3))</code>: suspends intentions to go to the location 1,3.
+ <li> <code>.suspend</code>: suspends the current intention.
</ul>
@@ -69,17 +70,32 @@
public class suspend extends DefaultInternalAction {
boolean suspendIntention = false;
- public static final String SUSPENDED_INT = "suspended-";
+ public static final String SUSPENDED_INT = "suspended-";
+ public static final String SELF_SUSPENDED_INT = SUSPENDED_INT+"self";
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
+ suspendIntention = false;
+
+ Circumstance C = ts.getC();
+
+ if (args.length == 0) {
+ // suspend the current intention
+ Intention i = C.getSelectedIntention();
+ suspendIntention = true;
+ i.setSuspended(true);
+ //i.peek().removeCurrentStep();
+ C.getPendingIntentions().put(SELF_SUSPENDED_INT, i); //
+
+ return true;
+ }
+
+ // use the argument to select the intention to suspend.
+
Trigger g = new Trigger(TEOperator.add, TEType.achieve, (Literal)args[0]);
- Circumstance C = ts.getC();
String k = SUSPENDED_INT+g.getLiteral();
- suspendIntention = false;
-
// ** Must test in PA/PI first since some actions (as .suspend) put intention in PI
// suspending from Pending Actions
@@ -106,16 +122,16 @@
}
}
- // dropping the current intention?
+ // suspending the current intention?
Intention i = C.getSelectedIntention();
if (i.hasTrigger(g, un)) {
suspendIntention = true;
i.setSuspended(true);
- i.peek().removeCurrentStep();
- C.getPendingIntentions().put(k, i);
+ //i.peek().removeCurrentStep();
+ C.getPendingIntentions().put(SELF_SUSPENDED_INT, i);
}
- // dropping G in Events
+ // suspending G in Events
for (Event e: C.getEvents()) {
i = e.getIntention();
if ( i != null &&
@@ -132,7 +148,7 @@
return true;
} catch (ArrayIndexOutOfBoundsException e) {
- throw new JasonException("The internal action 'suspend' has not received one argument.");
+ throw new JasonException("The internal action 'suspend' has not received one argument.", e);
} catch (Exception e) {
throw new JasonException("Error in internal action 'suspend': " + e, e);
}
Modified: trunk/src/xml/agInspection.xsl
===================================================================
--- trunk/src/xml/agInspection.xsl 2008-05-02 11:55:00 UTC (rev 1284)
+++ trunk/src/xml/agInspection.xsl 2008-05-03 14:16:12 UTC (rev 1285)
@@ -269,17 +269,21 @@
<xsl:template match="intended-means">
<tr>
<td valign="top" style="{$td-style}">
+ <xsl:apply-templates select="@trigger"/>
<xsl:if test="$show-int-details='true'">
+ <!-- td valign="top" style="{$td-style}" -->
+ <br/>
<xsl:apply-templates select="plan"/>
+ <!-- /td -->
</xsl:if>
- <xsl:if test="$show-int-details='false'">
- <xsl:apply-templates select="plan/trigger"/>
+ </td>
+
+ <xsl:if test="$show-int-details='true'">
+ <td valign="top" style="{$td-style}">
+ <xsl:text> </xsl:text><xsl:text> </xsl:text>
+ <xsl:apply-templates select="unifier"/>
+ </td>
</xsl:if>
- </td>
- <td valign="top" style="{$td-style}">
- <xsl:text> </xsl:text><xsl:text> </xsl:text>
- <xsl:apply-templates select="unifier"/>
- </td>
</tr>
</xsl:template>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|