PSO coding for multi-objective function-cost fumction and congestion function

8 vues (au cours des 30 derniers jours)
subash
subash le 18 Sep 2014
Réponse apportée : Aditya le 28 Août 2025
Hi sir/mam.. i need PSO coding for congestion management-multi-objective function

Réponses (1)

Aditya
Aditya le 28 Août 2025
Hi Subash,
Particle Swarm Optimization (PSO) is a popular metaheuristic technique used for solving complex optimization problems in power systems, such as congestion management. In a multi-objective congestion management scenario, the aim is typically to minimize both the total generation cost and the severity of line overloads (congestion), while satisfying operational constraints like power balance, generator limits, and line flow limits. The multi-objective function can be constructed as a weighted sum of generation cost and congestion penalty, allowing system operators to prioritize objectives as needed. In the PSO algorithm, a population of candidate solutions (particles) explores the search space, updating their positions based on personal and global best experiences. For each particle, the objective function evaluates the weighted sum of cost and congestion, penalizing solutions that violate constraints. The best solution found by the swarm provides the optimal generation dispatch that minimizes cost and congestion. Below is a Python template demonstrating this approach, which can be customized with your specific power system data.
import numpy as np
# Sample system data (replace with actual data)
n_generators = 3
Pmin = np.array([10, 20, 30])
Pmax = np.array([100, 150, 200])
cost_coeffs = np.array([[0.01, 2, 100], [0.02, 1.5, 120], [0.015, 1.8, 150]])
Pd = 270 # Total demand
n_lines = 2
line_limits = np.array([120, 100])
PTDF = np.array([[0.5, 0.3, 0.2], [0.2, 0.5, 0.3]]) # Power Transfer Distribution Factors
# PSO parameters
n_particles = 30
n_iterations = 100
w = 0.7
c1 = 1.5
c2 = 1.5
# Multi-objective weights
alpha = 0.7 # Weight for cost
beta = 0.3 # Weight for congestion
def generation_cost(Pg):
return np.sum(cost_coeffs[:,0]*Pg**2 + cost_coeffs[:,1]*Pg + cost_coeffs[:,2])
def line_flows(Pg):
return PTDF @ Pg
def congestion_penalty(flows):
penalty = 0
for i in range(n_lines):
if abs(flows[i]) > line_limits[i]:
penalty += (abs(flows[i]) - line_limits[i])**2
return penalty
def fitness(Pg):
# Enforce power balance
if abs(np.sum(Pg) - Pd) > 1e-3:
return 1e8 # Large penalty
flows = line_flows(Pg)
cost = generation_cost(Pg)
congestion = congestion_penalty(flows)
return alpha*cost + beta*congestion
# Initialize particles
particles = np.random.uniform(Pmin, Pmax, (n_particles, n_generators))
velocities = np.zeros_like(particles)
pbest = particles.copy()
pbest_fitness = np.array([fitness(p) for p in particles])
gbest = pbest[np.argmin(pbest_fitness)]
gbest_fitness = np.min(pbest_fitness)
for it in range(n_iterations):
for i in range(n_particles):
r1, r2 = np.random.rand(), np.random.rand()
velocities[i] = (w*velocities[i] +
c1*r1*(pbest[i] - particles[i]) +
c2*r2*(gbest - particles[i]))
particles[i] += velocities[i]
# Apply generator limits
particles[i] = np.clip(particles[i], Pmin, Pmax)
# Enforce power balance by adjusting last generator
particles[i,-1] = Pd - np.sum(particles[i][:-1])
particles[i,-1] = np.clip(particles[i,-1], Pmin[-1], Pmax[-1])
fit = fitness(particles[i])
if fit < pbest_fitness[i]:
pbest[i] = particles[i].copy()
pbest_fitness[i] = fit
if fit < gbest_fitness:
gbest = particles[i].copy()
gbest_fitness = fit
print(f"Iteration {it+1}, Best Fitness: {gbest_fitness:.2f}")
print("\nOptimal Generation (MW):", gbest)
print("Optimal Cost:", generation_cost(gbest))
print("Line Flows:", line_flows(gbest))

Catégories

En savoir plus sur Deep Learning Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by