<jupyter_start><jupyter_text>Simulated Annealing on Wind Placement<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

plt.style.use('classic')
!pip install bayesian-optimization
from bayes_opt import BayesianOptimization
from google.colab import drive
drive.mount('/content/drive')
import sys
sys.path.append('/content/drive/My Drive/Shell India Wind Competition')
from Farm_Evaluator_Vec import *
turb_coords = np.loadtxt('turbine_loc_test.csv', delimiter=',', skiprows=1)
power_curve   =  loadPowerCurve('power_curve.csv')
wind_inst_freq =  binWindResourceData(r'wind_data_2007.csv')
n_wind_instances, cos_dir, sin_dir, wind_sped_stacked, C_t = preProcessing(power_curve)

turb_rad = 50

AEP = getAEP(turb_rad, turb_coords, power_curve, wind_inst_freq, 
             n_wind_instances, cos_dir, sin_dir, wind_sped_stacked, C_t)
x = turb_coords[:,0]
y = turb_coords[:,1]

plt.figure(figsize=(5,5))
plt.xlim(0,4000)
plt.ylim(0,4000)
plt.title('Initial Wind Placement, Calculated AEP: {}'.format(np.round(AEP, 2)), pad=15)
plt.scatter(x, y)
plt.grid()
plt.gca().set_aspect('equal')
plt.show()
def obj_function(x, y):
  """
  This function randomize one of the points in the search space
  Actually pipelining to the real obj. function getAEP
  """
  turb_coords[i] = np.array([x, y])
  AEP = getAEP(turb_rad, turb_coords, power_curve, wind_inst_freq, 
               n_wind_instances, cos_dir, sin_dir, wind_sped_stacked, C_t)
  return AEP<jupyter_output><empty_output><jupyter_text>Optimization happens here. This will optimize one-by-one turbine. Search space (x, y bounds) is 0 to 4000. Apply stopping criterion, e.g. AEP = 530<jupyter_code>turb_coords = np.loadtxt('turbine_loc_test.csv', delimiter=',', skiprows=1)
stop_criterion = 550

for i in range(50):
  # Bounded region of parameter space
  pbounds = {"x": (50, 3950), "y": (50, 3950)}

  optimizer = BayesianOptimization(
      f=obj_function,
      pbounds=pbounds,
      verbose=2,  # verbose = 1 prints only when a maximum is observed, verbose = 0 is silent
      random_state=42,
  )

  print('Optimization at turbine:', i+1)
  optimizer.maximize(init_points=5, n_iter=20)

  # stopping criterion when AEP hits max value we want
  if optimizer.max['target'] >= stop_criterion:
    print('Optimization ends at turbine:', i+1)
    break

  x_reloc = optimizer.max['params']['x']
  y_reloc = optimizer.max['params']['y']
  point_reloc = np.array([x_reloc, y_reloc])
  turb_coords[i] = point_reloc
x = turb_coords[:,0]
y = turb_coords[:,1]
optimized_AEP = optimizer.max['target']

plt.figure(figsize=(5,5))
plt.title('Initial Wind Placement, Calculated AEP: {}'.format(np.round(optimized_AEP, 2)), pad=15)
plt.xlim(0,4000)
plt.ylim(0,4000)
plt.scatter(x, y)
plt.grid()
plt.gca().set_aspect('equal')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13095658312742675, 'fraction_numerical': 0.02717966819625838, 'mean_word_length': 5.397291196388262, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '185077', 'license': 'MIT', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1057, 'n_words': 239, 'path': 'wind_placement_simul_anneal.ipynb', 'repo_name': 'theSubsurfaceGuy/Wavlet-Analyis-for-classification-', 'size': '2833'}