Magentix2
2.1.1
|
Public Member Functions | |
void | run () |
String | getAgName () |
List< Literal > | perceive () |
void | act (ActionExec action, List< ActionExec > feedback) |
boolean | canSleep () |
boolean | isRunning () |
void | sleep () |
void | sendMsg (jason.asSemantics.Message m) throws Exception |
void | checkMail () |
void | broadcast (jason.asSemantics.Message m) throws Exception |
void | stopAg () |
CAgent | getJasonAgent () |
void | setJasonAgent (CAgent jasonAgent) |
Agent | getAg () |
void | setAg (Agent ag) |
Queue< ACLMessage > | getMessageList () |
void | setMessageList (Queue< ACLMessage > messageList) |
Map< String, String > | getConversationIds () |
void | setConversationIds (Map< String, String > conversationIds) |
void | setRunning (boolean running) |
Static Public Member Functions | |
static Logger | getLogger () |
static void | setLogger (Logger logger) |
Protected Member Functions | |
void | init (String filename, CAgent agent) throws AgentSpeakNotFoundException, JasonException |
Object | translateContentToJason (ACLMessage m) |
ACLMessage | jasonToACL (Message m) throws IOException |
void | addMessage (ACLMessage msg) |
Static Protected Member Functions | |
static int | kqmlToACL (String p) |
static String | aclToKqml (int p) |
Protected Attributes | |
boolean | running = true |
Map< String, String > | conversationIds = new HashMap<String, String>() |
Definition at line 42 of file MagentixAgArch.java.
static String es.upv.dsic.gti_ia.jason.MagentixAgArch.aclToKqml | ( | int | p | ) | [static, protected] |
Converts a fipa performative into a kqml one
p |
Definition at line 317 of file MagentixAgArch.java.
{ switch (p) { case ACLMessage.INFORM: return "tell"; case ACLMessage.QUERY_REF: return "askOne"; case ACLMessage.REQUEST: return "achieve"; case UNTELL: return "untell"; case UNACHIEVE: return "unachieve"; case ASKALL: return "askAll"; case ASKHOW: return "askHow"; case TELLHOW: return "tellHow"; case UNTELLHOW: return "untellHow"; } return ACLMessage.getPerformative(p).toLowerCase().replaceAll("-", "_"); }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.act | ( | ActionExec | action, |
List< ActionExec > | feedback | ||
) |
Definition at line 134 of file MagentixAgArch.java.
{ getTS().getLogger() .info("Agent " + getAgName() + " is doing: " + action.getActionTerm()); // return confirming the action execution was OK action.setResult(true); feedback.add(action); }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.addMessage | ( | ACLMessage | msg | ) | [protected] |
Adds a message to the message list
msg |
Definition at line 346 of file MagentixAgArch.java.
{ this.messageList.add(msg); }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.broadcast | ( | jason.asSemantics.Message | m | ) | throws Exception |
Definition at line 245 of file MagentixAgArch.java.
{ }
boolean es.upv.dsic.gti_ia.jason.MagentixAgArch.canSleep | ( | ) |
Definition at line 144 of file MagentixAgArch.java.
{ return true; }
Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.
Definition at line 178 of file MagentixAgArch.java.
{ ACLMessage m; do { m = messageList.poll(); if (m != null) { String ilForce = aclToKqml(m.getPerformativeInt()); String sender = m.getSender().name; String receiver = m.getReceiver().name; String replyWith = m.getReplyWith(); String irt = m.getInReplyTo(); // also remembers conversation ID if (replyWith != null && replyWith.length() > 0) { if (m.getConversationId() != null) { conversationIds.put(replyWith, m.getConversationId()); } } else { replyWith = "noid"; } Object propCont = translateContentToJason(m); if (propCont != null) { jason.asSemantics.Message im = new jason.asSemantics.Message( ilForce, sender, receiver, propCont, replyWith); if (irt != null) { im.setInReplyTo(irt); } this.getTS().getC().getMailBox().add(im); } } } while (m != null); }
Definition at line 119 of file MagentixAgArch.java.
Map<String, String> es.upv.dsic.gti_ia.jason.MagentixAgArch.getConversationIds | ( | ) |
Definition at line 417 of file MagentixAgArch.java.
{ return conversationIds; }
static Logger es.upv.dsic.gti_ia.jason.MagentixAgArch.getLogger | ( | ) | [static] |
void es.upv.dsic.gti_ia.jason.MagentixAgArch.init | ( | String | filename, |
CAgent | agent | ||
) | throws AgentSpeakNotFoundException, JasonException [protected] |
Starts the architecture
filename | File with the AgentSepak code |
agent | Agent with this architecture |
AgentSpeakNotFoundException | The filename is null or the file is not found |
JasonException |
Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.
Definition at line 63 of file MagentixAgArch.java.
{ if (filename == null) throw new AgentSpeakNotFoundException( "the AgentSpeak source file is null"); try { filename = filename.replaceAll("\\\\", "/"); new URL(filename); } catch (MalformedURLException e) { try { new FileInputStream(filename); } catch (FileNotFoundException e1) { throw new AgentSpeakNotFoundException( "the AgentSpeak source file '" + filename + "' was not found!"); } } try { this.jasonAgent = agent; ag = new Agent(); new TransitionSystem(ag, new Circumstance(), new Settings(), this); ag.initAg(filename); } catch (Exception e) { logger.log(Level.SEVERE, "Init error", e); throw new JasonException( "Problem with the initialization of Jason agent!"); } }
Definition at line 149 of file MagentixAgArch.java.
{ return running; }
ACLMessage es.upv.dsic.gti_ia.jason.MagentixAgArch.jasonToACL | ( | Message | m | ) | throws IOException [protected] |
Converts a jason message into an ACLMessage
m |
IOException |
Definition at line 255 of file MagentixAgArch.java.
{ ACLMessage acl = new ACLMessage(kqmlToACL(m.getIlForce())); // send content as string if it is a Term/String (it is better for // interoperability) if (m.getPropCont() instanceof Term || m.getPropCont() instanceof String) { acl.setContent(m.getPropCont().toString()); } else { acl.setContentObject((Serializable) m.getPropCont()); } acl.setReceiver(new AgentID(m.getReceiver())); acl.setSender(this.jasonAgent.getAid()); acl.setReplyWith(m.getMsgId()); acl.setLanguage("AgentSpeak"); if (m.getInReplyTo() != null) { acl.setInReplyTo(m.getInReplyTo()); } return acl; }
static int es.upv.dsic.gti_ia.jason.MagentixAgArch.kqmlToACL | ( | String | p | ) | [static, protected] |
Converts a kqml performative into a fipa performative
p |
Definition at line 288 of file MagentixAgArch.java.
{ if (p.equals("tell")) { return ACLMessage.INFORM; } else if (p.equals("askOne")) { return ACLMessage.QUERY_REF; } else if (p.equals("achieve")) { return ACLMessage.REQUEST; } else if (p.equals("untell")) { return UNTELL; } else if (p.equals("unachieve")) { return UNACHIEVE; } else if (p.equals("askAll")) { return ASKALL; } else if (p.equals("askHow")) { return ASKHOW; } else if (p.equals("tellHow")) { return TELLHOW; } else if (p.equals("untellHow")) { return UNTELLHOW; } return ACLMessage.getPerformative(p); }
List<Literal> es.upv.dsic.gti_ia.jason.MagentixAgArch.perceive | ( | ) |
Definition at line 126 of file MagentixAgArch.java.
{ List<Literal> l = new ArrayList<Literal>(); return l; }
Runs the reasoning cycle
Definition at line 102 of file MagentixAgArch.java.
{ // RunCentralisedMAS.setupLogger(); try { while (isRunning()) { // calls the Jason engine to perform one reasoning cycle logger.fine("Reasoning...."); // parche para arreglar la sincronizacion, buscar mejor solucion // y porque occure esto if (this.jasonAgent.getMutexHoldCount() > 0) this.jasonAgent.unlock(); getTS().reasoningCycle(); } } catch (Exception e) { logger.log(Level.SEVERE, "Run error", e); } }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.sendMsg | ( | jason.asSemantics.Message | m | ) | throws Exception |
Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.
Definition at line 165 of file MagentixAgArch.java.
{ ACLMessage acl = jasonToACL(m); acl.addReceiver(new AgentID(m.getReceiver())); if (m.getInReplyTo() != null) { String convid = conversationIds.get(m.getInReplyTo()); if (convid != null) { acl.setConversationId(convid); } } this.jasonAgent.send(acl); }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.setAg | ( | Agent | ag | ) |
void es.upv.dsic.gti_ia.jason.MagentixAgArch.setConversationIds | ( | Map< String, String > | conversationIds | ) |
conversationIds | the conversationIds to set |
Definition at line 425 of file MagentixAgArch.java.
{ this.conversationIds = conversationIds; }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.setJasonAgent | ( | CAgent | jasonAgent | ) |
jasonAgent | the jasonAgent to set |
Definition at line 365 of file MagentixAgArch.java.
{ this.jasonAgent = jasonAgent; }
static void es.upv.dsic.gti_ia.jason.MagentixAgArch.setLogger | ( | Logger | logger | ) | [static] |
logger | the logger to set |
Definition at line 395 of file MagentixAgArch.java.
{ MagentixAgArch.logger = logger; }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.setMessageList | ( | Queue< ACLMessage > | messageList | ) |
messageList | the messageList to set |
Definition at line 410 of file MagentixAgArch.java.
{ this.messageList = messageList; }
void es.upv.dsic.gti_ia.jason.MagentixAgArch.setRunning | ( | boolean | running | ) |
running | the running to set |
Definition at line 433 of file MagentixAgArch.java.
Definition at line 155 of file MagentixAgArch.java.
{ try { Thread.sleep(100); } catch (InterruptedException e) { } }
Definition at line 350 of file MagentixAgArch.java.
{ running = false; }
Object es.upv.dsic.gti_ia.jason.MagentixAgArch.translateContentToJason | ( | ACLMessage | m | ) | [protected] |
returns the content of the message m and implements some pro-processing of the content, if necessary
m | Message to translate |
Definition at line 218 of file MagentixAgArch.java.
{ Object propCont = null; try { propCont = m.getContentObject(); if (propCont instanceof String) { // try to parse as term try { propCont = ASSyntax.parseTerm((String) propCont); } catch (Exception e) { // no problem } } } catch (Exception e) { // no problem try another thing } if (propCont == null) { // still null // try to parse as term try { propCont = ASSyntax.parseTerm(m.getContent()); } catch (Exception e) { // not AS messages are treated as string propCont = new StringTermImpl(m.getContent()); } } return propCont; }
Map<String, String> es.upv.dsic.gti_ia.jason.MagentixAgArch.conversationIds = new HashMap<String, String>() [protected] |
Reimplemented in es.upv.dsic.gti_ia.norms.NormsMagentixAgArch.
Definition at line 162 of file MagentixAgArch.java.
boolean es.upv.dsic.gti_ia.jason.MagentixAgArch.running = true [protected] |
Definition at line 48 of file MagentixAgArch.java.