0% found this document useful (0 votes)
4 views6 pages

AI Design Program

The document outlines a simulation of an AI-driven grid computing system using Python, which dynamically routes data packets to the most efficient grid node based on performance history. It details the algorithm and steps for implementing the system, including node processing, latency simulation, and AI decision-making. The program successfully processes data packets and displays optimization results, including average latency and tasks handled by each node.

Uploaded by

kamalravi029
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

AI Design Program

The document outlines a simulation of an AI-driven grid computing system using Python, which dynamically routes data packets to the most efficient grid node based on performance history. It details the algorithm and steps for implementing the system, including node processing, latency simulation, and AI decision-making. The program successfully processes data packets and displays optimization results, including average latency and tasks handled by each node.

Uploaded by

kamalravi029
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EX NO:11

AI DRIVEN DATA TRANSFER USING GRID COMPUTING.


DATE:

AIM:

To simulate an AI-driven grid computing system using Python where data packets are dynamically
routed to the most efficient grid node based on performance history, using multiprocessing to emulate
distributed node processing.

ALGORITHM:

STEP:1 Start the program.

STEP:2 Import required Python modules:

 multiprocessing
 time
 random

STEP:3 Define a function grid_node_service(node_id, data_packet_size) to simulate a grid node


processing a data packet.

STEP:4 Assign base processing speeds to nodes:

Node 101 → 50 MB/s


Node 102 → 20 MB/s
Node 103 → 80 MB/s

STEP:5 Generate random fluctuations in node speed to simulate real network conditions.

STEP:6 Add a small random latency to simulate network delay.

STEP:7 Calculate the processing time using the formula:

Processing Time = (Data Packet Size / Current Speed) + Latency

STEP:8 Pause execution using [Link]() to simulate the actual processing time.

STEP:9 Return the node ID, processing time, and speed.

STEP:10Create a class GridAI to simulate the AI decision system.


STEP:11 Initialize a dictionary performance_history to store latency history for each node.

STEP:12 Define method get_best_node():

 If a node has no history, select it first.


 Otherwise, select the node with the lowest average latency.

STEP:13 Define method update_ai() to store the processing time of each node.

STEP:14 Create the main execution block using:

if __name__ == "__main__":

STEP:15 Initialize:

 Node list [101,102,103]


 AI brain object
 Total packets
 Packet size

STEP:16 For each packet:

1. AI selects the best node.


2. Create a multiprocessing pool.
3. Send the packet to the selected node.
4. Receive the processing result.

STEP:17 Update AI performance history with the returned latency.

STEP:18 Display packet routing details including node ID, processing time, and speed.

STEP:19 After all packets are processed, calculate the average latency for each node.

STEP:20 Display final optimization results including:

 Average latency
 Number of tasks handled by each node.

STEP:21 End the program.

PROGRAM:

import multiprocessing

import time
import random

def grid_node_service(node_id, data_packet_size):

"""

Simulates a remote Grid Node processing a data transfer.

Each node has a 'random' speed to simulate real-world network flux.

"""

base_speed = {101: 50, 102: 20, 103: 80}

current_speed = base_speed[node_id] + [Link](-10, 10)

latency = [Link](0.01, 0.05)

processing_time = (data_packet_size / current_speed) + latency

[Link](processing_time)

return node_id, round(processing_time, 4), round(current_speed, 2)

class GridAI:

def __init__(self, nodes):

self.performance_history = {node: [] for node in nodes}

def get_best_node(self):

"""AI picks the node with the lowest average latency."""

for node, history in self.performance_history.items():

if not history:

return node

return min(

self.performance_history,

key=lambda n: sum(self.performance_history[n]) / len(self.performance_history[n])


)

def update_ai(self, node_id, time_taken):

self.performance_history[node_id].append(time_taken)

if __name__ == "__main__":

node_list = [101, 102, 103]

brain = GridAI(node_list)

total_packets = 10

packet_size = 200

print("🚀 Starting AI-Driven Data Transfer on Python 3.13...")

print(f"Grid Cluster Active: Nodes {node_list}")

print("-" * 50)

for i in range(total_packets):

target_node = brain.get_best_node()

with [Link](1) as pool:

result = [Link](grid_node_service, (target_node, packet_size))

node, duration, speed = result

brain.update_ai(node, duration)

print(f"[Packet {i+1}] AI Routed to Node {node} | Time: {duration}s | Speed: {speed}MB/s")

print("-" * 50)

print("🎯 Final AI Optimization Results:")

for n in node_list:

avg = (

sum(brain.performance_history[n]) / len(brain.performance_history[n])
if brain.performance_history[n]

else 0

print(f"Node {n}: Avg Latency {avg:.4f}s | Tasks Handled:


{len(brain.performance_history[n])}")

OUTPUT:

RESULT:
Thus the program has been executed successfully,and output was verified.

You might also like