From: <jom...@us...> - 2013-08-24 16:23:03
|
Revision: 1743 http://sourceforge.net/p/jason/svn/1743 Author: jomifred Date: 2013-08-24 16:23:00 +0000 (Sat, 24 Aug 2013) Log Message: ----------- the internal action create_agent accepts a variable for the first argument, this variable will be then unified with the unique name given to the agent. Modified Paths: -------------- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java trunk/src/jason/stdlib/create_agent.java Modified: trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java =================================================================== --- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2013-08-15 14:15:34 UTC (rev 1742) +++ trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2013-08-24 16:23:00 UTC (rev 1743) @@ -40,9 +40,12 @@ if (stts == null) stts = new Settings(); - while (masRunner.getAg(agName) != null) - agName += "_a"; - + String nb = ""; + int n = 1; + while (masRunner.getAg(agName+nb) != null) + nb = "_" + (n++); + agName = agName + nb; + CentralisedAgArch agArch = newAgInstance(); agArch.setAgName(agName); agArch.createArchs(ap.getAgArchClasses(), ap.agClass.getClassName(), ap.getBBClass(), agSource, stts, masRunner); Modified: trunk/src/jason/stdlib/create_agent.java =================================================================== --- trunk/src/jason/stdlib/create_agent.java 2013-08-15 14:15:34 UTC (rev 1742) +++ trunk/src/jason/stdlib/create_agent.java 2013-08-24 16:23:00 UTC (rev 1743) @@ -28,16 +28,23 @@ import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; import jason.asSyntax.ListTerm; +import jason.asSyntax.SourceInfo; import jason.asSyntax.StringTerm; +import jason.asSyntax.StringTermImpl; import jason.asSyntax.Structure; import jason.asSyntax.Term; +import jason.asSyntax.VarTerm; import jason.mas2j.ClassParameters; import jason.runtime.RuntimeServicesInfraTier; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + /** <p>Internal action: <b><code>.create_agent</code></b>. @@ -46,7 +53,9 @@ <p>Parameters:<ul> - <li>+ name (atom or string): the name for the new agent.<br/> + <li>+ name (atom, string, or variable): the name for the new agent. + If this parameter is a variable, it will be unified with the name given to the agent. + The agent's name will be the name of the variable and some number that makes it unique.<br/> <li>+ source (string): path to the file where the AgentSpeak code for the new agent can be found.<br/> @@ -61,6 +70,9 @@ <li> <code>.create_agent(bob,"/tmp/x.asl")</code>: creates an agent named "bob" from the source file in "/tmp/x.asl".</li> + <li> <code>.create_agent(Bob,"/tmp/x.asl")</code>: creates an agent named "bob" (or "bob_1", "bob_2", ...) + and unifies variable Bob with the given name.</li> + <li> <code>.create_agent(bob,"x.asl", [agentClass("myp.MyAgent")])</code>: creates the agent with customised agent class @@ -108,6 +120,9 @@ else name = args[0].toString(); + if (args[0].isVar()) + name = name.substring(0,1).toLowerCase() + name.substring(1); + StringTerm source = (StringTerm)args[1]; File fSource = new File(source.getString()); @@ -138,7 +153,11 @@ RuntimeServicesInfraTier rs = ts.getUserAgArch().getRuntimeServices(); name = rs.createAgent(name, fSource.getAbsolutePath(), agClass, agArchClasses, bbPars, ts.getSettings()); rs.startAgent(name); - return true; + + if (args[0].isVar()) + return un.unifies(new StringTermImpl(name), args[0]); + else + return true; } private Structure testString(Term t) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |