|
From: <jom...@us...> - 2008-10-20 19:08:11
|
Revision: 1399
http://jason.svn.sourceforge.net/jason/?rev=1399&view=rev
Author: jomifred
Date: 2008-10-20 19:08:01 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
improve OrgArch for jason-moise
Modified Paths:
--------------
trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java
trunk/applications/jason-moise/example/moise-tutorial/tutorial.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/applications/jason-team/todo.org
trunk/demos/persistent-belief-base/VoidBB.java
trunk/src/jason/bb/BeliefBase.java
trunk/src/jason/bb/ChainBBAdapter.java
trunk/src/jason/bb/DefaultBeliefBase.java
Modified: trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java 2008-10-20 19:08:01 UTC (rev 1399)
@@ -47,10 +47,20 @@
JTextField args = new JTextField(30);
JFrame frame;
- String[][] actions = { { "create_group", "spec [,superGrId]" },
- { "remove_group", "groupID" },
- { "adopt_role", "role,groupId" },
- { "remove_role", "role,groupId" }
+ String[][] actions = { { "create_group", "g1,wpgroup" },
+ { "remove_group", "g1" },
+ { "adopt_role", "editor,g1" },
+ { "adopt_role", "writer,g1" },
+ { "remove_role", "role,groupId" },
+ { "create_scheme", "p1, writePaperSch, [g1]" },
+ { "abort_scheme", "schemeId" },
+ { "remove_scheme", "schemeId" },
+ { "add_responsible_group", "schemeId, groupId" },
+ { "commit_mission", "mManager, p1" },
+ { "commit_mission", "mColaborator, p1" },
+ { "commit_mission", "mBib, p1" },
+ { "remove_mission", "[missionId,] SchemeId" },
+ { "set_goal_state", "p1, goalId, state" }
};
protected void startGUI() {
@@ -96,11 +106,25 @@
}
});
+
+ JButton listBT = new JButton("Update Beliefs");
+ listBT.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ listBels();
+ }
+ });
+ }
+ });
+
+
JPanel control = new JPanel(new FlowLayout());
control.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Actions", TitledBorder.LEFT, TitledBorder.TOP));
control.add(actionsCB);
control.add(args);
control.add(doBT);
+ control.add(listBT);
frame = new JFrame(":: "+getAgName()+" interface ::");
Modified: trunk/applications/jason-moise/example/moise-tutorial/tutorial.mas2j
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/tutorial.mas2j 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/applications/jason-moise/example/moise-tutorial/tutorial.mas2j 2008-10-20 19:08:01 UTC (rev 1399)
@@ -1,7 +1,7 @@
MAS write_paper {
infrastructure: Centralised
agents:
- orgManager [osfile="jojOS.xml",gui=yes]
+ orgManager [osfile="../writePaper/wp-os.xml",gui=yes] // jojOS
agentArchClass jmoise.OrgManager;
marcos agentArchClass gui.OrgAgentGUI;
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-20 14:12:34 UTC (rev 1398)
+++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-10-20 19:08:01 UTC (rev 1399)
@@ -1,5 +1,6 @@
package jmoise;
+import static jason.asSyntax.ASSyntax.*;
import jason.JasonException;
import jason.RevisionFailedException;
import jason.architecture.AgArch;
@@ -31,6 +32,7 @@
import jason.runtime.Settings;
import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -182,26 +184,74 @@
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
+
+ // update "play"
+ List<Literal> toAdd = new ArrayList<Literal>();
+
+ // create list of groups
+ for (GroupInstance gi: currentOE.getAllSubGroupsTree()) {
+ Term typeAnnot;
+ if (gi.getSuperGroup() != null)
+ typeAnnot = createStructure("super_gr", new Atom(gi.getSuperGroup().getId()));
+ else
+ typeAnnot = new Atom("root");
+ Literal l = createLiteral("group", new Atom(gi.getGrSpec().getId()), new Atom(gi.getId()));
+ l.addAnnots(createStructure("owner", new Atom(gi.getOwner().getId())), typeAnnot, managerSource);
+ toAdd.add(l);
+ }
+ orgBUF(toAdd, groupLiteral);
+
+ // create list of players
+ toAdd.clear();
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);
+ Literal l = createLiteral("play", new Atom(rp.getPlayer().getId()), new Atom(rp.getRole().getId()), new Atom(rp.getGroup().getId()));
l.addAnnot(managerSource);
- ag.addBel(l);
+ toAdd.add(l);
}
- }
- // remove old players
- }
+ }
+ orgBUF(toAdd, playLiteral);
- Literal rolePlayer2literal(RolePlayer rp) {
- return ASSyntax.createLiteral("play", new Atom(rp.getPlayer().getId()), new Atom(rp.getRole().getId()), new Atom(rp.getGroup().getId()));
}
-
+ private void orgBUF(List<Literal> toAdd, PredicateIndicator bel) throws RevisionFailedException {
+ try {
+ Agent ag = getTS().getAg();
+ List<Literal> toDel = new ArrayList<Literal>();
+
+ // remove old bels
+ Iterator<Literal> i = ag.getBB().getCandidateBeliefs(bel);
+ if (i != null) {
+ while (i.hasNext()) {
+ Literal l = i.next();
+
+ // if this play in not in the add list, it should be removed
+ boolean isInOE = false;
+ for (Literal p: toAdd) {
+ if (p.equalsAsStructure(l)) {
+ isInOE = true;
+ break;
+ }
+ }
+ if (!isInOE) {
+ toDel.add(l);
+ }
+ }
+ }
+ for (Literal l: toDel)
+ ag.delBel(l);
+
+ // add new players
+ for (Literal l: toAdd)
+ ag.addBel(l);
+ } catch (ConcurrentModificationException e) {}
+ }
+
+
private Literal addAsBel(String b) throws RevisionFailedException {
Literal l = Literal.parseLiteral(b);
l.addAnnot(managerSource);
@@ -371,6 +421,9 @@
}
}
+ private static final PredicateIndicator groupLiteral = new PredicateIndicator("group", 2);
+ private static final PredicateIndicator playLiteral = new PredicateIndicator("play", 3);
+
private static final PredicateIndicator obligationLiteral = new PredicateIndicator("obligation", 2);
private static final PredicateIndicator permissionLiteral = new PredicateIndicator("permission", 2);
private static final PredicateIndicator schemeGroupLiteral = new PredicateIndicator("scheme_group", 2);
Modified: trunk/applications/jason-moise/src/jmoise/OrgManager.java
===================================================================
--- trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/applications/jason-moise/src/jmoise/OrgManager.java 2008-10-20 19:08:01 UTC (rev 1399)
@@ -26,7 +26,6 @@
import moise.oe.OE;
import moise.oe.OEAgent;
import moise.oe.Player;
-import moise.oe.RolePlayer;
import moise.oe.SchemeInstance;
import moise.tools.SimOE;
@@ -223,20 +222,27 @@
String roleId = command.getTerm(0).toString();
String grId = command.getTerm(1).toString();
- RolePlayer orp = sender.removeRole(roleId, grId);
+ sender.removeRole(roleId, grId);
GroupInstance gr = currentOE.findGroup(grId);
// notify other players
+ updateMembersOE(gr.getAgents(true), null, true, false);
+ // and the sender (that is not in the group anymore)
+ updateMembersOE(sender, null, true, false);
+
+ /*
+ // notify other players
updateMembersOE(gr.getAgents(true), rolePlayer2str(orp), 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()) {
+ /*for (RolePlayer rp : gr.getPlayers()) {
updateMembersOE(sender, rolePlayer2str(rp), false, false);
- }
+ }*/
for (SchemeInstance sch : gr.getRespSchemes()) {
updateMembersOE(sender, "scheme_group(" + sch.getId() + "," + grId + ")", false, false);
}
@@ -343,7 +349,8 @@
}
newGr.setOwner(sender);
- updateMembersOE(currentOE.getAgents(), group2str(newGr), false, true);
+ //updateMembersOE(currentOE.getAgents(), group2str(newGr), false, true);
+ updateMembersOE(currentOE.getAgents(), null, true, true);
sendReply(sender, mId, newGr.getId());
}
}
@@ -364,35 +371,41 @@
sendReply(sender, mId, "error(\"you are not the owner of the group " + grId + ", so you can not remove it\")");
}
- gr.checkRemove();
+ gr.checkRemove(); // TODO: does not work!
// also send untell scheme_group (if it is the case)
for (SchemeInstance sch: gr.getRespSchemes()) {
updateMembersOE(gr.getPlayers(), "scheme_group(" + sch.getId() + "," + grId + ")", false, false);
}
+
+ /*
// untell players
for (RolePlayer rp: gr.getPlayers()) {
updateMembersOE(gr.getAgents(true), rolePlayer2str(rp), false, false);
}
+ */
// send changes for subgroups of gr
for (GroupInstance sg: gr.getAllSubGroupsTree()) {
- updateMembersOE(currentOE.getAgents(), group2str(sg), 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), rolePlayer2str(rp), false, false);
}
+ */
}
// have to remove after sending the untells
currentOE.removeGroup(grId);
// sent a new copy of OE
- updateMembersOE(currentOE.getAgents(), group2str(gr), true, false);
+ //updateMembersOE(currentOE.getAgents(), group2str(gr), true, false);
+ updateMembersOE(currentOE.getAgents(), null, true, true);
sendReply(sender, mId, "ok");
}
}
@@ -404,17 +417,20 @@
public void process(OE currentOE, Pred command, OEAgent sender, String mId) throws MoiseException {
// send new OE to all
updateMembersOE(currentOE.getAgents(), null, true, true);
-
+ /*
// send created groups
for (GroupInstance gr: currentOE.getGroups()) {
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 {
@@ -484,7 +500,7 @@
return;
}
- if (sch.getSpec().getFS().getBoolProperty("only-owner-can-remove-scheme") && !sender.equals(sch.getOwner())) {
+ if (sch.getSpec().getFS().getBoolProperty("only-owner-can-remove-scheme", true) && !sender.equals(sch.getOwner())) {
sendReply(sender, mId, "error(\"you are not the owner of the scheme " + schId + ", so you can not change it\")");
}
@@ -583,6 +599,7 @@
}
}
+ /*
String group2str(GroupInstance gr) {
String sga = "root";
if (gr.getSuperGroup() != null)
@@ -590,9 +607,11 @@
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() + ")]";
Modified: trunk/applications/jason-team/todo.org
===================================================================
--- trunk/applications/jason-team/todo.org 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/applications/jason-team/todo.org 2008-10-20 19:08:01 UTC (rev 1399)
@@ -1,19 +1,24 @@
-* team formations (moise+ representation of the team)
+* 2009 team
+** communication link is intra-group
+** leaders group
+** merging scheme
+* 2008 team
+** team formations (moise+ representation of the team)
** Structure (we have something from the proposal)
** Functioning (we have noting, but I not sure we need...)
** computation of ideal locations of an agent to maintain a formation (can we use maintainance goal pattern?)
-* herding strategy
-* exploration strategy
-* protocols
-* faster simulator
-* DONE new scenarios
-* DONE Vectors (operations)
- CLOSED: [2008-04-20 Sun 22:23]
-* DONE develop a team of dummies to play against
- CLOSED: [2008-04-20 Sun 22:23]
+** herding strategy
+** exploration strategy
+** protocols
+** faster simulator
+** DONE new scenarios
+** DONE Vectors (operations)
+ CLOSED: [2008-04-20 Sun 22:23]
+** DONE develop a team of dummies to play against
+ CLOSED: [2008-04-20 Sun 22:23]
** what is a dummy strategy?
-* DONE A* (update previous to new directions)
- CLOSED: [2008-03-16 Sun 15:29]
-* DONE integration with new simulator
- CLOSED: [2008-03-16 Sun 15:28]
- add perceptions to the agents
+** DONE A* (update previous to new directions)
+ CLOSED: [2008-03-16 Sun 15:29]
+** DONE integration with new simulator
+ CLOSED: [2008-03-16 Sun 15:28]
+ add perceptions to the agents
Modified: trunk/demos/persistent-belief-base/VoidBB.java
===================================================================
--- trunk/demos/persistent-belief-base/VoidBB.java 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/demos/persistent-belief-base/VoidBB.java 2008-10-20 19:08:01 UTC (rev 1399)
@@ -56,6 +56,10 @@
return true;
}
+ public Iterator<Literal> getCandidateBeliefs(PredicateIndicator pi) {
+ return new ArrayList<Literal>().iterator();
+ }
+
public Iterator<Literal> getCandidateBeliefs(Literal l, Unifier u) {
return new ArrayList<Literal>().iterator();
}
Modified: trunk/src/jason/bb/BeliefBase.java
===================================================================
--- trunk/src/jason/bb/BeliefBase.java 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/src/jason/bb/BeliefBase.java 2008-10-20 19:08:01 UTC (rev 1399)
@@ -82,6 +82,12 @@
public Iterator<Literal> getAll();
/**
+ * Returns an iterator for all literals in BB that match the functor/arity
+ * of the parameter.<br>
+ */
+ public Iterator<Literal> getCandidateBeliefs(PredicateIndicator pi);
+
+ /**
* Returns an iterator for all literals relevant for l's predicate
* indicator, if l is a var, returns all beliefs.<br>
*
Modified: trunk/src/jason/bb/ChainBBAdapter.java
===================================================================
--- trunk/src/jason/bb/ChainBBAdapter.java 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/src/jason/bb/ChainBBAdapter.java 2008-10-20 19:08:01 UTC (rev 1399)
@@ -110,6 +110,10 @@
return nextBB.iterator();
}
+ public Iterator<Literal> getCandidateBeliefs(PredicateIndicator pi) {
+ return nextBB.getCandidateBeliefs(pi);
+ }
+
public Iterator<Literal> getCandidateBeliefs(Literal l, Unifier u) {
return nextBB.getCandidateBeliefs(l, u);
}
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeliefBase.java 2008-10-20 14:12:34 UTC (rev 1398)
+++ trunk/src/jason/bb/DefaultBeliefBase.java 2008-10-20 19:08:01 UTC (rev 1399)
@@ -229,17 +229,24 @@
}
}
+ public Iterator<Literal> getCandidateBeliefs(PredicateIndicator pi) {
+ BelEntry entry = belsMap.get(pi);
+ if (entry != null)
+ return Collections.unmodifiableList(entry.list).iterator();
+ else
+ return null;
+ }
+
public Iterator<Literal> getCandidateBeliefs(Literal l, Unifier u) {
if (l.isVar()) {
// all bels are relevant
return iterator();
} else {
BelEntry entry = belsMap.get(l.getPredicateIndicator());
- if (entry != null) {
+ if (entry != null)
return Collections.unmodifiableList(entry.list).iterator();
- } else {
+ else
return null;
- }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|