gpt-oss-20b / __init__ (26).py
Ananthusajeev190's picture
Upload 9 files
0e72aa7 verified
raw
history blame
4.09 kB
import random
import math
# -----------------------------
# Test Particle Class (The Subject)
# -----------------------------
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) # Energy level dictates stability
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}")
# -----------------------------
# Ananthu Sajeev Manipulator (The Algorithm)
# -----------------------------
class AnanthuSajeevManipulator:
def __init__(self, name="Ananthu Sajeev"):
self.name = name
self.manipulation_count = 0
# Low energy threshold for manipulation target
self.target_energy_threshold = 20.0
# Target position for low-energy particles
self.rearrangement_target = [50.0, 50.0]
# Algorithm efficiency
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:
# --- Step 1: Identify and Log Target ---
initial_pos = particle.position[:]
print(f" -> Targeting P_{particle.id} (Energy Low: {particle.energy:.2f}) at {initial_pos}")
# --- Step 2: Calculate Force/Vector ---
# Determine vector needed to move particle to the rearrangement target
dx = self.rearrangement_target[0] - initial_pos[0]
dy = self.rearrangement_target[1] - initial_pos[1]
# --- Step 3: Apply Manipulation (Rearrangement) ---
# The movement is affected by the algorithm's efficiency
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
# --- Step 4: Stabilization (Optional effect of manipulation) ---
# Manipulation requires energy input, increasing the particle's energy slightly
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
# -----------------------------
# Simulation Setup
# -----------------------------
SIZE = 10
particle_population = []
# Create particles at random initial positions (0 to 100)
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))
# Initialize the Manipulator
ananthu = AnanthuSajeevManipulator()
# --- Run Simulation Cycles ---
cycles = 3
for cycle in range(1, cycles + 1):
print("\n" + "="*40)
print(f"CYCLE {cycle}: Manipulator Action")
print("="*40)
# Run the core algorithm
ananthu.manipulation_algorithm(particle_population)
# --- Post-Cycle Status ---
print("\n[Population Status]")
for particle in particle_population:
print(particle)
# Simulate slight random energy decay between cycles
particle.energy = max(10.0, particle.energy - random.uniform(1.0, 5.0))
# Reset manipulation status for the next cycle
particle.manipulated = False