Skip to content

Commit 3b18f4b

Browse files
committed
update create_animation
1 parent d4c0076 commit 3b18f4b

File tree

4 files changed

+195
-226
lines changed

4 files changed

+195
-226
lines changed

Search/07-Local_Search_HillClimbing.ipynb

+191-221
Large diffs are not rendered by default.
53.9 KB
Loading

Search/imgs/10-queens-ha.gif

34 KB
Loading

Search/nqueens.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ def create_animation(history,
277277
plot_objective=False,
278278
summarize=False,
279279
xlabel="Generation",
280-
ylabel="Conflicts"):
280+
ylabel="Conflicts",
281+
interval=200):
281282

282283
hist = summarize_history(history) if summarize else history
283284

@@ -290,7 +291,7 @@ def animate(i):
290291
# plot objective function value
291292
if plot_objective:
292293
ax2.clear()
293-
ax2.plot([s.conflicts() for s in hist[:i]])
294+
ax2.plot([s.conflicts() for s in hist[:i + 1]])
294295
ax2.set_xlim(0, len(history))
295296
ax2.set_ylim(0, max([s.conflicts() for s in hist]))
296297
ax2.set_xlabel(xlabel)
@@ -305,7 +306,5 @@ def animate(i):
305306
fig = plt.figure(figsize=figsize, dpi=dpi)
306307
ax1 = fig.add_subplot(1, 1, 1)
307308

308-
309-
anim = FuncAnimation(fig, animate, frames=range(len(hist)), interval=200, repeat=True)
310-
clear_output()
309+
anim = FuncAnimation(fig, animate, frames=range(len(hist)), interval=interval, repeat=True)
311310
return anim

0 commit comments

Comments
 (0)