@@ -131,7 +131,7 @@ Each agent stays if they are happy and moves if they are unhappy.
131131132132The algorithm for moving is as follows
133133134-```{prf:algorithm} Jump Chain Algorithm
134+```{prf:algorithm} Move algorithm
135135:label: move_algo
1361361371371. Draw a random location in $S$
@@ -244,24 +244,26 @@ def plot_distribution(agents, cycle_num):
244244 plot_args = {'markersize': 8, 'alpha': 0.8}
245245 ax.set_facecolor('azure')
246246 ax.plot(x_values_0, y_values_0,
247- 'o', markerfacecolor='orange', **plot_args)
247+ 'o', markerfacecolor='orange', label='Type 0', **plot_args)
248248 ax.plot(x_values_1, y_values_1,
249- 'o', markerfacecolor='green', **plot_args)
249+ 'o', markerfacecolor='green', label='Type 1', **plot_args)
250250 ax.set_title(f'Cycle {cycle_num-1}')
251+ ax.legend()
251252 plt.show()
252253```
253254254-And here's some pseudocode for the main loop, where we cycle through the
255-agents until no one wishes to move.
255+Here's the main loop, where we cycle through the agents until no one wishes
256+to move.
256257257-The pseudocode is
258+```{prf:algorithm} Main loop
259+:label: schelling_main_loop
260+261+1. plot the distribution
262+1. while agents are still moving
263+ 1. for agent in agents
264+ 1. give agent the opportunity to move
265+1. plot the distribution
258266259-```{code-block} none
260-plot the distribution
261-while agents are still moving
262- for agent in agents
263- give agent the opportunity to move
264-plot the distribution
265267```
266268267269The real code is below
@@ -288,7 +290,6 @@ def run_simulation(num_of_type_0=600,
288290289291 # Loop until no agent wishes to move
290292 while count < max_iter:
291- print('Entering loop ', count)
292293 count += 1
293294 no_one_moved = True
294295 for agent in agents:
@@ -428,8 +429,10 @@ def plot_distribution(locations, types, title, savepdf=False):
428429 'o',
429430 markersize=8,
430431 markerfacecolor=color,
431- alpha=0.8)
432+ alpha=0.8,
433+ label=f'Type {agent_type}')
432434 ax.set_title(title)
435+ ax.legend()
433436 plt.show()
434437435438def sim_random_select(max_iter=100_000, flip_prob=0.01, test_freq=10_000):
@@ -470,11 +473,6 @@ def sim_random_select(max_iter=100_000, flip_prob=0.01, test_freq=10_000):
470473 print(f"Terminating at iteration {current_iter}")
471474```
472475473-```{solution-end}
474-```
475-476-+++
477-478476When we run this we again find that mixed neighborhoods break down and segregation emerges.
479477480478Here's a sample run.
@@ -483,6 +481,5 @@ Here's a sample run.
483481sim_random_select(max_iter=50_000, flip_prob=0.01, test_freq=10_000)
484482```
485483486-```{code-cell} ipython3
487-484+```{solution-end}
488485```