MINISTRY OF DIGITAL TECHNOLOGIES OF THE REPUBLIC
OF UZBEKISTAN
Tashkent University of Information Technologies
named after Muhammad Al-Khwarizmi
PRACTICAL TASK - 2
Group: MAD401-1
Student: Mahmudjonov Sardor
Teacher: Karimberdiyev Jaxongir
Tashkent-2025
PRACTICAL TASK – 2
Inter-Agent Communication
Disaster Response and Rescue Agents
Emergency agents: Finding survivors,
10. Mahmudjonov Sardorjon Xojiakbar o'g'li
clearing roads, and managing resources
during crises.
1. Establishing Agent Interaction
Direct Messaging: Agents send messages to specific recipients (e.g., TCP/IP,
WebSockets).
Shared Environment: Agents modify and read from a common space (e.g.,
blackboard system).
Broadcasting: Agents send messages to all available agents (e.g., UDP multicast,
MQTT publish-subscribe).
2. Implementing Communication Protocols
FIPA ACL (Agent Communication Language): Standardized for intelligent
agents, supports structured messages.
KQML (Knowledge Query and Manipulation Language): Focused on knowledge
sharing.
MQTT (Message Queuing Telemetry Transport): Lightweight, good for real-time
IoT applications.
HTTP/REST API: Simple and scalable for web-based communication.
3. Ensuring Efficient & Reliable Message Handling
Asynchronous Messaging: Prevents blocking and ensures fast response.
Fault Tolerance: Redundant agents, error detection, and recovery mechanisms.
Priority Queues: Messages related to survivor detection should have higher priority.
Disaster Response and Rescue Agents
Emergency Agents: Detect survivors using sensors, communicate positions, and
guide rescue teams.
Road Clearance Agents: Assess damage, coordinate removal of obstacles.
Resource Management Agents: Allocate supplies, communicate shortages, and
distribute aid.
!pip install paho-mqtt
BROKER = "broker.hivemq.com"
PORT = 1883
TOPIC = "disaster/survivor_location"
import paho.mqtt.client as mqtt
import time
import random
import threading
def emergency_agent():
client = mqtt.Client()
client.connect(BROKER, PORT, 60)
while True:
location = f"Latitude:{random.uniform(40.0, 41.0)},
Longitude:{random.uniform(69.0, 70.0)}"
print(f"Emergency Agent: Detected survivor at {location}")
client.publish(TOPIC, location)
time.sleep(5) # Publish every 5 seconds
# Run the agent in a separate thread
emergency_thread = threading.Thread(target=emergency_agent)
emergency_thread.start()
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
print(f"Rescue Agent: Received survivor location ->
{msg.payload.decode()}")
print("Rescue team is on the way!")
client = mqtt.Client()
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.subscribe(TOPIC)
print("Rescue Agent is listening for survivor locations...")
client.loop_start()
import paho.mqtt.client as mqtt
survivor_count = 0
def on_message_resource_manager(client, userdata, msg):
global survivor_count
survivor_count += 1
print(f"Resource Manager: Survivor #{survivor_count} detected ->
{msg.payload.decode()}")
print("Allocating food, water, and medical supplies...")
resource_client = mqtt.Client()
resource_client.on_message = on_message_resource_manager
resource_client.connect(BROKER, PORT, 60)
resource_client.subscribe(TOPIC)
print("Resource Management Agent is tracking survivors...")
resource_client.loop_start()
1-picture: Outcome from the program
MQTT-based survivor tracking and Google Maps visualization.
!pip install paho-mqtt
!pip install folium paho-mqtt
import paho.mqtt.client as mqtt
import folium
import time
from IPython.display import display
import random
import threading
# MQTT Configuration
BROKER = "broker.hivemq.com"
PORT = 1883
TOPIC = "disaster/survivor_location"
# List to store survivor locations
survivor_locations = []
def on_message(client, userdata, msg):
global survivor_locations
payload = msg.payload.decode()
# Extract latitude & longitude from received message
try:
lat_str, lon_str = payload.replace("Latitude:",
"").replace("Longitude:", "").split(", ")
lat, lon = float(lat_str), float(lon_str)
survivor_locations.append((lat, lon))
print(f"New survivor detected: {lat}, {lon}")
# Update Map
display_survivor_map()
except Exception as e:
print(f"Error processing message: {e}")
# Function to Display Google Maps with Markers
def display_survivor_map():
if not survivor_locations:
print("No survivor locations yet.")
return
# Center map on the latest survivor location
latest_lat, latest_lon = survivor_locations[-1]
survivor_map = folium.Map(location=[latest_lat, latest_lon],
zoom_start=10)
# Add markers for all detected survivors
for lat, lon in survivor_locations:
folium.Marker(location=[lat, lon], popup=f"Survivor at {lat}, {lon}",
icon=folium.Icon(color="red")).add_to(survivor_map)
# Display Map
display(survivor_map)
def emergency_agent():
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
client.connect(BROKER, PORT, 60)
while True:
location = f"Latitude:{random.uniform(40.0, 41.0)},
Longitude:{random.uniform(69.0, 70.0)}"
print(f"Emergency Agent: Detected survivor at {location}")
client.publish(TOPIC, location)
time.sleep(5)
# Start Emergency Agent in a separate thread
emergency_thread = threading.Thread(target=emergency_agent)
emergency_thread.start()
# Setup MQTT Subscriber
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
client.on_message = on_message
client.connect(BROKER, PORT, 60)
client.subscribe(TOPIC)
client.loop_start()
print("Tracking survivors... Waiting for location updates!")
2-picture: Survivors appear on the map in real time.
Conclusion
This program implements a multi-agent system for disaster response using MQTT
communication and Google Maps visualization. Live Location Tracking: Updates
survivor locations in real-time. Decentralized Communication: Uses MQTT for efficient
agent communication. Scalable: Can be extended for resource allocation, road
clearance, and rescue planning.