The metadata subpage is missing. You can start it via filling in this form or by following the instructions that come up after clicking on the [show] link to the right.
|
Do you see this on PREVIEW? then SAVE! before following a link.
A - For a New Cluster use the following directions
Subpages format requires a metadata page.
Using the following instructions will complete the process of creating this article's subpages.
- Click the blue "metadata template" link below to create the page.
- On the edit page that appears paste in the article's title across from "
pagename = ".
- You might also fill out the checklist part of the form. Ignore the rest.
- For background, see Using the Subpages template Don't worry--you'll get the hang of it right away.
- Remember to hit Save!
the "metadata template".
However, you can create articles without subpages. Just delete the {{subpages}} template from the top of this page and this prompt will disappear. :) Don't feel obligated to use subpages, it's more important that you write sentences, which you can always do without writing fancy code.
|
B - For a Cluster Move use the following directions
The metadata template should be moved to the new name as the first step. Please revert this move and start by using the Move Cluster link at the top left of the talk page.
The name prior to this move can be found at the following link.
|
|
Autonomous Agents in Erlang
Agent Example programs
Two Agent systems
Dynamic timeout based initiative switching
Explanation of the code in jungle.erl
Here we have a simple chat-bot agent called person/4. We create two instances of it called Tarzan and Jane. They talk to each other. Each has a timeout. The timeout is the lenght of time one will wait before they intiate conversation. The initial timeout of Jane is set to 10 seconds. The initial timeout of Tarzan is set to 8 seconds. Because of the initial values, Tarzan will speak first and Jane will respond. Both timeouts start over but keep the same values. Again, Tarzan speaks first and Jane responds. Now things get interesting. The agent can tell if the conversation is repeating. If the conversation repeats then special messages are sent to cause a swap in the relative levels of timeout. Now Tarzan waits longer than Jane and Jane has a chance to speak first. Now, Jane speaks first twice. Then they swap initiative again. Since the processes are autonomous, we need to stop them with a quit program called jungle:quit().
Example program listing: jungle.erl
-module( jungle ).
-compile(export_all).
%% This program shows how chat-bot agents can exchange initiative(lead) while in conversation.
%% Start with start().
%% End with quit().
start() ->
register( tarzan, spawn( jungle, person, [ tarzan, 8000, "", jane ] ) ),
register( jane, spawn( jungle, person, [ jane, 10000, "", tarzan ] ) ),
"Dialog will start in 5ish seconds, stop program with jungle:quit().".
quit() ->
jane ! exit,
tarzan ! exit.
%% Args for person/4
%% Name: name of agent being created/called
%% T: timeout to continue conversation
%% Last: Last thing said
%% Other: name of other agent in conversation
person( Name, T, Last, Other ) ->
receive
"hi" ->
respond( Name, Other, "hi there \n " ),
person( Name, T, "", Other );
"slower" ->
show( Name, "i was told to wait more " ++ integer_to_list(round(T*2/1000))),
person( Name, T*2, "", Other );
"faster" ->
NT = round( T/2 ),
show( Name, "I was told to wait less " ++ integer_to_list(round(NT/1000))),
person( Name, NT, "", Other );
exit ->
exit(normal);
_AnyWord ->
otherwise_empty_the_queue,
person( Name, T, Last, Other )
after T ->
respond( Name, Other, "hi"),
case Last of
"hi" ->
self() ! "slower",
sleep( 2000), % give the other time to print
Other ! "faster",
person( Name, T, "", Other );
_AnyWord ->
person( Name, T, "hi", Other )
end
end.
%
respond( Name, Other, String ) ->
show( Name, String ),
Other ! String.
%
show( Name, String ) ->
sleep(1000),
io:format( " ~s -- ~s \n ", [ Name, String ] ).
%
sleep(T) ->
receive
after T ->
done
end.
% ===========================================================>%
Sample output from: jungle.erl
Sample output:
18> c(jungle).
{ok,jungle}
19> jungle:start().
jane_and_tarzan_will_start_in_5_seconds
tarzan -- hi
jane -- hi there
tarzan -- hi
jane -- hi there
jane -- I was told to wait less: 5
tarzan -- I was told to wait more: 16
jane -- hi
tarzan -- hi there
jane -- hi
tarzan -- hi there
tarzan -- I was told to wait less: 8
jane -- I was told to wait more: 10
tarzan -- hi
jane -- hi there
tarzan -- hi
jane -- hi there
jane -- I was told to wait less: 5
tarzan -- I was told to wait more: 16
jane -- hi
tarzan -- hi there
20> jungle:quit().
exit