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 2 of 4.
Placing turbine 2 of 4.
Placing turbine 2 of 4.
Placing turbine 1 of 4.
Placing turbine 3 of 4.
Placing turbine 3 of 4.
Placing turbine 3 of 4.
Placing turbine 2 of 4.
Placing turbine 3 of 4.
Time to generate initial layouts: 1.753 s
=======================================
Optimization step +0.0
Optimization time = +1.8 [s]
Mean AEP = 56.6 [GWh] (+0.60%)
Median AEP = 56.4 [GWh] (+0.15%)
Max AEP = 58.0 [GWh] (+3.06%)
Min AEP = 55.7 [GWh] (-0.97%)
=======================================
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 = +12.1 [s]
Mean AEP = 57.7 [GWh] (+2.61%)
Median AEP = 58.4 [GWh] (+3.75%)
Max AEP = 58.5 [GWh] (+3.89%)
Min AEP = 55.7 [GWh] (-0.96%)
=======================================
Optimization time: 10.2 s / 60.0 s
=======================================
Optimization step +2.0
Optimization time = +22.2 [s]
Mean AEP = 58.6 [GWh] (+4.09%)
Median AEP = 58.6 [GWh] (+4.06%)
Max AEP = 58.6 [GWh] (+4.22%)
Min AEP = 58.5 [GWh] (+4.03%)
=======================================
Optimization time: 20.3 s / 60.0 s
=======================================
Optimization step +3.0
Optimization time = +32.3 [s]
Mean AEP = 58.7 [GWh] (+4.30%)
Median AEP = 58.7 [GWh] (+4.28%)
Max AEP = 58.8 [GWh] (+4.45%)
Min AEP = 58.6 [GWh] (+4.21%)
=======================================
Optimization time: 30.5 s / 60.0 s
=======================================
Optimization step +4.0
Optimization time = +42.5 [s]
Mean AEP = 58.8 [GWh] (+4.46%)
Median AEP = 58.8 [GWh] (+4.46%)
Max AEP = 58.8 [GWh] (+4.48%)
Min AEP = 58.8 [GWh] (+4.45%)
=======================================
Optimization time: 40.6 s / 60.0 s
=======================================
Optimization step +5.0
Optimization time = +52.7 [s]
Mean AEP = 58.8 [GWh] (+4.48%)
Median AEP = 58.8 [GWh] (+4.48%)
Max AEP = 58.8 [GWh] (+4.49%)
Min AEP = 58.8 [GWh] (+4.45%)
=======================================
Optimization time: 50.8 s / 60.0 s
=======================================
Optimization step +6.0
Optimization time = +62.8 [s]
Mean AEP = 58.8 [GWh] (+4.49%)
Median AEP = 58.8 [GWh] (+4.49%)
Max AEP = 58.8 [GWh] (+4.50%)
Min AEP = 58.8 [GWh] (+4.48%)
=======================================
Final AEP = 58.8 [GWh] (+4.50%)
![../../_images/5ff447f7b856aa14d3431487a9edb52661f4c3d445ddaefa526614f03ecd9e7b.png](../../_images/5ff447f7b856aa14d3431487a9edb52661f4c3d445ddaefa526614f03ecd9e7b.png)
![../../_images/5f8aa4e8e71da32f9e71321750c151c5f147dcd6f476d54a5f526703c61b105d.png](../../_images/5f8aa4e8e71da32f9e71321750c151c5f147dcd6f476d54a5f526703c61b105d.png)
![../../_images/17b13ba2736b785f5fed7f2aaa03a75e1e8c8ab1e49de87b9f9aa50992153c82.png](../../_images/17b13ba2736b785f5fed7f2aaa03a75e1e8c8ab1e49de87b9f9aa50992153c82.png)