def objfnc(x): global best_fitness global best_solution global list_of_best_fitness # Convert input into index_parameter_matrix x = np.asarray(x).round() parameter_matrix = x.reshape(-1, 2) index_matrix = np.arange(1, len(parameter_matrix) + 1).reshape(-1, 1) index_parameter_matrix = np.concatenate((index_matrix, parameter_matrix), axis=1) # Prepare avoided points (River Cells) rivercells = extract_rivercells() # Check if wells satisfy constraints. Return zero if they do not for well in parameter_matrix: # Check if the well is too close to the river if n_nearest_dist(rivercells, well, 0) < 1.0: return 0 # Check if the well is too close to another well: if n_nearest_dist(parameter_matrix, well, 1) < 1.0: return 0 # Prepare new GWM files using the index-parameter matrix write_supply2decvar(index_parameter_matrix) write_supply2hedcon(index_parameter_matrix) # Run GWM # print("Running gwm on: ", x, end=" ") try: run_gwm() except: print("Error with run_gwm") return 0 # Define ordered list of wells wells = ["Q1", "Q2", "Q3", "Q4"] # Read in the new fitness vector and return the negative sum totalfitness = -read_fitness_array(wells).sum().round() # print("fitness: ", totalfitness, end=" ") # Save best if totalfitness < -best_fitness: best_fitness = -totalfitness best_solution = parameter_matrix print(best_fitness) print(best_solution) list_of_best_fitness.append(best_fitness) return totalfitness
import matplotlib import matplotlib.pyplot as plt import numpy as np from GWM_Manipulator import extract_rivercells # Streamflow Constraint strmflw_cnstrnt = np.array([[14, 14], [14, 21], [13, 23], [15, 26]]) # Load in potentiometric surface surf = np.loadtxt("Supply2_PotenSurf.txt") surf = surf.reshape(25, 30) print(surf, surf.shape) # Setup empty grid model data = np.ones((25, 30)) * np.nan # Rows, Cols # put river cells in matrix rivercells = extract_rivercells() for rivercell in rivercells: data[rivercell[0] - 1, rivercell[1] - 1] = 0 print("data") print(data) print(data.shape) # make a figure + axes fig, ax = plt.subplots(1, 1, tight_layout=True, figsize=(8, 5.5)) # make color map river_cmap = matplotlib.colors.ListedColormap(['aqua']) hk_cmap = matplotlib.colors.ListedColormap(['r', 'b']) surf_cmap = plt.get_cmap('hsv', 14) # set the 'bad' values (nan) to be white and transparent river_cmap.set_bad(color='w', alpha=0) # draw the grid