|
|
import random |
|
|
import math |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestParticle: |
|
|
def __init__(self, particle_id, x=0, y=0): |
|
|
self.id = particle_id |
|
|
self.position = [x, y] |
|
|
self.energy = random.uniform(10.0, 50.0) |
|
|
self.manipulated = False |
|
|
|
|
|
def __str__(self): |
|
|
return (f"P_{self.id}: Pos=({self.position[0]:.1f}, {self.position[1]:.1f}), " |
|
|
f"Energy={self.energy:.2f}, Manipulated={self.manipulated}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AnanthuSajeevManipulator: |
|
|
def __init__(self, name="Ananthu Sajeev"): |
|
|
self.name = name |
|
|
self.manipulation_count = 0 |
|
|
|
|
|
self.target_energy_threshold = 20.0 |
|
|
|
|
|
self.rearrangement_target = [50.0, 50.0] |
|
|
|
|
|
self.efficiency = 0.95 |
|
|
|
|
|
def calculate_distance(self, pos1, pos2): |
|
|
"""Calculates Euclidean distance.""" |
|
|
return math.sqrt((pos1[0] - pos2[0])**2 + (pos1[1] - pos2[1])**2) |
|
|
|
|
|
def manipulation_algorithm(self, particles): |
|
|
""" |
|
|
The core algorithm to identify low-energy particles and rearrange their position. |
|
|
""" |
|
|
print(f"[{self.name}] Initiating particle scan...") |
|
|
|
|
|
for particle in particles: |
|
|
if particle.energy < self.target_energy_threshold and not particle.manipulated: |
|
|
|
|
|
|
|
|
initial_pos = particle.position[:] |
|
|
print(f" -> Targeting P_{particle.id} (Energy Low: {particle.energy:.2f}) at {initial_pos}") |
|
|
|
|
|
|
|
|
|
|
|
dx = self.rearrangement_target[0] - initial_pos[0] |
|
|
dy = self.rearrangement_target[1] - initial_pos[1] |
|
|
|
|
|
|
|
|
|
|
|
new_x = initial_pos[0] + dx * self.efficiency |
|
|
new_y = initial_pos[1] + dy * self.efficiency |
|
|
|
|
|
particle.position = [new_x, new_y] |
|
|
particle.manipulated = True |
|
|
self.manipulation_count += 1 |
|
|
|
|
|
|
|
|
|
|
|
particle.energy += 5.0 |
|
|
|
|
|
print(f" <- Rearranged to ({new_x:.1f}, {new_y:.1f}). New Energy: {particle.energy:.2f}") |
|
|
|
|
|
print(f"[{self.name}] Scan complete. Total manipulations this cycle: {self.manipulation_count}") |
|
|
return self.manipulation_count |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SIZE = 10 |
|
|
particle_population = [] |
|
|
|
|
|
|
|
|
for i in range(SIZE): |
|
|
x = random.uniform(0.0, 100.0) |
|
|
y = random.uniform(0.0, 100.0) |
|
|
particle_population.append(TestParticle(i, x, y)) |
|
|
|
|
|
|
|
|
ananthu = AnanthuSajeevManipulator() |
|
|
|
|
|
|
|
|
cycles = 3 |
|
|
for cycle in range(1, cycles + 1): |
|
|
print("\n" + "="*40) |
|
|
print(f"CYCLE {cycle}: Manipulator Action") |
|
|
print("="*40) |
|
|
|
|
|
|
|
|
ananthu.manipulation_algorithm(particle_population) |
|
|
|
|
|
|
|
|
print("\n[Population Status]") |
|
|
for particle in particle_population: |
|
|
print(particle) |
|
|
|
|
|
|
|
|
particle.energy = max(10.0, particle.energy - random.uniform(1.0, 5.0)) |
|
|
|
|
|
|
|
|
particle.manipulated = False |
|
|
|