import matplotlibpyplot as pltpltplotN times_brute_force label=Brute ForcepltplotN times_backtrack label=BacktrackpltplotN times_branch_bound label=Branch and BoundpltxlabelNpltylabelTime spltlegendpl
import numpy as np
plt.plot(N, times_brute_force, label='Brute Force') plt.plot(N, times_backtrack, label='Backtrack') plt.plot(N, times_branch_bound, label='Branch and Bound')
Fit a polynomial curve to the data points
curve_brute_force = np.polyfit(N, times_brute_force, 3) curve_backtrack = np.polyfit(N, times_backtrack, 3) curve_branch_bound = np.polyfit(N, times_branch_bound, 3)
Generate a smooth curve using the fitted polynomial coefficients
smooth_N = np.linspace(min(N), max(N), 100) smooth_times_brute_force = np.polyval(curve_brute_force, smooth_N) smooth_times_backtrack = np.polyval(curve_backtrack, smooth_N) smooth_times_branch_bound = np.polyval(curve_branch_bound, smooth_N)
plt.plot(smooth_N, smooth_times_brute_force, label='Brute Force (Curve)') plt.plot(smooth_N, smooth_times_backtrack, label='Backtrack (Curve)') plt.plot(smooth_N, smooth_times_branch_bound, label='Branch and Bound (Curve)')
plt.xlabel('N') plt.ylabel('Time (s)') plt.legend() plt.show()
原文地址: https://www.cveoy.top/t/topic/hHY5 著作权归作者所有。请勿转载和采集!