# main.py
# Author: Juliette Zerick (jnzerick@math.ucdavis.edu)
# EAD 221 + PHY 250 (Spring 2009)
# Purpose: This is the main driver for an immune system algorithm.

# MAIN DRIVER

# set up the populations
Ab_pop = spawn_Ab_pop()
Ag_pop = spawn_Ag_pop()

# hold on to the original population
Ag_pop_orig = copy_pop(Ag_pop)

# get the plot ready
pylab.figure()

# plot the Antigens
plot_Ag(Ag_pop)

# iterate generation by generation
try:
	for i in xrange(1,NUM_GENERATIONS+1):
		print "GENERATION",i

		# new generation
		new_pop = Ab_generation(Ab_pop,Ag_pop,i)

		# issue a warning to the user
		print "copying! do not interrupt!"
		Ab_pop = copy_pop(new_pop)
		print "done copying! carry on."

		# output the population to the console
		print_population(Ab_pop)

		# nudge the Antigens
		shift_Ag_pop(Ag_pop)

# catch a keyboard interrupt; the user manually stops the simulation--
# hopefully not while copying was taking place
except(KeyboardInterrupt):
	print "Keyboard interrupt caught! Stopping at generation %d." % i

# plot the Antibodies and their paths
plot_Ab(Ab_pop)
pylab.show()
