A Tcl/Tk BASED USER INTERFACE FOR MULTI-AGENT SYSTEMS Adriana Jurca Computer Science Department,“Politehnica” University of Timisoara Bv. Vasile Parvan 2, Timisoara, Romania Phone: +40-56-203876, E-mail:
[email protected],
[email protected] Jose Manuel da Fonseca Electrotechnical Department, New University of Lisbon 2825 Monte da Caparica, Portugal Phone: +351-1-3500234, E-mail:
[email protected] Ioan Jurca Computer Science Department,“Politehnica” University of Timisoara Bv. Vasile Parvan 2, Timisoara, Romania Phone: +40-56-203876, E-mail:
[email protected]
Abstract The main goal of this paper is to present a user interface for a multi-agent system “MACIV” [1]. The aim of the MACIV project is the design and implementation of a computer system, mainly based on Distributed Artificial Intelligence techniques, enabling a decentralised management of different resources in Civil Construction Companies. The user interface is implemented using the Tcl and Tk packages [3]. A novel characteristic of this work is the use of Tcl and Tk packages for creating a user interface for a dynamic application - a multi-agent system. The most frequent use of Tcl and Tk is for static applications: all the information about a window is set before it appears on the screen and rarely changed after that. In our case, the number of windows and their moment of apparition on screen is dynamically changed.
1. Introduction The user interface is a very important part of the systems that need human control and depend on human decisions and actions. The acceptance or rejection of a new software product often depends on its user interface, too, not only on its professional characteristics. A user interface has to be easy to manipulate and understand, to be “friendly”, in order to satisfy the users. The user interface implemented in this project was designed for the MACIV project [1], which will be briefly described, but its functionalities can be incorporated in any multi-agent system, using pvm messages [2] for agent communication.
The interface was implemented using the Tcl and Tk packages [3]. Together they provide a programming system for developing and using graphical user interface applications. A very important benefit of using Tcl and Tk is rapid development. Compared to toolkits where the programming is entirely in C, there is much less to learn in order to use Tcl and Tk and much less code to write. Tcl is a very powerful scripting language. All that an application needs to do is to implement a few new Tcl commands that provides the basic features of the application. Then the application can be linked with the Tcl interpreter to produce a fullfunction scripting language that includes both the commands provided by Tcl (called the Tcl core) and those implemented by the application. 1.1. The MACIV Project As stated by the MACIV [1] developers, the building construction environment is very appropriate for the multi-agent systems modelling. The large geographic distribution caused by the considerable number of installations in different locations, the resources diversity, the natural and usually easy task decomposition and the multiplicity of functions that the majority of the agents can play are some of the reasons why this problem is so attractive for the Distributed Artificial Intelligence. Here are some examples of tasks involved in building construction: wall building, painting, earthmoving. The solution adopted by the developers defines a software agent for each physical resource, containing all its particularities. All the edifications possessed by the company are supposed to have a computational equipment where the software agents, representing the physical entities located at that place, reside. When a new task is launched on the system, it must be broadcast to all the software agents and the interested agents will bid for it, presenting their conditions - costs, production characteristics, etc. The system is hierarchically organised as a collection of macro-agents interconnected through a communication link. By macro-agent is understood the functional grouping of one or more computers, interconnected through a local area network and devoted to local resources managing. Examples of macro-agents: Edification-representing an active working place, Garage-the place where inactive machines are stored, Personnel Department-where the inactive workers are registered. Every macro-agent will have a special agent called facilitator. Facilitators are used for reducing the communication overhead; they optimise the task announcement by directly addressing the message to the potentially interested agents. Facilitator agents are also used for connecting the agents with the user, with the help of the user interface. The remainder of this paper is structured as follows. In Section 2 the specification of the user interface is presented. Section 3 contains the interface design. The interface implementation is disscused in Section 4. The conclusions and future work are presented in Section 5.
2. The interface specification In a multi-agent system, some of the basic operations that need an user interface for controling or monitoring them are : • the displaying of control messages, sent by agents, informing the user about the system functionality, about problems that may appear. • the request of input values from the user, for adding new characteristics to the system, for modifying them or for controling and taking decisions in unexpected situations. • the selection of one choice from a list of options; when using large multi-agent systems, frequently appear situations when the user is the one that has to decide the next move from more possible options. The user interface presented in this paper allows all this operations to be performed. Three types of widgets [3] are needed: a display widget where the messages sent by agent are printed, an entry widget and a multiple choices menu widget. Each computer hosting agents must have an interface running on it. The communication between the interface and the agents is realised with pvm messages [2]. Each interaction between the agent and the interface corresponds to a specific pvm message type. In order to use the interface, an agent has to register to the interface (to send the tid [2] of the agent process in a pvm message), then to send in other pvm messages each requested operation. This messages will be processed by the interface, depending on their type.
3. The interface design The functions of the interface were designed accordingly to the operations that the agents have to perform in a multi-agent system. Thus, the widgets displayed on screen may be: • a multiple choices menu The user is allowed to choose exactly one from a list of option; the agent is sending the options. The chosen value is sent back to the agent. • an entry widget The user is asked to enter a value. He can add new characteristics for the agents, or to indicate the total number of agents in the system, etc. The input value is sent to the agent. • a display widget Text messages sent by the agents are displayed on screen. Usually they are control messages. There are two ways of printing these messages: if the display widget has already been opened, they just appear in the window, like being printed on the screen; if the window is closed, they are stored in a variable associated with the window, and when opening it, all messages previously sent will be displayed. A button widget is displayed on screen for each active agent. The agents are continuously sending messages to the interface. The messages sent by an agent are stored in a pending list associated with the agent button. At each mouse click over the agent button, a message is processed and a widget appears on screen. The next picture gives a general idea about the main characteristics of the interface:
Figure 1. The main functionalities of the interface All the widgets appear in agent windows that can be moved, opened, closed, resized independently. A main interface window contains all agent windows. The interface has two distinct parts, written in C and Tcl, respectively. The part written in C is implementing, mainly, the link between C and Tcl: all the necessary initialisations and communications between procedures, C and Tcl variable linking, the implementation the new Tcl commands, the management of the received and sent messages, etc. The part written in Tcl contains all the code related with widgets, windows and their management: creating and destroying the windows, displaying and moving them on the screen, creating and displaying the widgets, communication with the user. A main idea of how these parts are related is given in Figure 2:
Figure 2. The main structure of the interface The agent is sending messages to the interface (SYPBVHQG A timer function for handling messages is implemented in the C code of the interface. Each time a message arrives from an agent, the timer function activates a Tcl procedure for processing the message.
If a user action is requested (for example in the case of an entry widget), the result of this action is sent back to the agent. The sending is realised with new Tcl commands implemented in C (user_ok). Most of the time, the interface is executing Tcl code (the Tcl nucleus is active). It is leaving this state when a new message arrives or a user action occurs.
4. The interface implementation Thelogical approach of the interface implementation is presented in the first subsection; in the second one, all the procedures used in the interface implementation are explained. 4.1. General Figure 3 illustrates how the interface is working, how a message sent by the agent results in a window displayed on the screen:
Figure 3. A general idea about the components of the interface Step 1. The agent is sending a pvm_send message, asking for a specific widget to be displayed on screen, depending on the MsgType parameter. It also sends some other parameters needed for displaying the widget (the text to be printed, the tid of the agent process). In the interface code, the MsgType variable is used in a VZLWFK construction in order to select the appropriate procedure for each type of message. Step 2. In this step, one of the 3XWB0HVV or 3XWB0HVVDJH procedures, written in C++, is invoked. 3XWB0HVV is used for entry and multiple choices widgets, as well as for displaying a display-screen; for printing a message in the display-screen the 3XWB0HVVDJH procedure is used. Step 3. The 3XWB0HVV procedure is invoking the SXWBPHVV procedure, written in Tcl.. 3XWB0HVVDJH is invoking the SXWBPHVVDJH procedure.
the GLVSOD\BZLQGRZ procedure is invoked. From SXWBPHVV, 'LVSOD\BZLQGRZ is performing all the necessary operations for displaying a window on the screen, placing it in a certain space if more windows are already opened, initialising all the data structures needed for managing the windows. Step 5. The GLVSOD\BZLQGRZ procedure is calling the GLVSOD\BPHVV procedure, used for finally displaying on screen the widget asked by the agent. Step 6. One of the basic procedures : (QWU\/LVW%R[ or 7H[W:LGJHW is called, with all the needed parameters, previously set. Step 7. When calling (QWU\ or /LVW%R[, an answer from the user is expected. Using the procedures DVNBYDOXHBRN and DVNBPHQXBRN, the answers are sent to the agent. Step 8. In the (QWU\ procedure, DVNBYDOXHBRN is invoked. This procedure is written in C . It waits for the user to enter a value, then sends it to the agent, using again a pvm_send function. The /LVW%R[ procedure is calling DVNBPHQXBRN for sending to the agent the chosen option. Step 4.
4.2. Components description In the C code of the interface, the 7NB&UHDWH7LPHU+DQGOHU function is invoked. A timer call-back is created; at each 1000 milliseconds, Tk will invoke the 0VJ+DQGOHU procedure to wait for messages from the agent and treat each of them as needed. In the 0VJ+DQGOHU procedure each message that arrives is processed depending on its type. There are seven types of messages an agent may send to the interface: • SendLocFacTid - the agent is registering to the interface, sending its tid and name; a button with agent name appears on screen • MessagePrint - the agent wants to print a text in a display-screen • Entry - the agent needs an entry widget • Menu - the agent is asking for a multi-choices menu • DisplayScreen - agent is asking for a display screen , where the text sent in a MessagePrint message will be printed • GetHumanTid - agent is asking for the tid of the interface • SenderOut - agent is shutting down; it is informing the interface to destroy the agent button and all its windows that are opened on screen The processing of the MessagePrint, Entry, Menu and DisplayScreen messages has been briefly described in the prevoius subsection. The procedures that implement the operations are: The 3XWB0HVV procedure is written in C. It calls the Tcl procedure SXWBPHVV sending as parameters the tid of the agent process and the text to be printed in the widget. In the SXWBPHVV procedure the message is inserted in a list of pending messages associated with the agent that sent the message. A Tcl structure ButtonArray is used to store the messages. The structure has two pointers: PutMess is pointing to the most recent introduced message and GetMess indicates the message that is processed. There is a maximum number of possible pending messages that can not be exceeded. All the operations for managing the windows are implemented in the GLVSOD\BZLQGRZ procedure.
The window name is inserted in the :LQ2Q6FUHHQ list containing the windows currently displayed on screen. The :LQGRZ$UUD\ structure which stores all the information about the windows is set with the appropriate values. The window is created as a transient window of the main interface window. This means that when the main window is closed ( iconified), all the other windows will have the same state. The next step is computing the window’s coordinates. All the windows appear on screen in a cascade style. The coordinates are relative to the coordinates of the main interface window. A certain number of windows may appear at a time on the screen. Another operation is keeping the windows inside the main interface window. The user can not drag them out. If one of the window’s coordinates exits main interface window, a ZP geometry command is invoked, dragging back the window. When a window is focused on, it will appear in front of all the other windows currently displayed on screen. This could be a problem: if the main interface window receives focus ( by a mouse action), all the agent windows will disappear from screen ( the main window will be placed in front of them). Thus, when the main window is focused, all the agent windows are raised. ( displayed in front of it). This is implemented using a ELQG construction. When the interface main window is moved on screen all agent windows are also moving (new coordinates are computed). In the GLVSOD\BPHVV procedure a new message is selected from the list of pending messages. Depending of the type of the message, one of the Entry, ListBox or TextWidget procedures is called. The (QWU\ procedure creates a new widget and displays it in the window whose name was sent as a procedure parameter. The widget contains a label with a text sent by the agent and an entry where the user has to input a value. The value is sent to the agent by calling the DVNBYDOXHBRN function. The function is implemented in C. It uses a C variable linked with the Tcl variable where the input value is stored and communicates through pvm messages with the agent. The /LVW%R[ procedure displays a menu widget on screen. A scrollbar is associated with it. The list of options is sent by the agent. With a double mouse click an option is selected and its number is sent to the agent by invoking the DVNBPHQXBRN function, whose implementation is similar to the DVNBYDOXHBRN function. In the 7H[W:LGJHW procedure, a test is made to verify if there is no other display window created for the same agent (each is supposed to have only one ). A message box is attentioning the user if the condition is not satisfied. A text widget is created, and also a scrollbar associated with it. If the agent is senting MessagePrint messages, before the text widget is displayed, all the messages are stored in a list. After the text widget is created, they are printed in it. A Quit button is created. When activated, the procedure TXLWBGLVS is called to destroy the display window and to reset all the associated variables. The 3XWB0HVVDJH procedure is invoked when the agent is sending a MessagePrint message. It calls the Tcl procedure SXWBPHVVDJH. In the SXWBPHVVDJH procedure, a test is made, checking if a display window corresponding to the agent is already opened. If yes, the text sent by the agent is printed on screen; if not, the text is stored in the list used by the 7H[W:LGJHW procedure.
When the agent is sending a SendLocFacTid message, the C procedure 3XWB%XWB$JHQW is called with the tid of the agent process as parameter. The C procedure is invoking SXWBEXWBDJHQW a Tcl procedure that displays on screen a button with the agent name and initialise all the data structures associated with the agent. A limited number of agents can work at the same time with the interface. If the number is exceeded, the agent is notyified and asked to try later. An agent is sending a SenderOut message when it wants to dissconect from the interface. The agent button and all the windows containing messages sent by the agent are destroyed . 5. Conclusions and future work The design, implementation and use of a Tcl/Tk-based user interface for multi-agent systems have been presented in this paper. An interesting contribution of this work is the use of Tcl and Tk packages for creating a user interface for a dynamic application - a multi-agent system. The most frequent use of Tcl and Tk is for static applications: all the information about a window is set before it appears on the screen and rarely changed after that. In our case, the number of windows and their moment of apparition on screen is changing dynamically . The procedures that implement the main functions of the interface have been designed to be as general as possible, so that they can be used by any multi-agent system based on pvm. They also provide for a very easy extension: adding new messages (new types of widgets displayed on screen), requires only to write a few Tcl/Tk commands, implementing the desired widget. The code for the agent windows and their management need no changes. As a further development, a new geometry manager, written in C, is to be implemented, meeting the dynamic aspects of the application. When new windows are displayed on screen, the displaying space is equally divided between them (all the windows are resized and rearranged); all agent windows can be individually iconified; a master-slave relation is to be defined between windows - the operations performed on a master window (resizing, moving) will have the same effect on all its slave windows. New types of widgets will also be implemented, for visualising the bids evolution along the negotiation for a specific task. Databases containing all the information about an agent will be created and managed; when requested, the information will be displayed on screen.
References [1] Fonseca J. M., Oliveira E., Steiger-Garcao A. : “MACIV-A DAI Based Resource Management System”, 2nd IEEE/ECLA/IFIP International Conference BASYS ‘96, Costa da Caparica, Portugal [2] Geist et al : “PVM 3 User’s Guide and Reference Manual”, ORNL/TM-12187,May 1993 [3] Ousterhout J. : “Tcl and the Tk Toolkit”, draft 1994, to be published by AddisonWesley Publishing Company, Inc [4] Welch B. : “Practical Programming in Tcl and Tk”, draft 1994, to be published by Prentice Hall
9
10