# Coalition Formation among the Cooperative Agents for Efficient Energy Consumption
## 4 Proposed Distributed-Negotiated System (DNsys) Description  
The DNsys code's flow chart contains many phases; the first one contains start and initialization of network random parameter (space, energy, and static size of plot) (Figure 7). Setting the packet size and reading house temperatures were done through manager agents in the second phase. A run function calculation and the Dijkstra algorithm were executed in the third phase to determine the path for distributing energy between the first and last nodes. Finally, the result phase was presented by supplying energy to all devices or appearance of negotiation. DNsys Architecture: the proposed system architecture included several houses, one mosque, and one hospital. Each one of these components considered a node with its data with related agents. Every agent had its objective, and it worked to achieve it. The system architecture components described are as follows:  
Figure 7: Proposed Distributed-Negotiated System Flowchart. * Ten houses (ten nodes), each one has a specific log for storing the temperature inside it alongside the measurement date and time. Changing temperature inside the house opens or closes the devices. * One mosque, one node required full energy for cooling only during prayer times. * One hospital that needs its power supply at full capacity with no discontinuity. * Supplier device generates a random amount of energy to distribute among several nodes. * Agent in the system performs the required operations and specifies the status for each one. * Three manager agents are responsible for forming an agent coalition and the operations performed by their group, especially the negotiation process. * A random network initializes each time the supplier is connected with the manager agents. DNSys Topology: DNSys consists of heterogeneous agents, called functional agents, which supplement some energy functionalities (Figure 8). Agent communication language was used to communicate among agents that helped in understanding each other to initiate conversations. The Generator Agent (GA) generates a random amount of energy for distribution. It distributes the energy to the manager agents of the system by finding the best way to separate the total energy supplied into the appropriate coalition. The Broadcasting Agent (BA) is responsible for sending messages to all agents in other systems via the network. BA communicates the system's energy value at the beginning of the distribution. GA sends a message containing the amount of additional power the system has to BA if it has sufficient power. BA then sends this amount to the balancing agent, which stores the energy in special batteries for later use. However, the negotiation begins when the system lacks sufficient power. Negotiation between the broadcasting manager and balancing agents occurs when MA receives a message from a house node containing the energy requirement and the  
Figure 8: DNSys Hierarchy and Interaction between Agents. number of devices that require energy. BA broadcasts a message containing information from all other MAs, which then send messages to the balancing agent for negotiation. The balancing agent checks each group's energy needs and sends a broadcast message to all MA in the system with a request for energy. The request includes the number of devices to be turned OFF, the node it belongs to, and the amount of energy it can offer. The balancing agent communicates to the DA about the amount of energy which it can offer, and the coalition group name, if the request gets accepted. DA informs the balancing agent to send a verification message to all other coalitions to verify their energy sufficiency. Balancing agent then stores the nodes information which cooperated in the negotiation at the top of a list containing nodes that deserve energy. The process begins again if the requirement is refused. When energy is distributed, the balancing agent sends a message to MA to verify if the energy received was enough.