SMAS 2.0bA Primer |
7. Macros and Functions for Creating an Application
In this section the user will find the list of the basic function allowing to create simple simulations.
If the redefine option is not chosen then it is not possible to reload a file containing the definitions of the agents. Allowing to redefine the agent allow to reload the definition file as many times as needed, which is a good idea when designing a new application.
? (defagent MUL-1 :redefine t)
The dynamic part is not required for simple actions that do not lead to setting up subcontracts.
? (defskill MULTIPLY MUL-1 :static-fcn static-multiply)
(<date> <message-type> <target-agent> {<action>} <arg-list> {<protocol><timeout>})
where
Example:
(defscenario SC-2 (1 MUL-1 :request MULTIPLY (6 6)) (3 MARCOS :inform (\"Station S-23 is down\")) (5 FACTORIAL :request SEND-REQUEST ((MUL-2 MULTIPLY (3 4) :basic-protocol))) (12 PROXY :request SEND-REQUEST ((FACTORIAL DUMB-FACTORIAL (5)))) (15 PROXY :internal SEND-INFORM ((ALL INFORM (\"All is well\")))) (17 EXPERT-SYSTEM :internal SEND-INFORM ((MARCOS INFORM (\"All is up and running again\")))) (21 EXPERT-SYSTEM :internal SEND-REQUEST ((MARCOS ASK (\"What time is it?\")))))
All defined scenario names will appear in the pull-down list of the control panel.
The function simply creates a new task identifyer, e.g., ST-23.
The send-subtask function is used in the skills to issue subcontracts. If the subcontractor is known, then the message can be directed to a particular agent using the basic protocol, otherwise it is possible to broadcast a message using the contract-net. Various parameters can be specified while doing that. If they are not specified, then reasonable default values are used instead.
Example:
The following call broadcasts a request for multiplying 2 numbers, using the contract-net protocol.
(send-subtask agent :to 'ALL :action 'multiply :args (list answer res) :protocol :contract-net)
The function is a facility to let the user handle the environment (agent memory) as the value of the environment variable. The variable is recorded at the agent level, and is persistent.
Returns the number of pending subtasks for a given agent. If asked from the functions implementing a skill for a given agent, then the number is at least 1, the one corresponding to the current process. In that case, if the answer is exactly one, it means that no other subtasks is being processed for the agent, and thus the skill can invoque the dynamic-exit function.
When the agent calls this function from within the dynamic part of a skill, then SMAS buils an answer message to be returned to the sender of the initiating message, the message is put into the :delayed-output tray and the status of the agent is changed from :waiting-for-answer to :busy.
Copyrignt Jean-Paul Barthès@UTC, 1998 Last update, Jan 99