Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Optimasi Distributed Generation PSO-GWO #4: Particle Swarm Optimization & Grey Wolf Optimizer from Scratch”.
Other ways we can help with Python.
Learn with a mentor
Scheduled Simulation & Engineering courses with live guidance and a certificate.

Course/Training Ansys ~ Heat Transfer and Heat Flux Analysis
★ 5.0 (10)

Course/Training MATLAB — MATLAB App Design: The Ultimate Guide to MATLAB Apps
★ 5.0 (10)

Course/Training Ansys — Airflow Simulation of a Car Radiator with ANSYS
★ 5.0 (9)
Have it built for you
No time to learn Python? Our team can do the project for you.

Matlab Development Service — Complete Neural Signal Processing and Analysis Zero to Hero
★ 5.0 (59)

Ansys Maxwell Development Service
★ 5.0 (50)

Petrel Development Service
★ 5.0 (14)
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
Here is the final result, two metaheuristic algorithms inspired by nature, Particle Swarm Optimization and Grey Wolf Optimizer, we write from scratch without libraries, then compete on the sphere and Rastrigin functions full of local minima. Let's get started. Hello, welcome to episode four of the Distributed Generation optimization series. Metaheuristics are search algorithms that do not require derivatives and are robust against many local optima, suitable for DG placement problems. Today we write the two most popular ones, PSO that mimics a flock of birds, and Grey Wolf Optimizer that mimics a wolf pack hunt.
Create a file called optimasi.py The evaluation function calculates the objective value for each individual. PSO starts with random particles within the bounds. Each particle remembers its best position, P-best, and the swarm remembers the global best position, G-best. New velocity is inertia multiplied by the old velocity, plus random attraction to P-best and G-best with coefficients C-1 and C-2 valued at 2. Inertia weight decreases from 0.9 to 0.4. Initially exploring widely, eventually exploiting the best area. Velocity is limited to 20% of the range to prevent particles from jumping too far. Grey Wolf Optimizer uses a pack hierarchy.
Three best solutions are called alpha, beta, and delta. The leader update function keeps the three best throughout the search. Each wolf moves towards the average of the three positions directed by alpha, beta, and delta. Parameter A decreases from 2 to 0. When coefficient A is greater than 1, wolves move away to explore, and when it is smaller than 1, wolves encircle the prey. Coefficient C gives a random weight to the position of the leader.
Create a test file underscore benchmark.py to test both on a 10-dimensional function. Sphere only has one valley, while Rastrigin has thousands of local valleys. Run On Sphere, GWO drops very quickly to almost 0, while PSO is slower. On Rastrigin, both get stuck slightly above 0, but GWO remains better. However, results on the benchmark function do not always apply to real-world problems. And that is what we will see in the next episode on the DG placement problem. Done.
We have written Particle Swarm Optimization with a decreasing inertia weight, and Grey Wolf Optimizer with hierarchy alpha, beta, delta from 0, then tested it on the benchmark function. In the next episode, we will combine both into hybrid PSO-GWO, and use it to place 3 DG. Currently working on thesis, dissertation, Or research in the field of power system and renewable energy? Cerdas Inovasi Digital helps implement optimization of power systems from backward-forward sweep power flow, placement and capacity of distributed generation, PSO, Gray Wolf Optimizer, up to hybrid algorithms, as well as opening Python programming courses for electrical engineering. Want to master the entire series, from IEEE 33 boost data to algorithm comparison analysis? All 6 episodes, complete with step-by-step PDF guides and source code, are available for premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or one-time payment of Rp999.000 for lifetime access. Want a single class only? Buy the single class with lifetime access. Subscribe now at the premium page cerdasinovasidigital.com. Contact us via WhatsApp, or visit cerdasinovasidigital.com. Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →