For fun and practice, I've started writing various AI algorithms in Python. There are probably many other similar modules, but as I like to hack a bit... anyway, take a look and play around with them :)
Genetic Algorithm module - Treesearch module - Possible todo's# Usage: # import ga # # ga = ga.GA() # ga.evolve() # Function arguments (fun defaults are used otherwise): # # ga.GA(population_size, gene_size, crossover_rate, mutation_rate, list_of_alleles) # ga.evolve(number_of_generations_to_process) # # ga.set_fitness(your_fitness_function) # Interesting public variables (besides the ones you can modify using arguments) # # ga.debug = 1 (turns on lots of output) # ga.halt = X.X (stop if this fitness is reached) # Note: crossover_rate is the chance two entities will reproduce # mutation_rate is the chance a single entity will have an allele changed
# Usage: # import treesearch # # search = treesearch.TreeSearch() # search.dfs() # Depth-first search # search.bfs() # Breadth-first search # Defaults to an 'a' starting element, child_function returns the next # character in the alphabet and eval_function checks if the element is 'z' # Useful functions: # search = treesearch.TreeSearch(top_element) # Initialize using given element # search.set_eval_function(my_eval_function) # search.set_child_function(my_child_function) # Optionally, you can give the max number of evaluations to dfs() and bfs() # Ideally, you should only have to implement your own # evaluation and child-functions, give your first element, and use # the search-function you prefer :) # During implementation, use search.debug = 1 to output useful stuff