متن کامل آگهی:
کارشناسی ارشد مهندسی فناوری اطلاعات
من یک پایان نامه با مشخصات زیر دارم ،میخواستم ببینید هزینه اینکه کد من درست کار میکند یا خیر چقدر است ؟ (ضمیمه کردم)
پروژه پایتون:
Station')
plt.title("Loyal LEACH - WSN Simulation")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.legend()
plt.grid()
plt.show()
import numpy as np
import matplotlib.pyplot as plt
# Parameters
NUM\_NODES = 100 # Number of nodes
FIELD\_SIZE = (100, 100) # Area of the network (100x100 units)
INITIAL\_ENERGY = 0.5 # Initial energy for each node (in Joules)
BASE\_STATION = (50, 50) # Location of the base station
TRANSMIT\_COST = 50e-9 # Energy to transmit (per bit)
RECEIVE\_COST = 50e-9 # Energy to receive (per bit)
AMPLIFICATION\_COST = 10e-12 # Energy for amplification (per bit per meter^2)
DATA\_PACKET\_SIZE = 4000 # Packet size in bits
LOYALITY\_THRESHOLD = 5 # Number of rounds a node avoids being a cluster head
# Node Class
class Node:
def \_init\_(self, x, y):
self.x = x
self.y = y
self.energy = INITIAL\_ENERGY
self.is\_cluster\_head = False
self.cluster = None
self.rounds\_since\_ch = 0 # Tracks rounds since last CH status
def distance\_to(self, x, y):
return np.sqrt((self.x - x)\*2 + (self.y - y)\*2)
# Initialize nodes
nodes = \[Node(np.random.uniform(0, FIELD\_SIZE\[0\]), np.random.uniform(0, FIELD\_SIZE\[1\])) for \_ in range(NUM\_NODES)\]
# Loyal LEACH Algorithm
def select\_cluster\_heads(nodes, p=0.1):
"""Select cluster heads based on energy and loyalty constraints."""
for node in nodes:
if (
node.energy > 0 and
node.rounds\_since\_ch >= LOYALITY\_THRESHOLD and
np.random.rand() < p and
node.energy > np.mean(\[n.energy for n in nodes if n.energy > 0\])
):
node.is\_cluster\_head = True
node.rounds\_since\_ch = 0
else:
node.is\_cluster\_head = False
node.rounds\_since\_ch += 1
def assign\_clusters(nodes):
"""Assign nodes to the nearest cluster head."""
for node in nodes:
if not node.is\_cluster\_head and node.energy > 0:
min\_dist = float('inf')
for ch in \[n for n in nodes if n.is\_cluster\_head and n.energy > 0\]:
dist = node.distance\_to(ch.x, ch.y)
if dist < min\_dist:
min\_dist = dist
node.cluster = ch
# Energy Consumption
def transmit(node, distance):
"""Calculate energy consumption for transmission."""
return TRANSMIT\_COST \* DATA\_PACKET\_SIZE + AMPLIFICATION\_COST \* DATA\_PACKET\_SIZE \* distance\*\*2
def receive():
"""Calculate energy consumption for receiving."""
return RECEIVE\_COST \* DATA\_PACKET\_SIZE
# Simulation
NUM\_ROUNDS = 100
total\_energy\_consumed = 0
packets\_to\_base\_station = 0
for round\_num in range(NUM\_ROUNDS):
print(f"Round {round\_num + 1}")
# Select cluster heads
select\_cluster\_heads(nodes)
# Assign clusters
assign\_clusters(nodes)
# Energy consumption for cluster communication
for node in nodes:
if node.energy > 0:
if node.is\_cluster\_head:
# Cluster heads receive and transmit
total\_receive\_cost = sum(receive() for n in nodes if n.cluster == node)
distance\_to\_bs = node.distance\_to(\*BASE\_STATION)
transmit\_cost = transmit(node, distance\_to\_bs)
node.energy -= total\_receive\_cost + transmit\_cost
total\_energy\_consumed += total\_receive\_cost + transmit\_cost
packets\_to\_base\_station += 1
elif node.cluster:
# Regular nodes transmit to cluster head
distance\_to\_ch = node.distance\_to(node.cluster.x, node.cluster.y)
transmit\_cost = transmit(node, distance\_to\_ch)
node.energy -= transmit\_cost
total\_energy\_consumed += transmit\_cost
# Remove nodes with no energy
alive\_nodes = sum(1 for node in nodes if node.energy > 0)
print(f"Alive nodes: {alive\_nodes}")
# Plot
plt.figure(figsize=(8, 8))
for node in nodes:
if node.energy > 0:
color = 'red' if node.is\_cluster\_head else 'blue'
plt.scatter(node.x, node.y, color=color)
else:
plt.scatter(node.x, node.y, color='black')
plt.scatter(BASE\_STATION\[0\], BASE\_STATION\[1\], color='green', marker='x', label='Base
داده ها همینقدر است