# An Event-Driven Agent-Based Simulation Model for Industrial Processes
## 4 Software Architecture  
A MAS may be implemented by using any kind of programming language. In particular, object-oriented programming (OOP) languages represent a good solution, as they share some properties with the agents' concepts, but they are also used for implementing agent frameworks and development toolkits. C# (C-Sharp) was selected among the different OOP languages in combination with Microsoft Visual Studio environment and NET Framework platform, whose components represent a standard [25]. Basically, C# offers several advantages compared to other languages, as it integrates a \"garbage collection\" system, it is supported by several standard libraries and frameworks, it has a simple implementation of properties and events, it is an elegant option for \"embedded systems\" for the integration in industrial plants and it is also a multiplatform language. The Publish-Subscribe mechanism is implemented through the Event and Delegate pattern of C#. A delegate is like a pointer to a function, while an event is nothing but an encapsulated delegate. An example of the Publish-Subscribe pattern in C# is shown in Figure 9.  
In order to simulate the agent-based model, a web-based application was implemented through ASP:NET toolkit of.NET Frameworks 4.0 that allows the creating of classical web-apps, REST API, real-time web-apps and micro-services. The SignalR library included in the ASP:NET allows for the realizing of web applications with real-time bidirectional communication between client and server, suitable for monitoring applications that require continuous and constant updates at high frequency from the server. SignalR supports techniques for managing real-time communication (e.g., WebSocket objects, events sent by the servers and long polling) and automatically selects the best transport method within both server and client functionality. SignalR uses Hubs for the communication between clients and server. A Hub allows performing of a Remote Procedure Call (RPC) from a server to connected clients and vice versa. Concerning data access, a relational Data Base (DB) with Microsoft SQL Server and two patterns of access to data DAO (Data Access Object) and DTO (Data Transfer Object) have been created. The first one encapsulates the logic for accessing, recovering and saving data on the database. The second one, instead, is mainly used to transfer data between the different objects within the application. A schematic representation of the software architecture is provided in Figure 10. The designed software architecture is modular and flexible and can be deployed to the existing IT systems in the company. A possible solution in order to integrate the proposed software into the IT system of a company consists of exploiting a technical integration strategy, such as reported in reference [26]. For instance, a data integration approach can be implemented, which integrates the Enterprise Resource Planning (ERP) data with the agent-based system, since the ERP systems can be considered technologically and operationally ready for the factory of the future [27]. Another approach that can be used is presented in reference [28], where a technical integration strategy for the deployment of a CPPS platform according to the ISA 95 automation standard is described. Figure 9: Publish–Subscribe pattern in C#. The simulator graphical user interface (GUI) is shown in Figure 11. On the right side, a schematic view of the production process described in Section 2 is proposed. It is possible to interact with the graphical objects such as warehouses and machines and check the list of products inside them. There are also three tables: the table at the top shows the events occurring during the simulation, the table in the center summarizes products information such as their status, their identification number and their location and, finally, the table at the bottom shows the status of the production orders with the production demand and the products already delivered.