Updated lines 490-515 with: def optimize(npart, ndim, max_iter): # Initialize the GWO algorithm with the provided parameters gwo = GWO(obj=obj, npart=npart, ndim=ndim, max_iter=max_iter, init=init, bounds=bounds) best_positions, best_fitness, contour_plot = gwo.optimize() # Convert best_fitness and best_positions to NumPy arrays if necessary best_fitness_npy = np.array(best_fitness) best_positions_npy = np.array(best_positions) # Calculate dispersion dispersion = gwo.Dispersion() dispersion_text = f"Dispersion: {dispersion}" # Plot the dispersion over time dispersion_plot = gwo.plot_dispersion() # Plot the dispersion heatmap dispersion_heatmap_plot = gwo.plot_dispersion_heatmap(x_range=(-6,6), y_range=(-6,6)) # Format the output strings best_fitness_text = f"Best Fitness: {best_fitness_npy}" best_positions_text = f"Best Positions: {best_positions_npy}" # Return the images and text return [contour_plot, dispersion_plot, dispersion_heatmap_plot], best_fitness_text, best_positions_text, best_fitness_npy, best_positions_npy, dispersion_text
verified