From: <jom...@us...> - 2008-10-15 17:38:45
|
Revision: 1396 http://jason.svn.sourceforge.net/jason/?rev=1396&view=rev Author: jomifred Date: 2008-10-15 16:38:37 +0000 (Wed, 15 Oct 2008) Log Message: ----------- change the OrgArch to update some bels Modified Paths: -------------- trunk/applications/jason-moise/build.xml trunk/applications/jason-moise/example/auction/orgAuction.mas2j trunk/applications/jason-moise/example/writePaper/writePaper.mas2j trunk/applications/jason-moise/lib/moise.jar trunk/applications/jason-moise/src/jmoise/OrgAgent.java trunk/applications/jason-moise/src/jmoise/OrgManager.java trunk/src/jason/asSyntax/SourceInfo.java trunk/src/templates/build-template.xml trunk/src/test/MAS2JParserTest.java Modified: trunk/applications/jason-moise/build.xml =================================================================== --- trunk/applications/jason-moise/build.xml 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/applications/jason-moise/build.xml 2008-10-15 16:38:37 UTC (rev 1396) @@ -9,7 +9,7 @@ <property name="version" value="1"/> <property name="release" value="1.2"/> - <property name="moiseDir" value="${env.HOME}/svn-moise" /> + <property name="moiseDir" value="${env.HOME}/Moise/svn-moise" /> <property name="distDir" value="${env.HOME}/tmp/jmoise-${version}.${release}" /> <property name="distFile" value="${env.HOME}/jason-moise-${version}.${release}" /> <property name="doc-src-dir" value="${env.HOME}/programming/Moise-doc" /> Modified: trunk/applications/jason-moise/example/auction/orgAuction.mas2j =================================================================== --- trunk/applications/jason-moise/example/auction/orgAuction.mas2j 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/applications/jason-moise/example/auction/orgAuction.mas2j 2008-10-15 16:38:37 UTC (rev 1396) @@ -9,7 +9,7 @@ MAS auction { infrastructure: Centralised agents: - orgManager [osfile="auction-os.xml",gui=no] + orgManager [osfile="auction-os.xml",gui=yes] agentArchClass jmoise.OrgManager; bob auctioneer agentArchClass jmoise.OrgAgent; Modified: trunk/applications/jason-moise/example/writePaper/writePaper.mas2j =================================================================== --- trunk/applications/jason-moise/example/writePaper/writePaper.mas2j 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/applications/jason-moise/example/writePaper/writePaper.mas2j 2008-10-15 16:38:37 UTC (rev 1396) @@ -1,7 +1,7 @@ MAS write_paper { infrastructure: Centralised agents: - orgManager [osfile="wp-os.xml",gui=no] + orgManager [osfile="wp-os.xml",gui=yes] agentArchClass jmoise.OrgManager; jaime agentArchClass jmoise.OrgAgent; Modified: trunk/applications/jason-moise/lib/moise.jar =================================================================== (Binary files differ) Modified: trunk/applications/jason-moise/src/jmoise/OrgAgent.java =================================================================== --- trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-10-15 16:38:37 UTC (rev 1396) @@ -105,6 +105,7 @@ // check if content is and OE if (m.getPropCont() instanceof OE) { currentOE = (OE) m.getPropCont(); + updateBB(); i.remove(); } else if (m.getSender().equals(getOrgManagerName())) { // the content is a normal predicate @@ -181,6 +182,25 @@ logger.log(Level.SEVERE, "Error!", e); } } + + /** update the bel base according to the current OE */ + void updateBB() throws RevisionFailedException { + Agent ag = getTS().getAg(); + // add players + for (RolePlayer myrole: getMyOEAgent().getRoles()) { // for all my groups + for (RolePlayer rp: myrole.getGroup().getPlayers()) { // for player of the group I play some role + Literal l = rolePlayer2literal(rp); + l.addAnnot(managerSource); + ag.addBel(l); + } + } + // remove old players + } + + Literal rolePlayer2literal(RolePlayer rp) { + return ASSyntax.createLiteral("play", new Atom(rp.getPlayer().getId()), new Atom(rp.getRole().getId()), new Atom(rp.getGroup().getId())); + } + private Literal addAsBel(String b) throws RevisionFailedException { Literal l = Literal.parseLiteral(b); Modified: trunk/applications/jason-moise/src/jmoise/OrgManager.java =================================================================== --- trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-10-15 16:38:37 UTC (rev 1396) @@ -191,20 +191,26 @@ sender.adoptRole(roleId, grId); GroupInstance gr = currentOE.findGroup(grId); + // send new OE to the members of the group + updateMembersOE(gr.getAgents(true), null, true, true); + + /* // notify others in the group about this new player - updateMembersOE(gr.getAgents(true), "play(" + sender + "," + roleId + "," + grId + ")", true, true); + updateMembersOE(gr.getAgents(true), rolePlayer2str(nrp), true, true); // send players of the group to the sender for (RolePlayer rp : gr.getPlayers(null, true)) { if (!rp.getPlayer().equals(sender)) { - updateMembersOE(sender, "play(" + rp.getPlayer().getId() + "," + rp.getRole().getId() + "," + grId + ")", false, true); + updateMembersOE(sender, rolePlayer2str(rp), false, true); } } + */ // send schemes of this group to sender for (SchemeInstance sch : gr.getRespSchemes()) { updateMembersOE(sender, "scheme_group(" + sch.getId() + "," + grId + ")", false, true); } + sendReply(sender, mId, "ok"); } } @@ -217,11 +223,11 @@ String roleId = command.getTerm(0).toString(); String grId = command.getTerm(1).toString(); - sender.removeRole(roleId, grId); + RolePlayer orp = sender.removeRole(roleId, grId); GroupInstance gr = currentOE.findGroup(grId); // notify other players - updateMembersOE(gr.getAgents(true), "play(" + sender + "," + roleId + "," + grId + ")", false, false); + updateMembersOE(gr.getAgents(true), rolePlayer2str(orp), false, false); // and the sender updateMembersOE(sender, "play(" + sender + "," + roleId + "," + grId + ")", true, false); @@ -229,7 +235,7 @@ // 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); + updateMembersOE(sender, rolePlayer2str(rp), false, false); } for (SchemeInstance sch : gr.getRespSchemes()) { updateMembersOE(sender, "scheme_group(" + sch.getId() + "," + grId + ")", false, false); @@ -246,17 +252,17 @@ public void process(OE currentOE, Pred command, OEAgent sender, String mId) throws MoiseException { String misId = command.getTerm(0).toString(); String schId = command.getTerm(1).toString(); - sender.commitToMission(misId, schId); + MissionPlayer nmp = sender.commitToMission(misId, schId); SchemeInstance sch = currentOE.findScheme(schId); // notify to the scheme players the new player - updateMembersOE(sch.getPlayers(), "commitment(" + sender + "," + misId + "," + sch.getId() + ")", true, true); + updateMembersOE(sch.getPlayers(), missionPlayer2str(nmp), true, true); // notify to the sender the other commitments of the scheme for (MissionPlayer mp : sch.getPlayers()) { if (!mp.getPlayer().equals(sender)) { - updateMembersOE(sender, "commitment(" + mp.getPlayer().getId() + "," + mp.getMission().getId() + "," + sch.getId() + ")", false, true); + updateMembersOE(sender, missionPlayer2str(mp), false, true); } } @@ -290,7 +296,7 @@ MissionPlayer mp = mpi.next(); sender.removeMission(mp.getMission().getId(), schId); mpi = sender.getMissions().iterator(); - String evUnCom = "commitment(" + sender + "," + mp.getMission().getId() + "," + sch.getId() + ")"; + String evUnCom = missionPlayer2str(mp); updateMembersOE(sch.getPlayers(), evUnCom, false, false); //if (!sch.isPlayer(sender)) { updateMembersOE(sender, evUnCom, false, false); @@ -298,8 +304,8 @@ } } else { sch = currentOE.findScheme(schId); - sender.removeMission(misId, schId); - String evUnCom = "commitment(" + sender + "," + misId + "," + sch.getId() + ")"; + MissionPlayer omp = sender.removeMission(misId, schId); + String evUnCom = missionPlayer2str(omp); updateMembersOE(sender, evUnCom, false, false); //if (!sch.isPlayer(sender)) { updateMembersOE(sch.getPlayers(), evUnCom, false, false); @@ -323,7 +329,6 @@ public void process(OE currentOE, Pred command, OEAgent sender, String mId) throws MoiseException { boolean isNewRoot = command.getArity() == 1; GroupInstance newGr; - String annot = "root"; String specId = command.getTerm(0).toString(); if (isNewRoot) { newGr = currentOE.addGroup(specId); @@ -335,15 +340,15 @@ return; } newGr = superGr.addSubGroup(specId); - annot = "super_gr(" + superGr.getId() + ")"; } newGr.setOwner(sender); - updateMembersOE(currentOE.getAgents(), "group(" + specId + "," + newGr.getId() + ")[owner(" + sender + ")," + annot + "]", false, true); + updateMembersOE(currentOE.getAgents(), group2str(newGr), false, true); sendReply(sender, mId, newGr.getId()); } } + class RemoveGroup implements OrgManagerCommand { public String getId() { return "remove_group"; @@ -367,19 +372,19 @@ } // untell players for (RolePlayer rp: gr.getPlayers()) { - updateMembersOE(gr.getAgents(true), "play(" + rp.getPlayer().getId() + "," + rp.getRole().getId() + "," + gr.getId() + ")", false, false); + updateMembersOE(gr.getAgents(true), rolePlayer2str(rp), false, false); } // send changes for subgroups of gr for (GroupInstance sg: gr.getAllSubGroupsTree()) { - updateMembersOE(currentOE.getAgents(), "group(" + sg.getGrSpec().getId() + "," + sg.getId() + ")", false, false); + updateMembersOE(currentOE.getAgents(), group2str(sg), false, false); // also send untell scheme_group (if it is the case) for (SchemeInstance sch: sg.getRespSchemes()) { updateMembersOE(sg.getPlayers(), "scheme_group(" + sch.getId() + "," + sg.getId() + ")", false, false); } // untell players for (RolePlayer rp: sg.getPlayers()) { - updateMembersOE(sg.getAgents(true), "play(" + rp.getPlayer().getId() + "," + rp.getRole().getId() + "," + sg.getId() + ")", false, false); + updateMembersOE(sg.getAgents(true), rolePlayer2str(rp), false, false); } } @@ -387,7 +392,7 @@ currentOE.removeGroup(grId); // sent a new copy of OE - updateMembersOE(currentOE.getAgents(), "group(" + gr.getGrSpec().getId() + "," + gr.getId() + ")", true, false); + updateMembersOE(currentOE.getAgents(), group2str(gr), true, false); sendReply(sender, mId, "ok"); } } @@ -402,9 +407,14 @@ // send created groups for (GroupInstance gr: currentOE.getGroups()) { - updateMembersOE(sender, "group(" + gr.getGrSpec().getId() + "," + gr.getId() + ")[owner(" + gr.getOwner().getId() + ")]", false, true); + sendGr(sender, gr); } } + private void sendGr(OEAgent to, GroupInstance gr) { + updateMembersOE(to, group2str(gr), false, true); + for (GroupInstance sg: gr.getSubGroups()) + sendGr(to, sg); + } } class CreateScheme implements OrgManagerCommand { @@ -415,7 +425,7 @@ String schSpecId = command.getTerm(0).toString(); SchemeInstance sch = currentOE.startScheme(schSpecId.toString()); sch.setOwner(sender); - updateMembersOE(currentOE.getAgents(), "scheme(" + schSpecId + "," + sch.getId() + ")[owner(" + sender + ")]", true, true); + updateMembersOE(currentOE.getAgents(), scheme2str(sch), true, true); if (command.getArity() > 1) { // set the initial groups @@ -480,7 +490,7 @@ act(currentOE, sch); // send untell to agents - updateMembersOE(currentOE.getAgents(), "scheme(" + sch.getSpec().getId() + "," + sch.getId() + ")[owner(" + sch.getOwner() + ")]", false, false); + updateMembersOE(currentOE.getAgents(), scheme2str(sch), false, false); sendReply(sender, mId, "ok"); } protected void act(OE currentOE, SchemeInstance sch) throws MoiseException { @@ -573,6 +583,26 @@ } } + String group2str(GroupInstance gr) { + String sga = "root"; + if (gr.getSuperGroup() != null) + sga = "super_gr("+gr.getSuperGroup().getId()+")"; + return "group(" + gr.getGrSpec().getId() + "," + gr.getId() + ")[owner(" + gr.getOwner().getId() +"),"+sga+"]"; + } + + String rolePlayer2str(RolePlayer rp) { + return "play(" + rp.getPlayer().getId() + "," + rp.getRole().getId() + "," + rp.getGroup().getId() + ")"; + } + + String scheme2str(SchemeInstance sch) { + return "scheme(" + sch.getSpec().getId() + "," + sch.getId() + ")[owner(" + sch.getOwner().getId() + ")]"; + } + + String missionPlayer2str(MissionPlayer mp) { + return "commitment(" + mp.getPlayer().getId() + "," + mp.getMission().getId() + "," + mp.getScheme().getId() + ")"; + } + + void sendReply(OEAgent to, String mId, String content) { try { Message r = new Message("tell", null, to.getId(), content); Modified: trunk/src/jason/asSyntax/SourceInfo.java =================================================================== --- trunk/src/jason/asSyntax/SourceInfo.java 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/src/jason/asSyntax/SourceInfo.java 2008-10-15 16:38:37 UTC (rev 1396) @@ -1,10 +1,12 @@ package jason.asSyntax; +import java.io.Serializable; + /** * Store information about the file source of some term (atom, literal, etc). * (immutable objects) */ -public class SourceInfo { +public class SourceInfo implements Serializable { private final String source; private final int beginSrcLine; // the line this literal appears in the source Modified: trunk/src/templates/build-template.xml =================================================================== --- trunk/src/templates/build-template.xml 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/src/templates/build-template.xml 2008-10-15 16:38:37 UTC (rev 1396) @@ -90,7 +90,7 @@ failonerror="true" fork="yes" dir="${basedir}" > <classpath refid="project.classpath"/> <arg line="${mas2j.project.file} ${debug} <RUN-ARGS>"/> - <jvmarg line="-Xmx750M"/> + <jvmarg line="-Xmx500M"/> </java> <antcall target="user-end" /> </target> Modified: trunk/src/test/MAS2JParserTest.java =================================================================== --- trunk/src/test/MAS2JParserTest.java 2008-10-15 13:50:49 UTC (rev 1395) +++ trunk/src/test/MAS2JParserTest.java 2008-10-15 16:38:37 UTC (rev 1396) @@ -2,7 +2,9 @@ import jason.asSyntax.Literal; import jason.bb.ChainBB; +import jason.mas2j.ClassParameters; import jason.mas2j.MAS2JProject; +import jason.mas2j.parser.ParseException; import jason.mas2j.parser.mas2j; import java.io.StringReader; @@ -81,5 +83,11 @@ bb.add(Literal.parseLiteral("b(1)")); } - + public void testClassDef() throws ParseException { + String archClass = "my.Arch(test)"; + mas2j parser = new mas2j(new StringReader(archClass)); + ClassParameters c = parser.classDef(); + assertEquals("my.Arch", c.getClassName()); + assertEquals(1,c.getParametersArray().length); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |