Example: Layout optimization with genetic random search#
"""Example: Layout optimization with genetic random search
This example shows a layout optimization using the genetic random search
algorithm. It provides options for the users to try different distance
probability mass functions for the random search perturbations.
"""
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import gamma
from floris import FlorisModel, WindRose
from floris.optimization.layout_optimization.layout_optimization_random_search import (
LayoutOptimizationRandomSearch,
)
if __name__ == '__main__':
# Set up FLORIS
fmodel = FlorisModel('../inputs/gch.yaml')
# Setup 72 wind directions with a random wind speed and frequency distribution
wind_directions = np.arange(0, 360.0, 5.0)
np.random.seed(1)
wind_speeds = 8.0 + np.random.randn(1) * 0.0
# Shape frequency distribution to match number of wind directions and wind speeds
freq = (
np.abs(
np.sort(
np.random.randn(len(wind_directions))
)
)
.reshape( ( len(wind_directions), len(wind_speeds) ) )
)
freq = freq / freq.sum()
fmodel.set(
wind_data=WindRose(
wind_directions=wind_directions,
wind_speeds=wind_speeds,
freq_table=freq,
ti_table=0.06
)
)
# Set the boundaries
# The boundaries for the turbines, specified as vertices
boundaries = [(0.0, 0.0), (0.0, 1000.0), (1000.0, 1000.0), (1000.0, 0.0), (0.0, 0.0)]
# Set turbine locations to 4 turbines in a rectangle
D = 126.0 # rotor diameter for the NREL 5MW
layout_x = [0, 0, 6 * D, 6 * D]
layout_y = [0, 4 * D, 0, 4 * D]
fmodel.set(layout_x=layout_x, layout_y=layout_y)
# Perform the optimization
distance_pmf = None
# Other options that users can try
# 1.
# distance_pmf = {"d": [100, 1000], "p": [0.8, 0.2]}
# 2.
# p = gamma.pdf(np.linspace(0, 900, 91), 15, scale=20); p = p/p.sum()
# distance_pmf = {"d": np.linspace(100, 1000, 91), "p": p}
layout_opt = LayoutOptimizationRandomSearch(
fmodel,
boundaries,
min_dist_D=5.,
seconds_per_iteration=10,
total_optimization_seconds=60.,
distance_pmf=distance_pmf
)
layout_opt.describe()
layout_opt.plot_distance_pmf()
layout_opt.optimize()
layout_opt.plot_layout_opt_results()
layout_opt.plot_progress()
plt.show()
import warnings
warnings.filterwarnings('ignore')
Generating 4 initial layouts...
Placing turbine 1 of 4.
Placing turbine 1 of 4.
Placing turbine 1 of 4.
Placing turbine 1 of 4.
Placing turbine 2 of 4.
Placing turbine 2 of 4.
Placing turbine 2 of 4.
Placing turbine 2 of 4.
Placing turbine 3 of 4.
Placing turbine 3 of 4.
Placing turbine 3 of 4.
Placing turbine 3 of 4.
Time to generate initial layouts: 0.400 s
=======================================
Optimization step +0.0
Optimization time = +0.4 [s]
Mean AEP = 57.7 [GWh] (+2.57%)
Median AEP = 57.8 [GWh] (+2.79%)
Max AEP = 58.1 [GWh] (+3.21%)
Min AEP = 57.1 [GWh] (+1.48%)
=======================================
Random Layout Optimization
Number of turbines to optimize = 4
Minimum distance between turbines = 5.0 [D], 629.4 [m]
Number of individuals = 4
Seconds per iteration = 10
Initial AEP = 56.3 [GWh]
Optimizing using 4 individuals.
Optimization time: 0.0 s / 60.0 s
=======================================
Optimization step +1.0
Optimization time = +10.5 [s]
Mean AEP = 58.7 [GWh] (+4.32%)
Median AEP = 58.7 [GWh] (+4.33%)
Max AEP = 58.8 [GWh] (+4.44%)
Min AEP = 58.6 [GWh] (+4.18%)
=======================================
Optimization time: 10.0 s / 60.0 s
=======================================
Optimization step +2.0
Optimization time = +20.7 [s]
Mean AEP = 58.8 [GWh] (+4.45%)
Median AEP = 58.8 [GWh] (+4.45%)
Max AEP = 58.8 [GWh] (+4.48%)
Min AEP = 58.7 [GWh] (+4.39%)
=======================================
Optimization time: 20.2 s / 60.0 s
=======================================
Optimization step +3.0
Optimization time = +30.8 [s]
Mean AEP = 58.8 [GWh] (+4.50%)
Median AEP = 58.8 [GWh] (+4.50%)
Max AEP = 58.8 [GWh] (+4.52%)
Min AEP = 58.8 [GWh] (+4.47%)
=======================================
Optimization time: 30.4 s / 60.0 s
=======================================
Optimization step +4.0
Optimization time = +41.0 [s]
Mean AEP = 58.8 [GWh] (+4.53%)
Median AEP = 58.8 [GWh] (+4.53%)
Max AEP = 58.8 [GWh] (+4.54%)
Min AEP = 58.8 [GWh] (+4.51%)
=======================================
Optimization time: 40.5 s / 60.0 s
=======================================
Optimization step +5.0
Optimization time = +51.1 [s]
Mean AEP = 58.8 [GWh] (+4.54%)
Median AEP = 58.8 [GWh] (+4.54%)
Max AEP = 58.8 [GWh] (+4.55%)
Min AEP = 58.8 [GWh] (+4.54%)
=======================================
Optimization time: 50.6 s / 60.0 s
=======================================
Optimization step +6.0
Optimization time = +61.2 [s]
Mean AEP = 58.8 [GWh] (+4.55%)
Median AEP = 58.8 [GWh] (+4.55%)
Max AEP = 58.8 [GWh] (+4.55%)
Min AEP = 58.8 [GWh] (+4.54%)
=======================================
Final AEP = 58.8 [GWh] (+4.55%)