|
From: <jom...@us...> - 2008-10-20 14:12:44
|
Revision: 1398
http://jason.svn.sourceforge.net/jason/?rev=1398&view=rev
Author: jomifred
Date: 2008-10-20 14:12:34 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
start a new example in jmoise
Modified Paths:
--------------
trunk/src/jason/architecture/AgArch.java
trunk/src/jason/asSyntax/ASSyntax.java
trunk/src/jason/asSyntax/PlanBodyImpl.java
trunk/src/jason/asSyntax/VarTerm.java
Added Paths:
-----------
trunk/applications/jason-moise/example/moise-tutorial/
trunk/applications/jason-moise/example/moise-tutorial/jojOS.xml
trunk/applications/jason-moise/example/moise-tutorial/lucio.asl
trunk/applications/jason-moise/example/moise-tutorial/marcos.asl
trunk/applications/jason-moise/example/moise-tutorial/orgManager.asl
trunk/applications/jason-moise/example/moise-tutorial/src/
trunk/applications/jason-moise/example/moise-tutorial/src/gui/
trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java
trunk/applications/jason-moise/example/moise-tutorial/src/gui/list_bels.java
trunk/applications/jason-moise/example/moise-tutorial/tutorial.mas2j
Added: trunk/applications/jason-moise/example/moise-tutorial/jojOS.xml
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/jojOS.xml (rev 0)
+++ trunk/applications/jason-moise/example/moise-tutorial/jojOS.xml 2008-10-20 14:12:34 UTC (rev 1398)
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?xml-stylesheet href="os.xsl" type="text/xsl" ?>
+
+<organisational-specification
+
+ id="joj"
+ os-version="0.6"
+
+ xmlns='http://moise.sourceforge.net/os'
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xsi:schemaLocation='http://moise.sourceforge.net/os
+ http://moise.sourceforge.net/xml/os.xsd'>
+
+ <structural-specification>
+ <role-definitions>
+ <role id="player" />
+ <role id="coach" />
+ <role id="middle"> <extends role="player"/> </role>
+ <role id="leader"> <extends role="player"/> </role>
+ <role id="back"> <extends role="player"/> </role>
+ <role id="goalkeeper"> <extends role="back"/> </role>
+ <role id="attacker"> <extends role="player"/> </role>
+ </role-definitions>
+
+ <group-specification id="team">
+ <roles>
+ <role id="coach" min="1" max="2"/>
+ </roles>
+ <links>
+ <link from="leader" to="player" type="authority"
+ scope="inter-group" extends-sub-groups="true" bi-dir="false"/>
+ <link from="coach" to="player" type="authority"
+ scope="inter-group" extends-sub-groups="true" bi-dir="false"/>
+ <link from="player" to="player" type="communication"
+ scope="inter-group" extends-sub-groups="true" bi-dir="false"/>
+ <link from="player" to="coach" type="communication"
+ scope="inter-group" extends-sub-groups="true" bi-dir="false"/>
+ </links>
+ <sub-groups>
+
+ <group-specification id="attack" min="1" max="1">
+ <roles>
+ <role id="middle" min="5" max="5" />
+ <role id="leader" min="0" max="1"/>
+ <role id="attacker" min="2" max="2" />
+ </roles>
+ <formation-constraints>
+ <compatibility from="middle" to="leader" type="compatibility"
+ scope="intra-group" extends-sub-groups="false"
+ bi-dir="true"/>
+ </formation-constraints>
+ </group-specification>
+
+ <group-specification id="defense" min="1" max="1">
+ <roles>
+ <role id="leader" min="0" max="1" />
+ <role id="goalkeeper" min="1" max="1" />
+ <role id="back" min="3" max="3" />
+ </roles>
+ <links>
+ <link from="goalkeeper" to="back" type="authority"
+ scope="intra-group" extends-sub-groups="false"
+ bi-dir="false"/>
+ </links>
+ <formation-constraints>
+ <compatibility from="back" to="leader" type="compatibility"
+ scope="intra-group" extends-sub-groups="false"
+ bi-dir="true"/>
+ </formation-constraints>
+ </group-specification>
+ </sub-groups>
+
+ <formation-constraints>
+ <!-- sub-groups scope cardinality -->
+ <cardinality min="1" max="1" object="role" id="leader"/>
+ </formation-constraints>
+ </group-specification>
+ </structural-specification>
+
+
+ <functional-specification>
+ <scheme id="sideAttack" >
+ <goal id="scoreGoal" min="1">
+ <plan operator="sequence">
+ <goal id="g1" min="1" ds="get the ball" />
+ <goal id="g2" ds="to be well placed">
+ <plan operator="parallel">
+ <goal id="g7" min="1" ds="go toward the opponent's field" />
+ <goal id="g8" min="1" ds="be placed in the middle field" />
+ <goal id="g9" min="1" ds="be placed in the opponent's goal area" />
+ </plan>
+ </goal>
+ <goal id="g3" min="1" ds="kick the ball to the m2Ag" >
+ <argument id="M2Ag" />
+ </goal>
+ <goal id="g4" min="1" ds="go to the opponent's back line" />
+ <goal id="g5" min="1" ds="kick the ball to the goal area" />
+ <goal id="g6" min="1" ds="shot at the opponent's goal" />
+ </plan>
+ </goal>
+
+ <mission id="m1" min="1" max="1">
+ <goal id="g1" />
+ <goal id="g3" />
+ <goal id="g7" />
+ </mission>
+ <mission id="m2" min="1" max="1">
+ <goal id="g8" />
+ <goal id="g4" />
+ <goal id="g5" />
+ </mission>
+ <mission id="m3" min="1" max="1">
+ <goal id="g9" />
+ <goal id="g6" />
+ </mission>
+ </scheme>
+ </functional-specification>
+
+ <deontic-specification>
+ <deontic-relation type="permission" role="back" mission="m1" />
+ <deontic-relation type="obligation" role="middle" mission="m2" />
+ <deontic-relation type="obligation" role="attacker" mission="m3" />
+ </deontic-specification>
+</organisational-specification>
+
Added: trunk/applications/jason-moise/example/moise-tutorial/lucio.asl
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/lucio.asl (rev 0)
+++ trunk/applications/jason-moise/example/moise-tutorial/lucio.asl 2008-10-20 14:12:34 UTC (rev 1398)
@@ -0,0 +1,4 @@
+// the agent is controled by GUI
+
++!do(X) <- .print("doing ",X); X; gui.list_bels.
+
Added: trunk/applications/jason-moise/example/moise-tutorial/marcos.asl
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/marcos.asl (rev 0)
+++ trunk/applications/jason-moise/example/moise-tutorial/marcos.asl 2008-10-20 14:12:34 UTC (rev 1398)
@@ -0,0 +1,4 @@
+// the agent is controled by GUI
+
++!do(X) <- .print("doing ",X); X; gui.list_bels.
+
Added: trunk/applications/jason-moise/example/moise-tutorial/orgManager.asl
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/orgManager.asl (rev 0)
+++ trunk/applications/jason-moise/example/moise-tutorial/orgManager.asl 2008-10-20 14:12:34 UTC (rev 1398)
@@ -0,0 +1 @@
+/* nothing here, everything is implemented in the arhitecture */
\ No newline at end of file
Added: trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java (rev 0)
+++ trunk/applications/jason-moise/example/moise-tutorial/src/gui/OrgAgentGUI.java 2008-10-20 14:12:34 UTC (rev 1398)
@@ -0,0 +1,143 @@
+package gui;
+
+import jason.JasonException;
+import jason.asSemantics.Intention;
+import jason.asSyntax.ASSyntax;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Term;
+import jason.asSyntax.parser.ParseException;
+import jason.mas2j.ClassParameters;
+import jason.runtime.Settings;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
+import javax.swing.border.TitledBorder;
+
+import jmoise.OrgAgent;
+
+public class OrgAgentGUI extends OrgAgent {
+
+ @Override
+ public void initAg(String agClass, ClassParameters bbPars, String asSrc, Settings stts) throws JasonException {
+ super.initAg(agClass, bbPars, asSrc, stts);
+ startGUI();
+ }
+
+ @Override
+ public void stopAg() {
+ super.stopAg();
+ frame.setVisible(false);
+ }
+
+ JTextArea bels = new JTextArea(20,50);
+ JTextField args = new JTextField(30);
+ JFrame frame;
+
+ String[][] actions = { { "create_group", "spec [,superGrId]" },
+ { "remove_group", "groupID" },
+ { "adopt_role", "role,groupId" },
+ { "remove_role", "role,groupId" }
+ };
+
+ protected void startGUI() {
+
+ // top
+ JScrollPane pbb = new JScrollPane(bels);
+ pbb.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Belief Base", TitledBorder.LEFT, TitledBorder.TOP));
+ listBels();
+
+ // south
+ //control.add(new JLabel("Organisational action: "));
+
+ final JComboBox actionsCB = new JComboBox();
+ for (String[] a: actions) {
+ actionsCB.addItem(a[0]);
+ }
+ actionsCB.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent ievt) {
+ int a = actionsCB.getSelectedIndex();
+ args.setText(getInternalAction(a));
+ }
+ });
+
+ args.setText(getInternalAction(0));
+
+ JButton doBT = new JButton("Do");
+ doBT.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ executeAction(args.getText());
+ }
+ });
+ }
+ });
+ args.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ executeAction(args.getText());
+ }
+ });
+ }
+ });
+
+ 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);
+
+
+ frame = new JFrame(":: "+getAgName()+" interface ::");
+ frame.getContentPane().setLayout(new BorderLayout());
+ frame.getContentPane().add(BorderLayout.CENTER, pbb);
+ frame.getContentPane().add(BorderLayout.SOUTH, control);
+
+ frame.pack();
+ frame.setVisible(true);
+ }
+
+ private String getInternalAction(int i) {
+ return "jmoise."+actions[i][0] + "(" + actions[i][1] + ")";
+ }
+
+ protected void executeAction(String actionText) {
+ bels.setText("Doing: "+ actionText);
+ try {
+ Term ia = ASSyntax.parsePlanBody(actionText);
+ Literal action = ASSyntax.createLiteral("do", ia);
+ getTS().getC().addAchvGoal(action, Intention.EmptyInt);
+ getArchInfraTier().wake();
+ } catch (ParseException e) {
+ bels.setText("Error parsing "+actionText+" as an Jason internal action!\n"+e);
+ } catch (Exception e) {
+ bels.setText("Error performing action "+actionText+": "+e);
+ e.printStackTrace();
+ }
+ }
+
+ public void listBels() {
+ bels.setText("");
+ for (Literal b: getTS().getAg().getBB()) {
+ bels.append(b+"\n");
+ }
+ }
+
+
+
+}
Added: trunk/applications/jason-moise/example/moise-tutorial/src/gui/list_bels.java
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/src/gui/list_bels.java (rev 0)
+++ trunk/applications/jason-moise/example/moise-tutorial/src/gui/list_bels.java 2008-10-20 14:12:34 UTC (rev 1398)
@@ -0,0 +1,16 @@
+package gui;
+
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.Term;
+
+public class list_bels extends DefaultInternalAction {
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ OrgAgentGUI arch = (OrgAgentGUI)ts.getUserAgArch();
+ arch.listBels();
+ return true;
+ }
+}
Added: trunk/applications/jason-moise/example/moise-tutorial/tutorial.mas2j
===================================================================
--- trunk/applications/jason-moise/example/moise-tutorial/tutorial.mas2j (rev 0)
+++ trunk/applications/jason-moise/example/moise-tutorial/tutorial.mas2j 2008-10-20 14:12:34 UTC (rev 1398)
@@ -0,0 +1,12 @@
+MAS write_paper {
+ infrastructure: Centralised
+ agents:
+ orgManager [osfile="jojOS.xml",gui=yes]
+ agentArchClass jmoise.OrgManager;
+
+ marcos agentArchClass gui.OrgAgentGUI;
+ lucio agentArchClass gui.OrgAgentGUI;
+
+ classpath: "../../lib/moise.jar";"../../lib/jmoise.jar";
+}
+
Modified: trunk/src/jason/architecture/AgArch.java
===================================================================
--- trunk/src/jason/architecture/AgArch.java 2008-10-19 19:39:24 UTC (rev 1397)
+++ trunk/src/jason/architecture/AgArch.java 2008-10-20 14:12:34 UTC (rev 1398)
@@ -140,7 +140,10 @@
/** Gets the agent's name */
public String getAgName() {
- return archTier.getAgName();
+ if (archTier == null)
+ return "no-named";
+ else
+ return archTier.getAgName();
}
/** Sends a Jason message */
Modified: trunk/src/jason/asSyntax/ASSyntax.java
===================================================================
--- trunk/src/jason/asSyntax/ASSyntax.java 2008-10-19 19:39:24 UTC (rev 1397)
+++ trunk/src/jason/asSyntax/ASSyntax.java 2008-10-20 14:12:34 UTC (rev 1398)
@@ -153,4 +153,8 @@
return (LogicalFormula)new as2j(new StringReader(sExpr)).log_expr();
}
+ /** creates a new plan's body */
+ public static PlanBody parsePlanBody(String sExpr) throws ParseException {
+ return (PlanBody)new as2j(new StringReader(sExpr)).plan_body();
+ }
}
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-10-19 19:39:24 UTC (rev 1397)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-10-20 14:12:34 UTC (rev 1398)
@@ -56,15 +56,25 @@
}
public BodyType getBodyType() {
- return formType;
+ if (term instanceof VarTerm) { // do not use .isVar
+ return ((VarTerm)term).getBodyType();
+ } else {
+ return formType;
+ }
}
public void setBodyType(BodyType bt) {
formType = bt;
}
public Term getBodyTerm() {
+ if (term instanceof VarTerm) {
+ VarTerm v = (VarTerm)term;
+ if (v.hasValue())
+ return v.getValue();
+ }
return term;
}
+
public void setBodyTerm(Term t) {
term = t;
}
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-10-19 19:39:24 UTC (rev 1397)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-10-20 14:12:34 UTC (rev 1398)
@@ -904,6 +904,8 @@
public BodyType getBodyType() {
if (value != null && getValue() instanceof PlanBody)
return ((PlanBody) getValue()).getBodyType();
+ else if (value != null && getValue().isInternalAction())
+ return BodyType.internalAction;
else
return BodyType.none;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|